labelme_json_to_dataset不能转换关键点的问题(coordinate list must contain at least 2 coordinates)解决办法

Posted missingdays

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了labelme_json_to_dataset不能转换关键点的问题(coordinate list must contain at least 2 coordinates)解决办法相关的知识,希望对你有一定的参考价值。

如果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
"
Traceback (most recent call last):
  File "E:Anaconda3lib
unpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "E:Anaconda3lib
unpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "E:Anaconda3Scriptslabelme_json_to_dataset.exe\__main__.py", line 9, in <module>
  File "E:Anaconda3libsite-packageslabelmeclijson_to_dataset.py", line 62, in main
    lbl = utils.shapes_to_label(img.shape, data[shapes], label_name_to_value)
  File "E:Anaconda3libsite-packageslabelmeutilsshape.py", line 35, in shapes_to_label
    mask = polygons_to_mask(img_shape[:2], polygons)
  File "E:Anaconda3libsite-packageslabelmeutilsshape.py", line 12, in polygons_to_mask
    PIL.ImageDraw.Draw(mask).polygon(xy=xy, outline=1, fill=1)
  File "E:Anaconda3libsite-packagesPILImageDraw.py", line 185, in polygon
    self.draw.draw_polygon(xy, fill, 1)
TypeError: coordinate list must contain at least 2 coordinates

解决办法是:

打开python目录下的..Libsite-packageslabelmeutilsshape.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

 

以上是关于labelme_json_to_dataset不能转换关键点的问题(coordinate list must contain at least 2 coordinates)解决办法的主要内容,如果未能解决你的问题,请参考以下文章

Labelme 批量转 dataset 使用 labelme_json_to_dataset 命令 (简明图文教程)

高分辨率图像建筑物提取数据集制作

烦躁 当写日记了

错题记录

backspace不能用了怎么办(backspace不能删除)

没什么不能没良心,缺什么不能缺教养