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

Unknown layer: NonMaximumSuppression in imageAI Detection demo #629

Open sxbug opened 3 years ago

sxbug commented 3 years ago

imageAI 2.1.6 numpy1.19.3 Pillow7.0.0 opencv-python 4.5.1.48 keras 2.4.3 matplotlib 3.3.2 tensorflow 2.4.0 win 10 64Bit, AMD R9 M370X, python3.7.9 64bit DEMO: from imageai.Detection import ObjectDetection import os execution_path = os.getcwd() detector = ObjectDetection() detector.setModelTypeAsRetinaNet() detector.setModelPath( os.path.join(execution_path , "model/resnet50_coco_best_v2.0.1.h5")) detector.loadModel() ####### ValueError Unknown layer: NonMaximumSuppression .

I don't know why. Please advise me. thank you very much!

            sxbug
sxbug commented 3 years ago

detector = ObjectDetection() detector.setModelTypeAsYOLOv3()
detector.setModelPath( os.path.join(execution_path , "model/yolo-tiny.h5"))
detector.loadModel() ########### ValueError。 You are trying to load a weight file containing 24 layers into a model with 147 layers.

Why?

sxbug commented 3 years ago

detector.setModelTypeAsTinyYOLOv3() #detector.setModelTypeAsRetinaNet() detector.setModelPath( os.path.join(execution_path , "model/yolo-tiny.h5"))
detector.loadModel()

It is OK

But How can I use RetinaNet? Thanks

vangorade commented 3 years ago

detector.setModelTypeAsTinyYOLOv3() #detector.setModelTypeAsRetinaNet() detector.setModelPath( os.path.join(execution_path , "model/yolo-tiny.h5")) detector.loadModel()

It is OK

But How can I use RetinaNet? Thanks

fizyr/keras-retinanet#748

there are some answers here but i still don't know how to resolve it

sxbug commented 3 years ago

Thank you. My level is limited, and I still can't solve my problem, so I have to ask again in fizyr GITHUB . Thank you again!

yubg commented 3 years ago

I met the same issu. ######## Traceback (most recent call last):

File "", line 9, in detector.loadModel() ...... ...... raise ValueError('Unknown ' + printable_module_name + ': ' + class_name)

ValueError: Unknown layer: NonMaximumSuppression #######

how to resolve?

Email: 120487362@qq.com

s4lm-xi commented 3 years ago

The following error occurred to me Unknown layer: NonMaximumSuppression

when I ran the following code.

from imageai.Detection import ObjectDetection
import os

detector = ObjectDetection()
detector.setModelTypeAsRetinaNet()
detector.setModelPath('weights/resnet50_coco_best_v2.0.1.h5')
detector.loadModel()
detections = detector.detectObjectsFromImage(input_image="image.png",
                                             output_image_path="imagenew.jpg",
                                             minimum_percentage_probability=30)

for eachObject in detections:
    print(eachObject["name"] , " : ", eachObject["percentage_probability"], " : ", eachObject["box_points"] )
    print("--------------------------------")

in order to fix the error I had to replace the weights that I have loaded resnet50_coco_best_v2.0.1.h5 to the latest version which is resnet50_coco_best_v2.1.0.h5, download weights here

I simply replaced detector.setModelPath('weights/resnet50_coco_best_v2.0.1.h5') to detector.setModelPath('weights/resnet50_coco_best_v2.1.0.h5').

This has resolved my issue, I hope it fixed yours as well.

ChenZheChina commented 3 years ago

in order to fix the error I had to replace the weights that I have loaded resnet50_coco_best_v2.0.1.h5 to the latest version which is resnet50_coco_best_v2.1.0.h5, download weights here

I simply replaced detector.setModelPath('weights/resnet50_coco_best_v2.0.1.h5') to detector.setModelPath('weights/resnet50_coco_best_v2.1.0.h5').

This has resolved my issue, I hope it fixed yours as well.

Thank you. This solved my issue, too.

JiaYee commented 3 years ago

in order to fix the error I had to replace the weights that I have loaded resnet50_coco_best_v2.0.1.h5 to the latest version which is resnet50_coco_best_v2.1.0.h5, download weights here I simply replaced detector.setModelPath('weights/resnet50_coco_best_v2.0.1.h5') to detector.setModelPath('weights/resnet50_coco_best_v2.1.0.h5'). This has resolved my issue, I hope it fixed yours as well.

Thank you. This solved my issue, too.

The following error occurred to me Unknown layer: NonMaximumSuppression

when I ran the following code.

from imageai.Detection import ObjectDetection
import os

detector = ObjectDetection()
detector.setModelTypeAsRetinaNet()
detector.setModelPath('weights/resnet50_coco_best_v2.0.1.h5')
detector.loadModel()
detections = detector.detectObjectsFromImage(input_image="image.png",
                                             output_image_path="imagenew.jpg",
                                             minimum_percentage_probability=30)

for eachObject in detections:
    print(eachObject["name"] , " : ", eachObject["percentage_probability"], " : ", eachObject["box_points"] )
    print("--------------------------------")

in order to fix the error I had to replace the weights that I have loaded resnet50_coco_best_v2.0.1.h5 to the latest version which is resnet50_coco_best_v2.1.0.h5, download weights here

I simply replaced detector.setModelPath('weights/resnet50_coco_best_v2.0.1.h5') to detector.setModelPath('weights/resnet50_coco_best_v2.1.0.h5').

This has resolved my issue, I hope it fixed yours as well.

This solved mine too. Thanks!

drakorg commented 3 years ago

This v2.1.0.h5 should included in the docs, as far as I recall they still point to the v2.0.1, which doesn't work.

AllesGutehang commented 3 years ago

when I used 'resnet50_coco_bestv2.0.1.h5',I got the following issue: UnboundLocalError: local variable 'retval' referenced before assignment could someone help me

drakorg commented 3 years ago

Hi, please be aware that the latest version of resnet model requires v2.1.0.h5 not v2.0.1.h6.

On Fri, 6 Aug 2021 at 06:11 AllesGutehang @.***> wrote:

when I used 'resnet50_coco_bestv2.0.1.h5',I got the following issue: UnboundLocalError: local variable 'retval' referenced before assignment could someone help me

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/OlafenwaMoses/ImageAI/issues/629#issuecomment-894122095, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACK2RE2WMRLDRBZVZIGFB73T3ORKLANCNFSM4WE4HLNA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email .

AllesGutehang commented 3 years ago

Hi, please be aware that the latest version of resnet model requires v2.1.0.h5 not v2.0.1.h6. On Fri, 6 Aug 2021 at 06:11 AllesGutehang @.***> wrote: when I used 'resnet50_coco_bestv2.0.1.h5',I got the following issue: UnboundLocalError: local variable 'retval' referenced before assignment could someone help me — You are receiving this because you commented. Reply to this email directly, view it on GitHub <#629 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACK2RE2WMRLDRBZVZIGFB73T3ORKLANCNFSM4WE4HLNA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email .

thank you for your reply. I'm sorry that I write the wrong name of the model. I exactly used the resnet50_coco_bestv2.1.0.h5, and I met the following issue: UnboundLocalError: local variable 'retval' referenced before assignment I found the same the issue in stackoverflow(https://stackoverflow.com/questions/66905307/error-unboundlocalerror-local-variable-retval-referenced-before-assignment) but there is no answer.

drakorg commented 3 years ago

It happened to me that I had both h5 files in the same directory ... and i still kept a reference to the old one when setting the path to the model in the new version. If that has also been checked good luck with your hunting :)

On Fri, 6 Aug 2021 at 11:39 AllesGutehang @.***> wrote:

Hi, please be aware that the latest version of resnet model requires v2.1.0.h5 not v2.0.1.h6. … <#m-3624428415556895693> On Fri, 6 Aug 2021 at 06:11 AllesGutehang @.***> wrote: when I used 'resnet50_coco_bestv2.0.1.h5',I got the following issue: UnboundLocalError: local variable 'retval' referenced before assignment could someone help me — You are receiving this because you commented. Reply to this email directly, view it on GitHub <#629 (comment) https://github.com/OlafenwaMoses/ImageAI/issues/629#issuecomment-894122095>, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACK2RE2WMRLDRBZVZIGFB73T3ORKLANCNFSM4WE4HLNA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email .

thank you for your reply. I'm sorry that I write the wrong name of the model. I exactly used the resnet50_coco_bestv2.1.0.h5, and I met the following issue: UnboundLocalError: local variable 'retval' referenced before assignment I found the same the issue in stackoverflow( https://stackoverflow.com/questions/66905307/error-unboundlocalerror-local-variable-retval-referenced-before-assignment) but there is no answer.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/OlafenwaMoses/ImageAI/issues/629#issuecomment-894306911, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACK2REYH2X7RPBN5J25PHE3T3PXYPANCNFSM4WE4HLNA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email .

s4lm-xi commented 2 years ago

Imagine coming back facing the same issue and finding that you posted the solution to this issue years ago and it was approved. Feels great.

Could we close this issue please.

1YasserAmmar1 commented 2 years ago

Just download the last upgrade of the resent file you can find it here

https://github.com/fizyr/keras-retinanet/releases ;}

the answer is above too from the user "drakorg" thx man :}