ImageAI icon indicating copy to clipboard operation
ImageAI copied to clipboard

training custom detection models does not work

Open ander2000 opened this issue 4 years ago • 24 comments

Hello, at the time of training, I get the following: WARNING: tensorflow: Compiled the loaded model, but the compiled metrics have yet to be built. model.compile_metrics will be empty until you train or evaluate the model.

And also in the mAP evaluation it shows me the following: Evaluation samples: 59 Using IoU: 0.5 Using Object Threshold: 0.3 Using Non-Maximum Suppression: 0.5 hololens: 0.0000 mAP: 0.0000

[{'model_file': '/content/drive/MyDrive/hololens/models/detection_model-ex-001--loss-0037.935.h5', 'using_iou': 0.5, 'using_object_threshold': 0.3, 'using_non_maximum_suppression': 0.5, 'average_precision': {'hololens': 0.0}, 'evaluation_samples': 59, 'map': 0.0}]

ander2000 avatar Aug 04 '21 05:08 ander2000

Okay, you have a problem with the Code you are running. But to give you a meaningful answer I need the code you were running when the error happened. So if you could send it and put it in "```, ````" that would be the best to read bc the way you have written the question nobody can understand what the problem is and what the actual error output was. So if you provide the mentioned information I will be pleased to help you.

Best Wishes @ekesdf

ekesdf avatar Aug 04 '21 08:08 ekesdf

Hello, sorry for the inconvenience. At the time of training, I receive the following: "WARNING: tensorflow: You built the loaded model, but the compiled metrics have not yet been compiled. Model.compile_metric will be empty until you train or evaluate the model".

Also, in mAP evaluation it shows me the following: "Evaluation samples: 59 Using IoU: 0.5 Using Object Threshold: 0.3 Using No Maximum Suppression: 0.5 hololents: 0.0000 mAP: 0.0000 [{'model_file': '/content/drive/MyDrive/hololens/models/detection_model-ex-001--loss-0037.935.h5', 'using_iou': 0.5, 'using_object_threshold': 0.3, 'using_non_maximum_suppression': 0.5, 'average_precision': {'hololens': 0.0}, 'Evaluation_samples': 59, 'map': 0.0}] ".

This is the training code:

from imageai.Detection.Custom import DetectionModelTrainer
trainer = DetectionModelTrainer ()
trainer.setModelTypeAsYOLOv3 ()
trainer.setDataDirectory (data_directory = "/content/drive/MyDrive/hololens")
trainer.setTrainConfig (object_names_array = ["hololens"], batch_size = 4, num_experiments = 2, train_from_pretrained_model = "/content/drive/MyDrive/matriculas/pretrained-yolov3.h5")
trainer.trainModel ()

This is the code for the model evaluation:

from imageai.Detection.Custom import DetectionModelTrainer

trainer = DetectionModelTrainer()
trainer.setModelTypeAsYOLOv3()
trainer.setDataDirectory(data_directory="/content/drive/MyDrive/hololens")
metrics = trainer.evaluateModel(model_path="/content/drive/MyDrive/hololens/models", json_path="/content/drive/MyDrive/hololens/json/detection_config.json", iou_threshold=0.5, object_threshold=0.3, nms_threshold=0.5)
print(metrics)

I am programming on the Google Colab platform

ander2000 avatar Aug 04 '21 14:08 ander2000

No problem no body is perfect.

ekesdf avatar Aug 04 '21 14:08 ekesdf

@ekesdf The spaces were generated by mistake at the time of pasting the code, because both in Google Colab have the paths without spaces

ander2000 avatar Aug 04 '21 14:08 ander2000

Link to a Notebook that works for your training, just run it. You used the default dataset from the imageai documentations right. Then you can just run it, and it will train on that dataset

ekesdf avatar Aug 04 '21 14:08 ekesdf

Well @ekesdf Thank you very much for your kindness, I will do the test. Anything, I keep you posted

ander2000 avatar Aug 04 '21 14:08 ander2000

@ekesdf Please accept my access request. email: "[email protected]"

ander2000 avatar Aug 04 '21 15:08 ander2000

I change the access level, so you should be able to edit it

ekesdf avatar Aug 04 '21 15:08 ekesdf

Great thank you very much

ander2000 avatar Aug 04 '21 15:08 ander2000

Np keep it up and don't let you stop by some bug, there is always a solution even if it's not right around the corner. The is one, and you will find it, so good luck and have fun with your future projects

ekesdf avatar Aug 04 '21 15:08 ekesdf

@ekesdf Thank you very much for your good wishes and good luck. I have loved working with "imageAI",

ander2000 avatar Aug 04 '21 15:08 ander2000

Why loved ?? You hate it now ??

ekesdf avatar Aug 04 '21 15:08 ekesdf

@ekesdf I love working with "imageAI"

ander2000 avatar Aug 04 '21 15:08 ander2000

:smile: :partying_face:

ekesdf avatar Aug 04 '21 15:08 ekesdf

@ekesdf The following has appeared to me:

"Evaluation samples: 59 Using IoU: 0.5 Using Object Threshold: 0.3 Using Non-Maximum Suppression: 0.5 hololens: 0.0747 mAP: 0.0747

[{'model_file': '/content/hololens/models/detection_model-ex-002--loss-0034.959.h5', 'using_iou': 0.5, 'using_object_threshold': 0.3, 'using_non_maximum_suppression': 0.5, 'average_precision': {'hololens': 0.07473810459116413}, 'evaluation_samples': 59, 'map': 0.07473810459116413}]"

It's right?

ander2000 avatar Aug 04 '21 15:08 ander2000

Yeah looks good your accuracy is just 7% but this is due to the little amount of training. The rest looks fine 👍

ekesdf avatar Aug 04 '21 15:08 ekesdf

@ekesdf How could you improve accuracy?

ander2000 avatar Aug 04 '21 15:08 ander2000

Way longer training with much more data

ekesdf avatar Aug 04 '21 15:08 ekesdf

@ekesdf Thank you very much and you are very kind. You helped me a lot

ander2000 avatar Aug 04 '21 15:08 ander2000

@ekesdf Thank you very much and you are very kind. You helped me a lot

You too mate have a great day

ekesdf avatar Aug 04 '21 15:08 ekesdf

@ander2000 I am facing the same issues. How did you overcome the error?

epistimi4 avatar Aug 22 '21 07:08 epistimi4

@epistimi4 check out this Notebook, there is the right code he is using. If you have a problem, let me know.

ekesdf avatar Nov 01 '21 16:11 ekesdf

Here is a potential workaround if you are getting an mAP of 0.0 at the evaluation step (and have verified the h5 model and the training/evaluation data is not corrupted):

  • Flush the workspace cache with: !rm -r .../<name_of_workspace>/cache/

During the evaluation step, ImageAI will recreate this folder along with the .pkl files. Between model training and evaluation, sometimes the file becomes "corrupted", which will give a default mAP of 0.0. Flushing the cache after training resolved this issue every time it occurred for me.

TheBeastCoding avatar Jan 20 '22 19:01 TheBeastCoding

@ekesdf Please accept my access request. email: "[email protected]"

You should delete your email address from public view

Ebipatei avatar Nov 24 '22 01:11 Ebipatei