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

DetectionModelTrain #275

Open Jefflier opened 5 years ago

Jefflier commented 5 years ago

when l trained model,an error occured. Using TensorFlow backend. Generating anchor boxes for training images and annotation... Traceback (most recent call last): File "/content/drive/My Drive/APP/dh/as.py", line 6, in trainer.setTrainConfig(object_names_array=["battery"], batch_size=4, num_experiments=20,train_from_pretrained_model="/content/drive/My Drive/APP/dh/yolo-tiny.h5") File "/usr/local/lib/python3.6/dist-packages/imageai/Detection/Custom/init.py", line 162, in setTrainConfig self.train_cache_file, self.model_labels) File "/usr/local/lib/python3.6/dist-packages/imageai/Detection/Custom/gen_anchors.py", line 89, in generateAnchors relative_w = (float(obj['xmax']) - float(obj['xmin']))/image['width'] ZeroDivisionError: float division by zero

OlafenwaMoses commented 5 years ago

Kindly note that transfer learning using TinyYOLOv3 is not supported. Use the pre-trained YOLOv3 model in the training essentials release.

https://github.com/OlafenwaMoses/ImageAI/releases/tag/essential-v4

Jefflier commented 5 years ago

Thanks,l will change it and try again!

OlafenwaMoses commented 5 years ago

Hello please see an urgent bug fix update here #278

Jefflier commented 5 years ago

In CustomVideoObjectDetection,it seems that video_detector.loadModel() don't have detection_speed.

OlafenwaMoses commented 5 years ago

Not yet. It will be added later.

tiensu commented 5 years ago

I have a similar issue. This is my code:

from imageai.Detection.Custom import DetectionModelTrainer trainer = DetectionModelTrainer() trainer.setModelTypeAsYOLOv3() trainer.setDataDirectory(data_directory="dataset") trainer.setTrainConfig(object_names_array=["Apple", "Orange"], batch_size=4, num_experiments=10, train_from_pretrained_model="pretrained-yolov3.h5") trainer.trainModel()

and this is my issue: Using TensorFlow backend. Generating anchor boxes for training images and annotation... Traceback (most recent call last): File "TrainModel.py", line 9, in train_from_pretrained_model="pretrained-yolov3.h5") File "C:\Anaconda3\envs\ai-study\lib\site-packages\imageai\Detection\Custom__init.py", line 161, in setTrainConfig self.train_cache_file, self.__model_labels) File "C:\Anaconda3\envs\ai-study\lib\site-packages\imageai\Detection\Custom\gen_anchors.py", line 89, in generateAnchors relative_w = (float(obj['xmax']) - float(obj['xmin']))/image['width'] ZeroDivisionError: float division by zero

I already update to the latest version of imageai 5 minutes ago. Is anybody has a solution for this?

Jefflier commented 5 years ago

just check your label file, is there some .xml file get width or height that equals to zero

tiensu commented 5 years ago

Thank Jefflier! I already checked with the command: grep -r "0" . There some label files with width and height equal 0. I removed them then run again. But the error still appears. Do you have any other solution?

Jefflier commented 5 years ago

not only the label file,but also the images

OlafenwaMoses commented 5 years ago

@tiensu Since there are some labels with width and height equals "0", you must remove the labels and their corresponding images from the dataset.

tiensu commented 5 years ago

Hi OlafenwaMoses! I did as below:

  1. Search label with width/height equal 0 by command: grep -r "width>0" dataset
  2. Remove all labels (XML files) output from the command (1) and their corresponding images from the dataset.
  3. Train again It's still the same error. I don't know whether there is any image with the size equal to 0. Actually, I can train successfully with a smaller dataset. But with large dataset, how can I know which image has a size equal to 0?
deepaseb commented 4 years ago

I am getting zerodivision error at the line " relative_w = (float(obj['xmax']) - float(obj['xmin']))/image['width']". Checked the images and annotations but could not find the problem. Can you please help me to resolve this? Error given below:

Generating anchor boxes for training images and annotation...

ZeroDivisionError Traceback (most recent call last)

in () 4 trainer.setModelTypeAsYOLOv3() 5 trainer.setDataDirectory(data_directory="Sofadataset") ----> 6 trainer.setTrainConfig(object_names_array=["sofa"], batch_size=4, num_experiments=10, train_from_pretrained_model="pretrained-yolov3.h5") 7 trainer.trainModel() 1 frames /usr/local/lib/python3.6/dist-packages/imageai/Detection/Custom/gen_anchors.py in generateAnchors(train_annotation_folder, train_image_folder, train_cache_file, model_labels) 88 89 for obj in image['object']: ---> 90 relative_w = (float(obj['xmax']) - float(obj['xmin']))/image['width'] 91 relatice_h = (float(obj["ymax"]) - float(obj['ymin']))/image['height'] 92 annotation_dims.append(tuple(map(float, (relative_w,relatice_h)))) ZeroDivisionError: float division by zero
gbaptista commented 4 years ago

With the command grep -r "width>0" I figure out the problem: it was my webp images that generate annotations with 0 widths and heights. I converted all the webp to jpg and fixed all the annotations with the correct width and height using a python script.

After that, the error keeps occurring. In my case, the reason is that ImageAI uses some caching. 3 folders are generated: cache, models and json. I deleted all three folders, and with the corrected annotations, everything works fine.

Not sure, but maybe just deleting the cache folder would be enough.