guchengxi1994 / simple-tools-for-machine-learning

Simple tools for deep learning. Including computer vision, machine learning,...
https://guchengxi1994.github.io/simple-tools-for-machine-learning/
MIT License
21 stars 2 forks source link

[bug] LabelmeAugementation without yaml path cause "no contours find" bug #15

Open monkeycc opened 2 years ago

monkeycc commented 2 years ago

I find a bug about mltools

Your os: win11

Your python version: 3.8

Description:

I find a bug about mltools_viewer

Your platform:

Your flutter version:

Description:

I find a bug about mltools_server

from mltools.src.augmentation.aug_labelme import LabelmeAugementation

# l = LabelmeAugementation(["3.png"],["3.json"],"3.yaml")

l = LabelmeAugementation(["D:/simple-tools-for-machine-learning-dev/test/0.png"], ["D:/simple-tools-for-machine-learning-dev/test/0.json"])

# flip
l.onlyFlip()
# rotate
l.onlyRotate()
# translation
l.onlyTrans()
# zoom
l.onlyZoom()
# noise
l.onlyNoise()


(base) PS D:\simple-tools-for-machine-learning-dev> python 1.py
INFO:Machine learning tools log:
    __  _____  ______            __
   /  |/  / / /_  __/___  ____  / /____
  / /|_/ / /   / / / __ \/ __ \/ / ___/
 / /  / / /___/ / / /_/ / /_/ / (__  )
/_/  /_/_____/_/  \____/\____/_/____/

LabelmeAugementation is incomplete .
LabelmeAugementation is unfully tested
[Machine learning tools log]  [ERROR]  [2022-09-06 17:32:09,464] [=====    Exception     ===== ]
ERROR:Machine learning tools log:=====    Exception     =====
Traceback (most recent call last):
  File "D:\simple-tools-for-machine-learning-dev\mltools\src\utils\json2mask\convert.py", line 14, in convert_json_to_mask
    img = img_b64_to_arr(data["imageData"])
TypeError: list indices must be integers or slices, not str
[Machine learning tools log]  [ERROR]  [2022-09-06 17:32:09,466] [parameter oriImg type error,expected a string or ndarray,got <class 'NoneType'> ]
ERROR:Machine learning tools log:parameter oriImg type error,expected a string or ndarray,got <class 'NoneType'>
[Machine learning tools log]  [ERROR]  [2022-09-06 17:32:09,489] [=====    Exception     ===== ]
ERROR:Machine learning tools log:=====    Exception     =====
Traceback (most recent call last):
  File "D:\simple-tools-for-machine-learning-dev\mltools\src\augmentation\aug_labelme.py", line 70, in onlyFlip
    io.imsave(_savePath + fileName + "_h.jpg", oriImgList[0])
  File "D:\Anaconda3\lib\site-packages\skimage\io\_io.py", line 143, in imsave
    return call_plugin('imsave', fname, arr, plugin=plugin, **plugin_args)
  File "D:\Anaconda3\lib\site-packages\skimage\io\manage_plugins.py", line 207, in call_plugin
    return func(*args, **kwargs)
  File "D:\Anaconda3\lib\site-packages\imageio\v2.py", line 238, in imwrite
    with imopen(uri, "wi", **imopen_args) as file:
  File "D:\Anaconda3\lib\site-packages\imageio\core\imopen.py", line 118, in imopen
    request = Request(uri, io_mode, format_hint=format_hint, extension=extension)
  File "D:\Anaconda3\lib\site-packages\imageio\core\request.py", line 248, in __init__
    self._parse_uri(uri)
  File "D:\Anaconda3\lib\site-packages\imageio\core\request.py", line 412, in _parse_uri
    raise FileNotFoundError("The directory %r does not exist" % dn)
FileNotFoundError: The directory 'D:\\\simple-tools-for-machine-learning-dev\\results\\D:\\\simple-tools-for-machine-learning-dev\\test' does not exist

[Machine learning tools log]  [ERROR]  [2022-09-06 17:32:09,515] [=====    Exception     ===== ]
ERROR:Machine learning tools log:=====    Exception     =====
Traceback (most recent call last):
  File "D:\simple-tools-for-machine-learning-dev\mltools\src\utils\json2mask\convert.py", line 14, in convert_json_to_mask
    img = img_b64_to_arr(data["imageData"])
TypeError: list indices must be integers or slices, not str
[Machine learning tools log]  [ERROR]  [2022-09-06 17:32:09,636] [parameter oriImg type error,expected a string or ndarray,got <class 'NoneType'> ]
ERROR:Machine learning tools log:parameter oriImg type error,expected a string or ndarray,got <class 'NoneType'>
[Machine learning tools log]  [ERROR]  [2022-09-06 17:32:09,639] [=====    Exception     ===== ]
ERROR:Machine learning tools log:=====    Exception     =====
Traceback (most recent call last):
  File "D:\simple-tools-for-machine-learning-dev\mltools\src\augmentation\aug_labelme.py", line 148, in onlyRotate
    _rotatedMask = img_rotation(mask, angle=_angle)
  File "D:\simple-tools-for-machine-learning-dev\mltools\src\augmentation\nolabel\img_rotation.py", line 43, in img_rotation
    rotatedImage = transform.rotate(img, angle=angle, preserve_range=True)
UnboundLocalError: local variable 'img' referenced before assignment

[Machine learning tools log]  [ERROR]  [2022-09-06 17:32:09,663] [=====    Exception     ===== ]
ERROR:Machine learning tools log:=====    Exception     =====
Traceback (most recent call last):
  File "D:\simple-tools-for-machine-learning-dev\mltools\src\utils\json2mask\convert.py", line 14, in convert_json_to_mask
    img = img_b64_to_arr(data["imageData"])
TypeError: list indices must be integers or slices, not str
[Machine learning tools log]  [ERROR]  [2022-09-06 17:32:09,742] [parameter oriImg type error,expected a string or ndarray,got <class 'NoneType'> ]
ERROR:Machine learning tools log:parameter oriImg type error,expected a string or ndarray,got <class 'NoneType'>
[Machine learning tools log]  [ERROR]  [2022-09-06 17:32:09,744] [=====    Exception     ===== ]
ERROR:Machine learning tools log:=====    Exception     =====
Traceback (most recent call last):
  File "D:\simple-tools-for-machine-learning-dev\mltools\src\augmentation\aug_labelme.py", line 184, in onlyTrans
    _transMask = img_translation(mask, trans_h, trans_v)
  File "D:\simple-tools-for-machine-learning-dev\mltools\src\augmentation\nolabel\img_translation.py", line 27, in img_translation
    imgShape = img.shape
UnboundLocalError: local variable 'img' referenced before assignment

[Machine learning tools log]  [ERROR]  [2022-09-06 17:32:09,769] [=====    Exception     ===== ]
ERROR:Machine learning tools log:=====    Exception     =====
Traceback (most recent call last):
  File "D:\simple-tools-for-machine-learning-dev\mltools\src\utils\json2mask\convert.py", line 14, in convert_json_to_mask
    img = img_b64_to_arr(data["imageData"])
TypeError: list indices must be integers or slices, not str
[Machine learning tools log]  [ERROR]  [2022-09-06 17:32:09,905] [parameter oriImg type error,expected a string or ndarray,got <class 'NoneType'> ]
ERROR:Machine learning tools log:parameter oriImg type error,expected a string or ndarray,got <class 'NoneType'>
Traceback (most recent call last):
  File "D:\simple-tools-for-machine-learning-dev\1.py", line 14, in <module>
    l.onlyZoom()
  File "D:\simple-tools-for-machine-learning-dev\mltools\src\augmentation\aug_labelme.py", line 221, in onlyZoom
    _zoomedmask = img_zoom(mask, size=zoomfactor)
  File "D:\simple-tools-for-machine-learning-dev\mltools\src\augmentation\nolabel\img_zoom.py", line 35, in img_zoom
    return _get_zoomed_img(img, size)
UnboundLocalError: local variable 'img' referenced before assignment
guchengxi1994 commented 2 years ago

@monkeycc the 0.json is not a labelme json file. It is a createML json file. (generated from labelImg xml, here is the script)

besides, when using LabelmeAugementation, please add a yaml path,otherwise there will be a bug.

monkeycc commented 2 years ago
from mltools.src.augmentation.aug_labelme import LabelmeAugementation

# l = LabelmeAugementation(["3.png"],["3.json"],"3.yaml")

l = LabelmeAugementation(["D:/simple-tools-for-machine-learning-dev/test/3.png"], ["D:/simple-tools-for-machine-learning-dev/test/3.json"],"D:/simple-tools-for-machine-learning-dev/test/3.yaml")

# flip
l.onlyFlip()
# rotate
l.onlyRotate()
# translation
l.onlyTrans()
# zoom
l.onlyZoom()
# noise
l.onlyNoise()
d:/simple-tools-for-machine-learning-dev/1.py
INFO:Machine learning tools log:
    __  _____  ______            __
   /  |/  / / /_  __/___  ____  / /____
  / /|_/ / /   / / / __ \/ __ \/ / ___/
 / /  / / /___/ / / /_/ / /_/ / (__  )
/_/  /_/_____/_/  \____/\____/_/____/

LabelmeAugementation is incomplete .
LabelmeAugementation is unfully tested
{'_background_': 0, 'eye': 1, 'mouth': 3, 'nose': 2}
[Machine learning tools log]  [ERROR]  [2022-09-07 09:19:56,474] [=====    Exception     ===== ]
ERROR:Machine learning tools log:=====    Exception     =====
Traceback (most recent call last):
  File "d:\simple-tools-for-machine-learning-dev\mltools\src\augmentation\aug_labelme.py", line 70, in onlyFlip
    io.imsave(_savePath + fileName + "_h.jpg", oriImgList[0])
  File "D:\Anaconda3\envs\PaddleX38\lib\site-packages\skimage\io\_io.py", line 143, in imsave
    return call_plugin('imsave', fname, arr, plugin=plugin, **plugin_args)
  File "D:\Anaconda3\envs\PaddleX38\lib\site-packages\skimage\io\manage_plugins.py", line 207, in call_plugin
    return func(*args, **kwargs)
  File "D:\Anaconda3\envs\PaddleX38\lib\site-packages\imageio\v2.py", line 238, in imwrite
    with imopen(uri, "wi", **imopen_args) as file:
  File "D:\Anaconda3\envs\PaddleX38\lib\site-packages\imageio\core\imopen.py", line 118, in imopen
    request = Request(uri, io_mode, format_hint=format_hint, extension=extension)
  File "D:\Anaconda3\envs\PaddleX38\lib\site-packages\imageio\core\request.py", line 248, in __init__
    self._parse_uri(uri)
  File "D:\Anaconda3\envs\PaddleX38\lib\site-packages\imageio\core\request.py", line 412, in _parse_uri
    raise FileNotFoundError("The directory %r does not exist" % dn)
FileNotFoundError: The directory 'D:\\\simple-tools-for-machine-learning-dev\\results\\D:\\\simple-tools-for-machine-learning-dev\\test' does not exist

{'_background_': 0, 'eye': 1, 'mouth': 3, 'nose': 2}
[Machine learning tools log]  [ERROR]  [2022-09-07 09:19:56,675] [=====    Exception     ===== ]
ERROR:Machine learning tools log:=====    Exception     =====
Traceback (most recent call last):
  File "d:\simple-tools-for-machine-learning-dev\mltools\src\augmentation\aug_labelme.py", line 149, in onlyRotate
    io.imsave(
  File "D:\Anaconda3\envs\PaddleX38\lib\site-packages\skimage\io\_io.py", line 143, in imsave
    return call_plugin('imsave', fname, arr, plugin=plugin, **plugin_args)
  File "D:\Anaconda3\envs\PaddleX38\lib\site-packages\skimage\io\manage_plugins.py", line 207, in call_plugin
    return func(*args, **kwargs)
  File "D:\Anaconda3\envs\PaddleX38\lib\site-packages\imageio\v2.py", line 238, in imwrite
    with imopen(uri, "wi", **imopen_args) as file:
  File "D:\Anaconda3\envs\PaddleX38\lib\site-packages\imageio\core\imopen.py", line 118, in imopen
    request = Request(uri, io_mode, format_hint=format_hint, extension=extension)
  File "D:\Anaconda3\envs\PaddleX38\lib\site-packages\imageio\core\request.py", line 248, in __init__
    self._parse_uri(uri)
  File "D:\Anaconda3\envs\PaddleX38\lib\site-packages\imageio\core\request.py", line 412, in _parse_uri
    raise FileNotFoundError("The directory %r does not exist" % dn)
FileNotFoundError: The directory 'D:\\\simple-tools-for-machine-learning-dev\\results\\D:\\\simple-tools-for-machine-learning-dev\\test' does not exist

{'_background_': 0, 'eye': 1, 'mouth': 3, 'nose': 2}
{'_background_': 0, 'eye': 1, 'mouth': 3, 'nose': 2}
monkeycc commented 2 years ago

大佬 最新版 还是这样 @guchengxi1994

INFO:Machine learning tools log:
    __  _____  ______            __
   /  |/  / / /_  __/___  ____  / /____
  / /|_/ / /   / / / __ \/ __ \/ / ___/
 / /  / / /___/ / / /_/ / /_/ / (__  )
/_/  /_/_____/_/  \____/\____/_/____/

LabelmeAugementation is incomplete .
LabelmeAugementation is unfully tested
{'_background_': 0, 'eye': 1, 'mouth': 3, 'nose': 2}
[Machine learning tools log]  [ERROR]  [2022-09-20 16:54:43,706] [=====    Exception     ===== ]
ERROR:Machine learning tools log:=====    Exception     =====
Traceback (most recent call last):
  File "d:\0SDXX\simple-tools-for-machine-learning-dev\mltools\src\augmentation\aug_labelme.py", line 72, in onlyFlip
    io.imsave(_savePath + fileName + "_h.jpg", oriImgList[0])
  File "D:\Anaconda3\envs\LabelMe\lib\site-packages\skimage\io\_io.py", line 143, in imsave
    return call_plugin('imsave', fname, arr, plugin=plugin, **plugin_args)
  File "D:\Anaconda3\envs\LabelMe\lib\site-packages\skimage\io\manage_plugins.py", line 207, in call_plugin
    return func(*args, **kwargs)
  File "D:\Anaconda3\envs\LabelMe\lib\site-packages\imageio\v2.py", line 238, in imwrite
    with imopen(uri, "wi", **imopen_args) as file:
  File "D:\Anaconda3\envs\LabelMe\lib\site-packages\imageio\core\imopen.py", line 118, in imopen
    request = Request(uri, io_mode, format_hint=format_hint, extension=extension)
  File "D:\Anaconda3\envs\LabelMe\lib\site-packages\imageio\core\request.py", line 248, in __init__
    self._parse_uri(uri)
  File "D:\Anaconda3\envs\LabelMe\lib\site-packages\imageio\core\request.py", line 412, in _parse_uri
    raise FileNotFoundError("The directory %r does not exist" % dn)
FileNotFoundError: The directory 'D:\\simple-tools-for-machine-learning-dev\\results\\D:\\simple-tools-for-machine-learning-dev\\test' does not exist

{'_background_': 0, 'eye': 1, 'mouth': 3, 'nose': 2}
[Machine learning tools log]  [ERROR]  [2022-09-20 16:54:43,916] [=====    Exception     ===== ]
ERROR:Machine learning tools log:=====    Exception     =====
Traceback (most recent call last):
  File "d:\0SDXX\simple-tools-for-machine-learning-dev\mltools\src\augmentation\aug_labelme.py", line 152, in onlyRotate
    io.imsave(
  File "D:\Anaconda3\envs\LabelMe\lib\site-packages\skimage\io\_io.py", line 143, in imsave
    return call_plugin('imsave', fname, arr, plugin=plugin, **plugin_args)
  File "D:\Anaconda3\envs\LabelMe\lib\site-packages\skimage\io\manage_plugins.py", line 207, in call_plugin
    return func(*args, **kwargs)
  File "D:\Anaconda3\envs\LabelMe\lib\site-packages\imageio\v2.py", line 238, in imwrite
    with imopen(uri, "wi", **imopen_args) as file:
  File "D:\Anaconda3\envs\LabelMe\lib\site-packages\imageio\core\imopen.py", line 118, in imopen
    request = Request(uri, io_mode, format_hint=format_hint, extension=extension)
  File "D:\Anaconda3\envs\LabelMe\lib\site-packages\imageio\core\request.py", line 248, in __init__
    self._parse_uri(uri)
  File "D:\Anaconda3\envs\LabelMe\lib\site-packages\imageio\core\request.py", line 412, in _parse_uri
    raise FileNotFoundError("The directory %r does not exist" % dn)
FileNotFoundError: The directory 'D:\\simple-tools-for-machine-learning-dev\\results\\D:\\simple-tools-for-machine-learning-dev\\test' does not exist

{'_background_': 0, 'eye': 1, 'mouth': 3, 'nose': 2}
{'_background_': 0, 'eye': 1, 'mouth': 3, 'nose': 2}
monkeycc commented 2 years ago

微信截图_20220920170008

平移 应该有的会有问题

guchengxi1994 commented 2 years ago

最近公司有项目要赶,估计要节后才有时间处理开源项目了

guchengxi1994 commented 1 year ago

微信截图_20220920170008

平移 应该有的会有问题

这个bug是因为 skimage 求外接多边形的时候只求取了外部的边界,内部的(如果是图像边缘上的)就舍去了...比较囧的一个问题,换成opencv就可以了