0

I am testing out python opencv (cv2) to detect multiple images using openvino DNN models. My code for first detection:

import cv2
dog=cv2.imread("dog.jfif")
cat=cv2.imread("cat.jfif")
net=cv2.dnn.readNet("ssd_mobilenetv2_fp16_scale2.xml","ssd_mobilenetv2_fp16_scale2.bin")
blob=cv2.dnn.blobFromImage(dog)
net.setInput(blob)
out=net.forward()

Until here, no error is shown and print (out) shows that the "dog" detection is successful. But then when i continue the next detection of "cat" image by adding the next few lines:

blob=cv2.dnn.blobFromImage(cat)
net.setInput(blob)
out=net.forward()

And I get:

>>> out = net.forward()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
cv2.error: OpenCV(4.3.0-openvino) ../opencv/modules/dnn/src/ie_ngraph.cpp:522: error: (-215:Assertion failed) !isInitialized() in function 'initPlugin'

Why does this error occur? What is the correct way to do for the second detection?

Community
  • 1
  • 1
Hoo
  • 93
  • 10

1 Answers1

2

Probably you can try to run the dog and cat detection separately because the program might confuse of those 2 inputs that came at the same time during the implementation of blob.

Another workaround is, if you still want them to work simultaneously, name the blob differently such as:

For dog:

blob1=cv2.dnn.blobFromImage(dog)
net.setInput(blob1)

For cat

blob2=cv2.dnn.blobFromImage(cat)
net.setInput(blob2)

so that the function net.setInput(blob) doesn't get confuse on which input it should refer to.

Thanks!

Rommel_Intel
  • 1,369
  • 1
  • 4
  • 8