labelme_json_to_dataset不能转换关键点的问题

labelme_json_to_dataset不能转换关键点的问题


如果json文件中有关键点,在使用labelme_json_to_dataset.exe时就会有如下错误:

UserWarning: This script is aimed to demonstrate how to convert the JSON file to a single image dataset, and not to handle
multiple JSON files to generate a real-use dataset.
  warnings.warn("This script is aimed to demonstrate how to convert the\n"
Traceback (most recent call last):
  File "E:\Anaconda3\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "E:\Anaconda3\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "E:\Anaconda3\Scripts\labelme_json_to_dataset.exe\__main__.py", line 9, in <module>
  File "E:\Anaconda3\lib\site-packages\labelme\cli\json_to_dataset.py", line 62, in main
    lbl = utils.shapes_to_label(img.shape, data[‘shapes‘], label_name_to_value)
  File "E:\Anaconda3\lib\site-packages\labelme\utils\shape.py", line 35, in shapes_to_label
    mask = polygons_to_mask(img_shape[:2], polygons)
  File "E:\Anaconda3\lib\site-packages\labelme\utils\shape.py", line 12, in polygons_to_mask
    PIL.ImageDraw.Draw(mask).polygon(xy=xy, outline=1, fill=1)
  File "E:\Anaconda3\lib\site-packages\PIL\ImageDraw.py", line 185, in polygon
    self.draw.draw_polygon(xy, fill, 1)
TypeError: coordinate list must contain at least 2 coordinates

解决办法是:

打开python目录下的…\Lib\site-packages\labelme\utils\shape.py

将第8行的polygons_to_mask函数改成如下:

1 def polygons_to_mask(img_shape, polygons):
2     mask = np.zeros(img_shape[:2], dtype=np.uint8)
3     mask = PIL.Image.fromarray(mask)
4     if len(polygons)==1:
5         polygons.append(polygons[0])
6     xy = list(map(tuple, polygons))
7     PIL.ImageDraw.Draw(mask).polygon(xy=xy, outline=1, fill=1)
8     mask = np.array(mask, dtype=bool)
9     return mask
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值