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

training custom detection models does not work #690

Open ander2000 opened 3 years ago

ander2000 commented 3 years ago

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}]

ekesdf commented 3 years ago

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

ander2000 commented 3 years ago

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

ekesdf commented 3 years ago

No problem no body is perfect.

ander2000 commented 3 years ago

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

ekesdf commented 3 years ago

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

ander2000 commented 3 years ago

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

ander2000 commented 3 years ago

@ekesdf Please accept my access request. email: "andermillanlopez@gmail.com"

ekesdf commented 3 years ago

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

ander2000 commented 3 years ago

Great thank you very much

ekesdf commented 3 years ago

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

ander2000 commented 3 years ago

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

ekesdf commented 3 years ago

Why loved ?? You hate it now ??

ander2000 commented 3 years ago

@ekesdf I love working with "imageAI"

ekesdf commented 3 years ago

:smile: :partying_face:

ander2000 commented 3 years ago

@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?

ekesdf commented 3 years ago

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

ander2000 commented 3 years ago

@ekesdf How could you improve accuracy?

ekesdf commented 3 years ago

Way longer training with much more data

ander2000 commented 3 years ago

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

ekesdf commented 3 years ago

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

You too mate have a great day

epistimi4 commented 3 years ago

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

ekesdf commented 2 years ago

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

TheBeastCoding commented 2 years ago

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):

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.

Ebipatei commented 1 year ago

@ekesdf Please accept my access request. email: "andermillanlopez@gmail.com"

You should delete your email address from public view