ValueError: a must be greater than 0 unless no samples are taken
shaunczh opened this issue · 1 comments
I'm getting errors when trying to run custom training model code taken from documentation with my own dataset.
`from imageai.Detection.Custom import DetectionModelTrainer
trainer = DetectionModelTrainer()
trainer.setModelTypeAsYOLOv3()
trainer.setDataDirectory(data_directory="keycaps")
trainer.setTrainConfig(object_names_array=["a-key"], batch_size=4, num_experiments=200, train_from_pretrained_model="yolov3.pt")
trainer.trainModel()`
Here is the issue I'm facing when running the code above:
`Warning (from warnings module):
File "C:\Users\shaun\AppData\Local\Programs\Python\Python39\lib\site-packages\numpy\core_methods.py", line 264
ret = _var(a, axis=axis, dtype=dtype, out=out, ddof=ddof,
RuntimeWarning: Degrees of freedom <= 0 for slice
Warning (from warnings module):
File "C:\Users\shaun\AppData\Local\Programs\Python\Python39\lib\site-packages\numpy\core_methods.py", line 222
arrmean = um.true_divide(arrmean, div, out=arrmean, casting='unsafe',
RuntimeWarning: invalid value encountered in true_divide
Warning (from warnings module):
File "C:\Users\shaun\AppData\Local\Programs\Python\Python39\lib\site-packages\numpy\core_methods.py", line 253
ret = um.true_divide(
RuntimeWarning: invalid value encountered in true_divide
Traceback (most recent call last):
File "C:\Users\shaun\workspace\imageAI-python\DetectionTrainer.py", line 7, in
trainer.trainModel()
File "C:\Users\shaun\AppData\Local\Programs\Python\Python39\lib\site-packages\imageai\Detection\Custom_init_.py", line 229, in trainModel
self.__set_training_param(self._epochs, accumulate)
File "C:\Users\shaun\AppData\Local\Programs\Python\Python39\lib\site-packages\imageai\Detection\Custom_init.py", line 62, in __set_training_param
self.__anchors = generate_anchors(
File "C:\Users\shaun\AppData\Local\Programs\Python\Python39\lib\site-packages\imageai\Detection\Custom\yolo\custom_anchors.py", line 58, in generate_anchors
k, dist = kmeans(wh / s, n, iter=30) # points, mean distance
File "C:\Users\shaun\AppData\Local\Programs\Python\Python39\lib\site-packages\scipy\cluster\vq.py", line 475, in kmeans
guess = _kpoints(obs, k, rng)
File "C:\Users\shaun\AppData\Local\Programs\Python\Python39\lib\site-packages\scipy\cluster\vq.py", line 503, in _kpoints
idx = rng.choice(data.shape[0], size=k, replace=False)
File "mtrand.pyx", line 909, in numpy.random.mtrand.RandomState.choice
ValueError: a must be greater than 0 unless no samples are taken`
Hi.
I've got same errors too, but I've solved it.
Using PascalVOC format will cause an error, you need to convert your dataset to YOLO format.
https://github.com/OlafenwaMoses/ImageAI/blob/master/BACKEND_MIGRATION.md#convert-pascal-voc-dataset-to-yolo-format
Link to converter script: https://github.com/OlafenwaMoses/ImageAI/blob/master/scripts/pascal_voc_to_yolo.py