我在实际使用您的代码训练自己的数据集时发现,labelme2coco.py 好像缺少对shape_type == "rectangle"时的处理,导致我最后生成的json文件annotations项为空。
以下是labelme2coco.py文件100行到124行代码:
` if shape_type == "polygon":
mask = labelme.utils.shape_to_mask(
img.shape[:2], points, shape_type
)
# cv2.imshow("",np.array(mask, dtype=np.uint8)*255)
# cv2.waitKey(0)
if group_id is None:
group_id = uuid.uuid1()
instance = (label, group_id)
# print(instance)
if instance in masks:
masks[instance] = masks[instance] | mask
else:
masks[instance] = mask
# print(masks[instance].shape)
if shape_type == "rectangle":
(x1, y1), (x2, y2) = points
x1, x2 = sorted([x1, x2])
y1, y2 = sorted([y1, y2])
points = [x1, y1, x2, y1, x2, y2, x1, y2]
if shape_type == "circle":
....
`
代码永远不会执行到shape_type == "rectangle"或shape_type == "circle"。