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

ValueError: Dimension 0 in both shapes must be equal, but are 1 and 18. Shapes are [1,1,1024,255] and [18,1024,1,1]. for 'Assign_360' (op: 'Assign') with input shapes: [1,1,1024,255], [18,1024,1,1]. #300

Closed acleitao76 closed 5 years ago

acleitao76 commented 5 years ago

Hey. I trained a model with 800 images just 15 epocs. I tried this model with CustomObjectDetection but I was getting too many false positives. I decided to try with Object Detection setting my detector.CustomObjects to my class. And I'm getting this huge error. I didn't try yet with the other models but I guess I will get the same this is my code. What am I doing wrong getting the error when I try to load the model

#detector = CustomObjectDetection()
detector = ObjectDetection()
detector.setModelTypeAsYOLOv3()
detector.setModelPath(os.path.join(model_path, "detection_model-ex-09--loss-12.45.h5"))
#detector.setJsonPath("detection_config.json")
detector.loadModel()
custom = detector.CustomObjects(bibnumber=True)
detections = detector.detectCustomObjectsFromImage(custom_objects=custom,
                                                           input_image=os.path.join(execution_path , file),
                                                           output_type="array",
                                                           minimum_percentage_probability=30)
acleitao76 commented 5 years ago

yep...tried four models and all the same error... Am I missing something? My first model I trainned with only 70 images for 15 epocs was much better than this one... As I said before... I'm trying to get people using badges(bigones) and extract the badges area. I got ambient pictures with the lots of people from this events in each picture I marked every badge I could see(annotations) my hope is imageai find all the badges in the scene. Can you guys point me in the right direction? I feel kind of lost like I missed some link of the chain

Meulen92 commented 5 years ago

Stupid question, but could this be the problem in your code? #detector.setJsonPath("detection_config.json") I think it's mandatory to pass the config to the detector.

OlafenwaMoses commented 5 years ago

Hey. I trained a model with 800 images just 15 epocs. I tried this model with CustomObjectDetection but I was getting too many false positives. I decided to try with Object Detection setting my detector.CustomObjects to my class. And I'm getting this huge error. I didn't try yet with the other models but I guess I will get the same this is my code. What am I doing wrong getting the error when I try to load the model

#detector = CustomObjectDetection()
detector = ObjectDetection()
detector.setModelTypeAsYOLOv3()
detector.setModelPath(os.path.join(model_path, "detection_model-ex-09--loss-12.45.h5"))
#detector.setJsonPath("detection_config.json")
detector.loadModel()
custom = detector.CustomObjects(bibnumber=True)
detections = detector.detectCustomObjectsFromImage(custom_objects=custom,
                                                           input_image=os.path.join(execution_path , file),
                                                           output_type="array",
                                                           minimum_percentage_probability=30)

Please note that defining custom_objects is not yet supported for your custom detection models

OlafenwaMoses commented 5 years ago

Stupid question, but could this be the problem in your code? #detector.setJsonPath("detection_config.json") I think it's mandatory to pass the config to the detector.

Your 800-images trained models may be performing poorly because you are using the detection_config.json file of the previous training.

acleitao76 commented 5 years ago

thx Moses... hummmm... I don't remember if I change the json for the new one... in any case I will check it... again thx for all your support and honestly I hope this library bring you a lot of jobs it's really a piece of art

OlafenwaMoses commented 5 years ago

Thank you very much @acleitao76

acleitao76 commented 5 years ago

@OlafenwaMoses got the right json still not ok. The first train I used 70 images for train 15 to validation ...15 epocs. This time I increased the complexity by using pictures of different badges (120 pictures of each event or each badge in the person chest) label them right do you think it's not enough epocs for a accurate result? That's why I was asking if I can run 15 ... get the best result and run again over it(using the generated h5 file as a pre-trained model) . As google colab only give me 12hours I can't do 100 epocs at once. Is that possible? 15 it's not enough?

OlafenwaMoses commented 5 years ago

You can train with any number of epochs (recommend at least 5) . The use of 100 epochs is not a requirement; it was just used as a convention in the example.