Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AssertionError while generating anchors #807

Open
JonasBoukamp opened this issue May 12, 2023 · 4 comments
Open

AssertionError while generating anchors #807

JonasBoukamp opened this issue May 12, 2023 · 4 comments

Comments

@JonasBoukamp
Copy link

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
Copy link

A similar problem

@number571
Copy link

number571 commented Nov 8, 2023

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
Copy link

i have same problem. how to fix it

@number571
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants