Ask Your Question
0

opencv4.1.1 dnn readNetFromTensorflow error

asked 2019-08-15 23:56:51 -0500

updated 2019-08-16 01:59:09 -0500

berak gravatar image

I have defined a keras model(.h5), and coverted to tensorflow (.pb). And it works on tensorflow :

 pb_path = r'*.pb'
 with tf.gfile.FastGFile(pb_path, 'rb') as f:
      graph_def = tf.GraphDef()
      graph_def.ParseFromString(f.read())
      _ = tf.import_graph_def(graph_def, name='')

 with tf.Session() as session:
      input = tf.get_default_graph().get_tensor_by_name("input_1:0")
      output_1 = tf.get_default_graph().get_tensor_by_name("trans/out_13/yolo_head/out_/concat:0")
      output_2 = tf.get_default_graph().get_tensor_by_name("trans/out_26/yolo_head/out_/concat:0")
      output_3 = tf.get_default_graph().get_tensor_by_name("trans/out_52/yolo_head/out_/concat:0")  
img = Image.open('/home/hyg/disk2/quanda_data/crop/1.png')
boxed_image = letterbox_image(img, (416, 416))
img = np.array(boxed_image, dtype='float32')
img *= 1./255.
img = np.expand_dims(img, axis=0)
out = session.run([output_1,output_2,output_3], feed_dict={input: img})

But when I use cv.dnn.readNetFromTensorflow("*.pb")

cv2.error: OpenCV(4.1.0) /io/opencv/modules/dnn/src/tensorflow/tf_importer.cpp:1383: error: (-215:Assertion failed) scaleMat.type() == CV_32FC1 in function 'populateNet'

So, I try to use the tensorflow tools (optimize_for_inference.py) to optimize the model

Use tf.compat.v1.graph_util.remove_training_nodes
WARNING:tensorflow:Didn't find expected Conv2D input to 'batch_normalization_2/FusedBatchNorm_1'
WARNING:tensorflow:Didn't find expected Conv2D input to 'batch_normalization_4/FusedBatchNorm_1'
WARNING:tensorflow:Didn't find expected Conv2D input to 'batch_normalization_7/FusedBatchNorm_1'
WARNING:tensorflow:Didn't find expected Conv2D input to 'batch_normalization_10/FusedBatchNorm_1'
WARNING:tensorflow:Didn't find expected Conv2D input to 'batch_normalization_13/FusedBatchNorm_1'
WARNING:tensorflow:Didn't find expected Conv2D input to 'batch_normalization_16/FusedBatchNorm_1'
WARNING:tensorflow:Didn't find expected Conv2D input to 'batch_normalization_19/FusedBatchNorm_1'
WARNING:tensorflow:Didn't find expected Conv2D input to 'batch_normalization_22/FusedBatchNorm_1'
WARNING:tensorflow:Didn't find expected Conv2D input to 'batch_normalization_25/FusedBatchNorm_1'
WARNING:tensorflow:Didn't find expected Conv2D input to 'batch_normalization_28/FusedBatchNorm_1'
WARNING:tensorflow:Didn't find expected Conv2D input to 'batch_normalization_31/FusedBatchNorm_1'
WARNING:tensorflow:Didn't find expected Conv2D input to 'batch_normalization_34/FusedBatchNorm_1'
WARNING:tensorflow:Didn't find expected Conv2D input to 'batch_normalization_37/FusedBatchNorm_1'
WARNING:tensorflow:Didn't find expected Conv2D input to 'batch_normalization_40/FusedBatchNorm_1'
WARNING:tensorflow:Didn't find expected Conv2D input to 'batch_normalization_43/FusedBatchNorm_1'
WARNING:tensorflow:Didn't find expected Conv2D input to 'batch_normalization_46/FusedBatchNorm_1'
WARNING:tensorflow:Didn't find expected Conv2D input to 'batch_normalization_49/FusedBatchNorm_1'
WARNING:tensorflow:Didn't find expected Conv2D input to 'batch_normalization_52/FusedBatchNorm_1'
WARNING:tensorflow:Didn't find expected Conv2D input to 'batch_normalization_55/FusedBatchNorm_1'
WARNING:tensorflow:Didn't find expected Conv2D input to 'batch_normalization_58/FusedBatchNorm_1'
WARNING:tensorflow:Didn't find expected Conv2D input to 'batch_normalization_61/FusedBatchNorm_1'
WARNING:tensorflow:Didn't find expected Conv2D input to 'batch_normalization_64/FusedBatchNorm_1'
WARNING:tensorflow:Didn't find expected Conv2D input to 'batch_normalization_67/FusedBatchNorm_1'
WARNING:tensorflow:Didn't find expected Conv2D input to 'batch_normalization_70/FusedBatchNorm_1'
WARNING:tensorflow:Didn't find expected Conv2D input to 'batch_normalization_73/FusedBatchNorm_1'
WARNING:tensorflow:Didn't find expected Conv2D input to 'batch_normalization_76/FusedBatchNorm_1'
WARNING:tensorflow:Didn't find expected Conv2D input to 'batch_normalization_79/FusedBatchNorm_1'
WARNING:tensorflow:Didn't find expected Conv2D input to 'batch_normalization_82/FusedBatchNorm_1'
WARNING:tensorflow:Didn't find expected Conv2D input to 'batch_normalization_85/FusedBatchNorm_1'
WARNING:tensorflow:Didn't find expected Conv2D input ...
(more)
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2019-08-19 03:49:58 -0500

can any one help me ?

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2019-08-15 23:56:51 -0500

Seen: 16 times

Last updated: 4 hours ago