Intel® Distribution of OpenVINO™ Toolkit
Community assistance about the Intel® Distribution of OpenVINO™ toolkit, OpenCV, and all aspects of computer vision-related on Intel® platforms.
6392 Discussions

Assertion failed when using NCS running model.

王__济维
Beginner
634 Views

Hi.

I'm using opencv(4.0.1-openvino) to inference.

this is code:

import cv2 as cv
import numpy as np

net = cv.dnn.readNet('tensor_modelv1.4.xml', 'tensor_modelv1.4.bin')
net.setPreferableTarget(cv.dnn.DNN_TARGET_MYRIAD)

capture = cv.VideoCapture(0, cv.CAP_V4L)
capture.set(3, 128.0)
capture.set(4, 128.0)
capture.set(5, 60.0)

while(True):
    ret, frame = capture.read()
    frame = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
    blob = cv.dnn.blobFromImage(frame, size=(128, 128), ddepth=cv.CV_8U)
    net.setInput(blob)
    out = net.forward()
    predict_chr = np.where(out == np.max(out))[1]
    if np.any(predict_chr >= 0):
        if np.all(predict_chr < 10):
            predict_chr = str(predict_chr[0])
        else:
            predict_chr = chr(predict_chr[0] + 55)
        frame = cv.putText(frame, predict_chr, (10, 25), cv.FONT_HERSHEY_SIMPLEX, 1.0, (255, 255, 255), 2)
    cv.imshow('frame', frame)
    if cv.waitKey(1) == ord('q'):
        break

it actually work at before. As usual , I change the model struct(Keras) for better performance and using model optimizer to generate the IR file. Unexpectedly, the inference engine doesn't work . and it output an error information:

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/home/corazon/pycharm-2018.3.5/helpers/pydev/_pydev_bundle/pydev_umd.py", line 197, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
  File "/home/corazon/pycharm-2018.3.5/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "/home/corazon/PycharmProjects/AI_Desktop/keras_cv/NCS_Test.py", line 16, in <module>
    out = net.forward()
cv2.error: OpenCV(4.0.1-openvino) /home/jenkins/workspace/OpenCV/OpenVINO/build/opencv/modules/dnn/src/op_inf_engine.cpp:553: error: (-215:Assertion failed) Failed to initialize Inference Engine backend: [VPU] Internal error: Output in max_pooling2d_2/MaxPool has incorrect width dimension. Expected: 31 or 31 Actual: 30 in function 'initPlugin'

I don't know what's happen, I tried to use old model which can work before, but it also doesn't work now,it rising the same error information.

But using NCS to run the demo (interactive_face_detection_demo) is working. so I guess isn't hardware problem.

The interesting thing is: if I change the device to CPU (cv.dnn.DNN_TARGET_CPU), it working as expect.

I have no idea to deal this problem.what should I do ? T_T

0 Kudos
4 Replies
Shubha_R_Intel
Employee
634 Views

T_T, so if i understand you correctly, it works perfectly fine when you change the device to CPU (cv.dnn.DNN_TARGET_CPU) ? If all you change is the device to cv.dnn.DNN_TARGET_MYRIAD this seems like a bug.

Can you kindly attach your frozen tensorflow model, IR (and python code) here as a zip file so that I can reproduce your bug ? Also please give me the exact MO command you used to produce your IR. Since you started with Keras I assume that you converted the Keras model to frozen tensorflow first before you invoked model optimizer ?

Thanks for using OpenVino !

Shubha

0 Kudos
王__济维
Beginner
634 Views

Thanks for your reply!

There are my files that you need,  this problem still exist and I have no idea to solve it...

I already transform my Keras model in FP_16 and FP_32, you can change "IR_cv.py" files to reproduce bugggggggggg :(

And forgive my English proficiency  :D

0 Kudos
Shubha_R_Intel
Employee
634 Views

Hi 王, 济维, I don't see any zip files attached ? I have sent you a PM so that you can send them to me privately.

Thanks,

Shubha

0 Kudos
Shubha_R_Intel
Employee
634 Views

Dear 王, 济维,

I went ahead and tried your code with OpenVino 2019 R1 and on NCS2.  Here are the first few lines of your IR_cv.py :

net = cv.dnn.readNet('NandW.xml', 'NandW.bin')
#net = cv.dnn.readNet('tensor_modelv1.4.xml', 'tensor_modelv1.4.bin')
net.setPreferableTarget(cv.dnn.DNN_TARGET_MYRIAD)
#net.setPreferableTarget(cv.dnn.DNN_TARGET_CPU)

capture = cv.VideoCapture(0)
print(capture.isOpened())

I had to change the arguments to cv.VideoCapture from capture = cv.VideoCapture(0, cv.CAP_V4L) to what i have  above. But the code works fine. 

You never sent me 'tensor_modelv1.4.xml', 'tensor_modelv1.4.bin' however (through the PM).  You only sent me NandW and NandW_32 *.bin, *.xml and *.mapping files.

I think if you download OpenVino 2019 R1 you will no longer have this problem.

As a tip I have noticed this. If something bombs and OpenVino suddenly stops working normally, you can get things back to a sane state by opening up a new shell and re-running setupvars.bat (or the Linux version setupvars.sh). 

Thanks for using OpenVino !

Shubha

0 Kudos
Reply