Using readNetFromTensorflow() and running Frozen Graph, but Fails to predict correctly

asked 2017-09-26 05:45:32 -0600

mwh1989 gravatar image

I have a frozen graph that im trying to load into opencv 3.3 dnn in python. The graph works as I have loaded it separately using tf.import_graph_def() and predicts correctly. Opencv on the other hand runs the model but predicts completely wrong. I know that the function in opencv uses mean subtraction which i have tried both of all images and the input image mean BGR value, but it does not seem to help me. Any help would be greatly appreciated.


example code:

# read the testing data
test_data = np.load('../test_data.npy')

X = np.array([i[0] for i in test_data]).reshape(-1, 125, 50, 3)
Y = [i[1] for i in test_data]

mean = np.mean(X[2398], axis=( -2, -3))

blob = cv2.dnn.blobFromImage(X[2398], 1, (125, 50), mean)

net.setInput(blob, name="input/X")

start = time.time()

preds = net.forward(outputName="output_layer/Softmax")

end = time.time()

print("[INFO] classification took {:.5} seconds".format(end - start))
edit retag flag offensive close merge delete


@mwh1989, Is it possible to share the graph? I think it would be the fastest solution.

dkurt gravatar imagedkurt ( 2017-09-27 03:56:46 -0600 )edit