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.64k stars 2.19k forks source link

ValueError: a must be greater than 0 unless no samples are taken #804

Open shaunczh opened 1 year ago

shaunczh commented 1 year ago

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`

kalina2b commented 1 year ago

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