OlafenwaMoses / ImageAI

A python library built to empower developers to build applications and systems with self-contained Computer Vision capabilities
https://www.genxr.co/#products
MIT License
8.48k stars 2.18k forks source link

AssertionError while generating anchors #807

Open JonasBoukamp opened 1 year ago

JonasBoukamp commented 1 year ago

Hi, I´m training a volov3 using a custom dataset and ran into the error where an assertion is triggered. I´m using the same code with another dataset without any problems so I asume, I made an error creating this dataset. Does anybody know what type of mistakes in a dataset could trigger the shown assertion. Until now I couldn´t find any differences in the annotation files of the two datasets.

All annotation files are generated by a self written script. The following example shows one of the files:

18 0.21185185185185185 0.19555555555555557 0.08 0.12
19 0.5488888888888889 0.5944444444444444 0.07111111111111111 0.10666666666666667
16 0.7037037037037037 0.14 0.08 0.12
4 0.7844444444444445 0.37 0.044444444444444446 0.06666666666666667
26 0.29185185185185186 0.22 0.07111111111111111 0.10666666666666667
26 0.09037037037037038 0.88 0.08888888888888889 0.13333333333333333
16 0.35555555555555557 0.7755555555555556 0.07111111111111111 0.10666666666666667

Traceback (most recent call last): File "C:\Users\jonas\OneDrive\Hochschule\Master\Master Arbeit\Python\testFramework\yolo.py", line 86, in y.train(dataDirectory="syntheticDataset/temp/out", baseModelPath="syntheticDataset/yolov3.pt") File "C:\Users\jonas\OneDrive\Hochschule\Master\Master Arbeit\Python\testFramework\yolo.py", line 80, in train trainer.trainModel() File "C:\Users\jonas\AppData\Roaming\Python\Python311\site-packages\imageai\Detection\Custom__init.py", line 229, in trainModel self.set_training_param(self.epochs, accumulate) File "C:\Users\jonas\AppData\Roaming\Python\Python311\site-packages\imageai\Detection\Custom\init.py", line 62, in set_training_param self.__anchors = generate_anchors( ^^^^^^^^^^^^^^^^^ File "C:\Users\jonas\AppData\Roaming\Python\Python311\site-packages\imageai\Detection\Custom\yolo\custom_anchors.py", line 59, in generate_anchors assert len(k) == n, f'ERROR: scipy.cluster.vq.kmeans requested {n} points but returned only {len(k)}' ^^^^^^^^^^^ AssertionError: ERROR: scipy.cluster.vq.kmeans requested 9 points but returned only 7

number571 commented 7 months ago

A similar problem

number571 commented 7 months ago

A small random change in the width and height fields helped me. Previously, I set the constant numbers as field data, and this error occurred.

fridayzerg commented 7 months ago

i have same problem. how to fix it

number571 commented 7 months ago

i have same problem. how to fix it

As I empirically understood, such an error is related to the uniformity of input parameters, whether width or height, that interfere with successful learning. On my part, I personally generated a constant height and width, which is why I always got this error. The solution for me was a small randomization of width and height, literally by ~0.01 values. I do not exclude that there may be other reasons for this error, but so far I have had only one such case.