ImageAI icon indicating copy to clipboard operation
ImageAI copied to clipboard

Custom Object Detection Model - My model doesn't work on my own dataset

Open marbortoli opened this issue 3 years ago • 17 comments

My model comes out with good accuracy after 100 epochs, however, when to detect the objects in a random image, nothing is detected. Someone here really used ImageAI on your own dataset? Is there some limitation according to image resolution?

Cheers

marbortoli avatar Nov 01 '21 14:11 marbortoli

Hi,

Can you give me some details about your custom dataset. So I can get a better view about the situation.

ekesdf avatar Nov 01 '21 14:11 ekesdf

_import imageai from imageai.Detection.Custom import DetectionModelTrainer train the custom model trainer = DetectionModelTrainer() trainer.setModelTypeAsYOLOv3() trainer.setDataDirectory(data_directory='scada_all') trainer.setTrainConfig(object_names_array=["tag"], batch_size=4, num_experiments= 100, train_from_pretrained_model=(\bla\pretrained-yolov3.h5) train = trainer.trainModel() print(train) evaluation of the model

metrics = trainer.evaluateModel(model_path='scada_all/models', json_path='scada_all/json/detection_config.json', iou_threshold=0.5, object_threshold=0.3, nms_threshold=0.5) print(metrics)_

my model loss = 13.616 and mAP =~ 80%

image detection detector = CustomObjectDetection() detector.setModelTypeAsYOLOv3() detector.setModelPath('scada_all/models/detection_model-exBLABLABLA') detector.setJsonPath('scada_all/json/detection_config.json') detector.loadModel() detections = detector.detectObjectsFromImage(input_image=input_path, output_image_path=output_path) for detection in detections: print(detection['name'], ' : ', detection['percentage_probability'], ' : ', detection['box_points'])

single_sensor_original_24 png_2f77a9a4-fc77-4495-be57-ee7c388a4cab

my dataset is made of images like this, where I want to detect one of this tags. I did data augmentation to increase the amount of images to train the model.

marbortoli avatar Nov 01 '21 15:11 marbortoli

how big are your images compared to the objects you want to detect ?

ekesdf avatar Nov 01 '21 15:11 ekesdf

I have different styles of images. I'm not sure if the quality is too low. single_sensor_original_01 png_8b1987ac-0328-4083-832d-2ee6c6bae173

single_sensor_original_07 png_f99f4483-84cd-4af0-8395-fab91caa3cf1

single_sensor_original_08 png_99218f01-25a3-4b06-b25b-58d802c19620

And I would detect in a picture very similar, like this: Capture

marbortoli avatar Nov 01 '21 15:11 marbortoli

How big is the resolution in like pixels

ekesdf avatar Nov 01 '21 15:11 ekesdf

it varies like in this examples, from 76x57 to 1037x612

marbortoli avatar Nov 01 '21 15:11 marbortoli

This range should not be a problem. The problem might be you labels itself bc they have a lot of background.

ekesdf avatar Nov 01 '21 16:11 ekesdf

If those 3 images you send me where cut our labels then are the objects in them are too small compared to the background. They should look more like this. 139700541-b25c1a53-3047-446e-b848-d7d5540c244c (1) (Kopie)

ekesdf avatar Nov 01 '21 16:11 ekesdf

Thanks a lot! The object detection model works, but not for every input image I provide. I'll try to improve my dataset.

Thanks a lot again!!

marbortoli avatar Nov 02 '21 07:11 marbortoli

@marbortoli Hey how it is going could you fix your problem ?

ekesdf avatar Nov 12 '21 18:11 ekesdf

I could fix in general. The main issue now is that the model doesn't work for every image I give as an input. I'm increasing the epochs to try to solve the problem :)

marbortoli avatar Nov 15 '21 07:11 marbortoli

That is the problem regarding to the object detecting using machine learning that the accuracy will never be 100 % Btw if u train the model to long it could decrease the acc on images outside you training se. So if the loss is stable on a low lvl for a long time you should stop training to prevent that

ekesdf avatar Nov 15 '21 07:11 ekesdf

Thanks! So far my accuracy is very low anyways. I don't know if its due to my dataset, but I provided a lot of images. However many of them are from data augmentation and I don't know if this can compromise my training in some way.

marbortoli avatar Nov 15 '21 07:11 marbortoli

What kind of augmentation do u use ?

ekesdf avatar Nov 15 '21 07:11 ekesdf

Augmentor library from python

marbortoli avatar Nov 15 '21 07:11 marbortoli

@marbortoli hi can u specify exactly what u used things like rotation or random cropping ?

ekesdf avatar Nov 19 '21 15:11 ekesdf

oh sorry for the delay.

p.rotate(probability=0.9, max_left_rotation=10, max_right_rotation=10) p.zoom(probability=0.3, min_factor=1.1, max_factor=1.6)

marbortoli avatar Nov 22 '21 06:11 marbortoli