ImageAI icon indicating copy to clipboard operation
ImageAI copied to clipboard

Unknown layer: NonMaximumSuppression in imageAI Detection demo

Open sxbug opened this issue 4 years ago • 15 comments

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 avatar Jan 16 '21 02:01 sxbug

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 avatar Jan 16 '21 09:01 sxbug

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

sxbug avatar Jan 17 '21 02:01 sxbug

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

vangorade avatar Jan 17 '21 15:01 vangorade

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!

sxbug avatar Jan 19 '21 01:01 sxbug

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: [email protected]

yubg avatar Mar 02 '21 15:03 yubg

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.

s4lm-xi avatar Apr 01 '21 15:04 s4lm-xi

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.

ChenZheChina avatar Apr 20 '21 09:04 ChenZheChina

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!

JiaYee avatar Jul 13 '21 07:07 JiaYee

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.

drakorg avatar Aug 03 '21 00:08 drakorg

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

AllesGutehang avatar Aug 06 '21 09:08 AllesGutehang

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_best_v2.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 .

drakorg avatar Aug 06 '21 12:08 drakorg

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_best_v2.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_best_v2.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.

AllesGutehang avatar Aug 06 '21 14:08 AllesGutehang

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_best_v2.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_best_v2.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 .

drakorg avatar Aug 06 '21 14:08 drakorg

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.

s4lm-xi avatar Jul 29 '22 14:07 s4lm-xi

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

1YasserAmmar1 avatar Nov 19 '22 04:11 1YasserAmmar1