You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
custom dataset that I loaded in a json file according to COCO annotations and I am trying to train a detectron2 model but i keep getting the same issue with the indexes.. I believe this is related to how i write my annotation file. I have put a sample of the generated json...similar issue reported on #4115
I've tried annotating using via and exporting as coco format, as well as labelme and converted using labelme2COCO
What exact command you run:
def get_pcb_dicts(img_dir):
json_file = os.path.join(img_dir, "via_region_data.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("pcb10_" + d, lambda d=d: get_pcb_dicts("Final/train/" + d))
MetadataCatalog.get("pcb10_" + d).set(thing_classes=["IC"])
pcb_metadata = MetadataCatalog.get("pcb10_train")
import matplotlib.pyplot as plt
dataset_dicts = get_pcb_dicts("New1/train/")
for d in random.sample(dataset_dicts, 3):
img = cv2.imread(d["file_name"])
visualizer = Visualizer(img[:, :, ::-1], metadata=balloon_metadata, scale=0.5)
out = visualizer.draw_dataset_dict(d)
cv2_imshow(out.get_image()[:, :, ::-1])
Full logs or other relevant observations:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[8], line 6
1 #OOOLLLDDDD
2
3 # To verify the data loading is correct, let's visualize the annotations of randomly selected samples in the training set:
5 import matplotlib.pyplot as plt
----> 6 dataset_dicts = get_pcb_dicts("New1/train/")
7 for d in random.sample(dataset_dicts, 3):
8 img = cv2.imread(d["file_name"])
Cell In[3], line 12, in get_pcb_dicts(img_dir)
9 for idx, v in enumerate(imgs_anns.values()):
10 record = {}
---> 12 filename = os.path.join(img_dir, v["filename"])
16 height, width = cv2.imread(filename).shape[:2]
18 record["file_name"] = filename
TypeError: list indices must be integers or slices, not str
please simplify the steps as much as possible so they do not require additional resources to
run, such as a private dataset.
Here's my .json file
Instructions To Reproduce the 🐛 Bug:
What exact command you run:
def get_pcb_dicts(img_dir):
json_file = os.path.join(img_dir, "via_region_data.json")
with open(json_file) as f:
imgs_anns = json.load(f)
dataset_dicts = []
for idx, v in enumerate(imgs_anns.values()):
record = {}
return dataset_dicts
for d in ["train", "val"]:
DatasetCatalog.register("pcb10_" + d, lambda d=d: get_pcb_dicts("Final/train/" + d))
MetadataCatalog.get("pcb10_" + d).set(thing_classes=["IC"])
import matplotlib.pyplot as plt
dataset_dicts = get_pcb_dicts("New1/train/")
for d in random.sample(dataset_dicts, 3):
img = cv2.imread(d["file_name"])
visualizer = Visualizer(img[:, :, ::-1], metadata=balloon_metadata, scale=0.5)
out = visualizer.draw_dataset_dict(d)
cv2_imshow(out.get_image()[:, :, ::-1])
run, such as a private dataset.
Here's my .json file
{"images":[{"height":3280,"width":4928,"id":1,"file_name":"0.jpg"},{"height":3280,"width":4928,"id":2,"file_name":"5.jpg"}],"annotations":[{"iscrowd":0,"image_id":1,"bbox":[2456.8571428571427,1470.9523809523807,342.85714285714266,319.04761904761926],"segmentation":[[2456,1470,2799,1480,2794,1775,2461,1790]],"category_id":0,"id":1,"area":103843},{"iscrowd":0,"image_id":1,"bbox":[3056.8571428571427,1466.1904761904761,195.23809523809496,242.8571428571429],"segmentation":[[3056,1475,3252,1466,3237,1694,3071,1709]],"category_id":0,"id":2,"area":41791},{"iscrowd":0,"image_id":1,"bbox":[2833.047619047619,1799.5238095238094,214.28571428571422,171.42857142857156],"segmentation":[[2833,1804,3047,1799,3004,1970,2833,1970]],"category_id":0,"id":3,"area":32551},{"iscrowd":0,"image_id":1,"bbox":[2547.333333333333,1218.5714285714284,157.14285714285688,228.57142857142867],"segmentation":[[2571,1218,2704,1218,2699,1447,2547,1447]],"category_id":0,"id":4,"area":32653},{"iscrowd":0,"image_id":1,"bbox":[3013.9999999999995,1032.8571428571427,228.5714285714289,247.6190476190477],"segmentation":[[3056,1032,3242,1047,3228,1280,3013,1266]],"category_id":0,"id":5,"area":47074},{"iscrowd":0,"image_id":1,"bbox":[2390.1904761904757,1237.6190476190475,147.6190476190477,200.0],"segmentation":[[2390,1242,2537,1237,2523,1437,2418,1437]],"category_id":0,"id":6,"area":24954},{"iscrowd":0,"image_id":2,"bbox":[1723.5238095238094,1713.8095238095236,166.66666666666674,128.57142857142867],"segmentation":[[1723,1742,1837,1713,1890,1799,1756,1842]],"category_id":0,"id":7,"area":13027}],"categories":[{"id":0,"name":"IC","supercategory":"IC"}]}
Expected behavior:
If there are no obvious error in "full logs" provided above,
please tell us the expected behavior.
Environment: Linux
sys.platform linux
Python 3.9.16 | packaged by conda-forge | (main, Feb 1 2023, 21:39:03) [GCC 11.3.0]
numpy 1.23.5
detectron2 0.6 @/ihome/hban/php13/.conda/envs/detectron/lib/python3.9/site-packages/detectron2
Compiler GCC 7.3
CUDA compiler CUDA 11.3
detectron2 arch flags /ihome/hban/php13/.conda/envs/detectron/lib/python3.9/site-packages/detectron2/_C.cpython-39-x86_64-linux-gnu.so
DETECTRON2_ENV_MODULE
PyTorch 1.10.0 @/ihome/hban/php13/.conda/envs/detectron/lib/python3.9/site-packages/torch
PyTorch debug build False
GPU available Yes
GPU 0 NVIDIA A100-PCIE-40GB (arch=8.0)
Driver version 515.65.01
CUDA_HOME None - invalid!
Pillow 9.4.0
torchvision 0.11.0 @/ihome/hban/php13/.conda/envs/detectron/lib/python3.9/site-packages/torchvision
torchvision arch flags /ihome/hban/php13/.conda/envs/detectron/lib/python3.9/site-packages/torchvision/_C.so
fvcore 0.1.5.post20221221
iopath 0.1.9
cv2 4.7.0
PyTorch built with:
If your issue looks like an installation issue / environment issue,
please first try to solve it yourself with the instructions in
https://detectron2.readthedocs.io/tutorials/install.html#common-installation-issues
The text was updated successfully, but these errors were encountered: