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.5k stars 2.18k forks source link

Detection using custom model #84

Closed John-Almardeny closed 5 years ago

John-Almardeny commented 5 years ago

I am getting this error:

Traceback (most recent call last):
  File "/home/yahya/Desktop/ML/FirstDetection.py", line 11, in <module>
    detector.loadModel()
  File "/usr/local/lib/python3.5/dist-packages/imageai/Detection/__init__.py", line 185, in loadModel
    model.load_weights(self.modelPath)
  File "/usr/local/lib/python3.5/dist-packages/keras/engine/network.py", line 1166, in load_weights
    f, self.layers, reshape=reshape)
  File "/usr/local/lib/python3.5/dist-packages/keras/engine/saving.py", line 1030, in load_weights_from_hdf5_group
    str(len(filtered_layers)) + ' layers.')
ValueError: You are trying to load a weight file containing 107 layers into a model with 116 layers.

My code is as simple as this:

from imageai.Detection import ObjectDetection
import os

execution_path = os.getcwd()
detector = ObjectDetection()
detector.setModelTypeAsRetinaNet()
detector.setModelPath(os.path.join(execution_path , "custom_model.h5"))
detector.loadModel()
detections = detector.detectObjectsFromImage(input_image=os.path.join(execution_path , "2.png"))
OlafenwaMoses commented 5 years ago

Hi John, you are trying to perform object detection using the prediction model you trained. Please be aware your custom model is for prediction and not object detection. Support for training custom models for object detection will be provided in subsequent versions of ImageAI.

Also, ensure you set the model type of your prediction class to correspond with the model type you used in straining.

John-Almardeny commented 5 years ago

Thanks. That makes sense now.

rw86347 commented 5 years ago

I just realized this too. Do you have a time frame for when detection will be supported?

OlafenwaMoses commented 5 years ago

Please refer to #8