facebookresearch / facebookresearch/detectron2
Error: 'list' object has no attribute 'items' while registering dataset
- Dominant language
- Python
- Stars
- 34.7k
- Forks
- 7.9k
- PR merge metrics
- No merged PRs in 30d
Description
Hi I am new to Detectron 2. I am using Mask RCNN to train my own dataset. However, while registering the dataset I am getting this error which is mentioned in subject line. My code and corresponding error is below. I would really appreciate if someone tell what I am doing wrong. Thanks
**CODE:**
def get_lettuce_dicts(img_dir):
json_file = os.path.join(img_dir, "annotations_maskrcnn.json")
with open(json_file) as f:
imgs_anns = json.load(f)
dataset_dicts = []
for idx, v in enumerate(imgs_anns.values()):
record = {}
filename = os.path.join(img_dir, v["filename"])
height, width = cv2.imread(filename).shape[:2]
record["file_name"] = filename
record["image_id"] = idx
record["height"] = height
record["width"] = width
annos = v["regions"]
objs = []
for _, anno in annos.items():
assert not anno["region_attributes"]
anno = anno["shape_attributes"]
px = anno["all_points_x"]
py = anno["all_points_y"]
poly = [(x + 0.5, y + 0.5) for x, y in zip(px, py)]
poly = [p for x in poly for p in x]
obj = {
"bbox": [np.min(px), np.min(py), np.max(px), np.max(py)],
"bbox_mode": BoxMode.XYXY_ABS,
"segmentation": [poly],
"category_id": 0,
}
objs.append(obj)
record["annotations"] = objs
dataset_dicts.append(record)
return dataset_dicts
for d in ["train", "val"]:
DatasetCatalog.register("lettuce_" + d, lambda d=d: get_lettuce_dicts("Lettuce_Dataset/" + d))
MetadataCatalog.get("lettuce_" + d).set(thing_classes=["Lettuce"])
lettuce_metadata = MetadataCatalog.get("lettuce_train")
import matplotlib.pyplot as plt
dataset_dicts = get_lettuce_dicts("Lettuce_Dataset/train")
**Error:**
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
~\AppData\Local\Temp\2\ipykernel_32116\3384862469.py in
1 import matplotlib.pyplot as plt
----> 2 dataset_dicts = get_lettuce_dicts("Lettuce_Dataset/train")
~\AppData\Local\Temp\2\ipykernel_32116\2458792380.py in get_lettuce_dicts(img_dir)
18 annos = v["regions"]
19 objs = []
---> 20 for _, anno in annos.items():
21 assert not anno["region_attributes"]
22 anno = anno["shape_attributes"]
AttributeError: 'list' object has no attribute 'items'
Contributor guide
Assessment
This issue has not been assessed yet.