keras_to_tensorflow icon indicating copy to clipboard operation
keras_to_tensorflow copied to clipboard

Error predicting after converting to .pb file

Open Purav-Zumkhawala opened this issue 5 years ago • 1 comments

I have a keras model where I trained YOLO v3 on custom dataset. Now I converted it to a tensorflow model using your script and am trying to make predictions using the following code

import tensorflow
import numpy
import cv2 as cv

cvNet = cv.dnn.readNetFromTensorflow("model/tf_model.pb")

img = cv.imread('/media/purav/24D2B69BD2B67122/AutoFolder/a.jpg')
rows = img.shape[0]
cols = img.shape[1]
cvNet.setInput(cv.dnn.blobFromImage(img, size=(300, 300), swapRB=True, crop=False))
cvOut = cvNet.forward()

for detection in cvOut[0,0,:,:]:
    score = float(detection[2])
    if score > 0.3:
        left = detection[3] * cols
        top = detection[4] * rows
        right = detection[5] * cols
        bottom = detection[6] * rows
        cv.rectangle(img, (int(left), int(top)), (int(right), int(bottom)), (23, 230, 210), thickness=2)

cv.imshow('img', img)
cv.waitKey()

And when I run it I get the following error :

cv2.error: OpenCV(3.4.5) /io/opencv/modules/dnn/src/dnn.cpp:513: error: (-2:Unspecified error) Can't create layer "leaky_0/LeakyRelu" of type "LeakyRelu" in function 'getLayerInstance'

Any advice on how to solve this ?

Purav-Zumkhawala avatar Mar 25 '19 13:03 Purav-Zumkhawala

Have you checked this thread: https://answers.opencv.org/question/211175/cant-create-layer-leaky_0leakyrelu-of-type-leakyrelu-in-function-getlayerinstance/

It seems to be an OpenCV problem.

amir-abdi avatar Apr 24 '19 18:04 amir-abdi