New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TOCO failed Batch normalization resolution requires that mean, multiplier and offset arrays be constant. #23253
Comments
same problem here (tensorflow-gpu 1.11.0) |
what? I am not understand |
I'm also facing same problem with facenet pretrain model, tensorflow 1.10.0, here is my command:
|
@tung238 is your model trained with quantization? 'inference_type=QUANTIZED_UINT8' and 'quantize_weights' are not meant to be used at the same time. If your model was trained with quantization, use 'inference_type=QUANTIZED_UINT8' and remove 'quantize_weights'. |
@sxsxsx Can you attach your model here? |
I am facing the same problem with my conversion, I'm attaching my model below. Command to convert - |
Looks like you're trying to convert a training graph. You first need to get a frozen EVAL graph and then convert it. |
@liyunlu0618 my model is frozen. |
I have the same issue |
i have the same issue too. |
I have the same issue as well |
Same issue. Is there a solution for this? |
same problem here, I am using |
I've solved my problem, my model uses a placeholder to initialize Batchnorm, so my exported diagram contains some Op nodes for training purposes. |
I think in the process of converting pb to tflite, everything wrong with batchnorm, that means this graph is not a clean prediction graph, is that right? |
anyone has a concrete solution to this? @liyunlu0618 can you elaborate more on this? |
Marking issue as resolved due to inactivity. Feel free to re-open this if it's unresolved or file a new issue |
System information
Describe the current behavior
toco --output_file=test.tflite --graph_def_file=freeze.pb --input_arrays=Placeholder --output_arrays=logits/BatchNorm/Reshape_1 --output_format=TFLITE --inference_type=FLOAT --std_dev_values=1 --mean_values=0
failed
Traceback (most recent call last):
File "/home/icare/.local/bin/toco", line 11, in
sys.exit(main())
File "/home/icare/.local/lib/python2.7/site-packages/tensorflow/contrib/lite/python/tflite_convert.py", line 320, in main
app.run(main=run_main, argv=sys.argv[:1])
File "/home/icare/.local/lib/python2.7/site-packages/tensorflow/python/platform/app.py", line 125, in run
_sys.exit(main(argv))
File "/home/icare/.local/lib/python2.7/site-packages/tensorflow/contrib/lite/python/tflite_convert.py", line 316, in run_main
_convert_model(tflite_flags)
File "/home/icare/.local/lib/python2.7/site-packages/tensorflow/contrib/lite/python/tflite_convert.py", line 121, in _convert_model
output_data = converter.convert()
File "/home/icare/.local/lib/python2.7/site-packages/tensorflow/contrib/lite/python/lite.py", line 309, in convert
allow_custom_ops=self.allow_custom_ops)
File "/home/icare/.local/lib/python2.7/site-packages/tensorflow/contrib/lite/python/convert.py", line 225, in toco_convert
input_data.SerializeToString())
File "/home/icare/.local/lib/python2.7/site-packages/tensorflow/contrib/lite/python/convert.py", line 107, in toco_convert_protos
(stdout, stderr))
RuntimeError: TOCO failed see console for info.
2018-10-25 17:33:59.010229: I tensorflow/contrib/lite/toco/graph_transformations/graph_transformations.cc:39] Before Removing unused ops: 135 operators, 224 arrays (0 quantized)
2018-10-25 17:33:59.011116: I tensorflow/contrib/lite/toco/graph_transformations/graph_transformations.cc:39] After Removing unused ops pass 1: 127 operators, 212 arrays (0 quantized)
2018-10-25 17:33:59.012209: I tensorflow/contrib/lite/toco/graph_transformations/graph_transformations.cc:39] Before general graph transformations: 127 operators, 212 arrays (0 quantized)
2018-10-25 17:33:59.012368: F tensorflow/contrib/lite/toco/graph_transformations/resolve_batch_normalization.cc:42] Check failed: IsConstantParameterArray(*model, bn_op->inputs[1]) && IsConstantParameterArray(*model, bn_op->inputs[2]) && IsConstantParameterArray(*model, bn_op->inputs[3]) Batch normalization resolution requires that mean, multiplier and offset arrays be constant.
Aborted (core dumped)
None
Describe the expected behavior
I want to use toco to transform the pb file to the tflite file
Code to reproduce the issue
I use the code below to generate graph.pb and ckpy file
g = tf.get_default_graph() graph_def = g.as_graph_def() tf.train.write_graph(graph_def, "./model", 'graph.pb', as_text=False) saver = tf.train.Saver() saver.save(sess, os.path.join(FLAGS.checkpoint_dir, 'mnist-conv-slim.ckpt'))
and then I freezed the graph.pb successfullly
python freeze_graph.py --input_graph=/payh/to/graph.pb --input_checkpoint=/payh/tpo/mnist-conv-slim.ckpt --output_graph=/payh/to/mobile_face/model/freeze.pb --output_node_names=logits/BatchNorm/Reshape_1 --input_binary=True
Other info / logs
I use the code below to watch the nodes of each layer
import tensorflow as tf gf = tf.GraphDef() #gf.ParseFromString(open('/tmp/inception_v3_quantized.pb','rb').read()) gf.ParseFromString(open('./model/freeze.pb','rb').read()) for n in gf.node: print ( n.name +' ===> '+n.op )
result:
Placeholder ===> Placeholder
Placeholder_1 ===> Placeholder
Placeholder_3 ===> Placeholder
Reshape/shape ===> Const
Reshape ===> Reshape
conv1/weights ===> Const
conv1/weights/read ===> Identity
conv1/Conv2D ===> Conv2D
conv1/BatchNorm/Const ===> Const
conv1/BatchNorm/beta ===> Const
conv1/BatchNorm/beta/read ===> Identity
conv1/BatchNorm/moving_mean ===> Const
conv1/BatchNorm/moving_mean/read ===> Identity
conv1/BatchNorm/moving_variance ===> Const
conv1/BatchNorm/moving_variance/read ===> Identity
conv1/BatchNorm/cond/Switch ===> Switch
conv1/BatchNorm/cond/switch_t ===> Identity
conv1/BatchNorm/cond/pred_id ===> Identity
conv1/BatchNorm/cond/Const ===> Const
conv1/BatchNorm/cond/Const_1 ===> Const
conv1/BatchNorm/cond/FusedBatchNorm ===> FusedBatchNorm
conv1/BatchNorm/cond/FusedBatchNorm/Switch ===> Switch
conv1/BatchNorm/cond/FusedBatchNorm/Switch_1 ===> Switch
conv1/BatchNorm/cond/FusedBatchNorm/Switch_2 ===> Switch
conv1/BatchNorm/cond/FusedBatchNorm_1 ===> FusedBatchNorm
conv1/BatchNorm/cond/FusedBatchNorm_1/Switch ===> Switch
conv1/BatchNorm/cond/FusedBatchNorm_1/Switch_1 ===> Switch
conv1/BatchNorm/cond/FusedBatchNorm_1/Switch_2 ===> Switch
conv1/BatchNorm/cond/FusedBatchNorm_1/Switch_3 ===> Switch
conv1/BatchNorm/cond/FusedBatchNorm_1/Switch_4 ===> Switch
conv1/BatchNorm/cond/Merge ===> Merge
conv1/CRelu/Neg ===> Neg
conv1/CRelu/axis ===> Const
conv1/CRelu ===> ConcatV2
conv1/CRelu/Relu ===> Relu
pool1/MaxPool ===> MaxPool
conv2/weights ===> Const
conv2/weights/read ===> Identity
conv2/Conv2D ===> Conv2D
conv2/BatchNorm/Const ===> Const
conv2/BatchNorm/beta ===> Const
conv2/BatchNorm/beta/read ===> Identity
conv2/BatchNorm/moving_mean ===> Const
conv2/BatchNorm/moving_mean/read ===> Identity
conv2/BatchNorm/moving_variance ===> Const
conv2/BatchNorm/moving_variance/read ===> Identity
conv2/BatchNorm/cond/Switch ===> Switch
conv2/BatchNorm/cond/switch_t ===> Identity
conv2/BatchNorm/cond/pred_id ===> Identity
conv2/BatchNorm/cond/Const ===> Const
conv2/BatchNorm/cond/Const_1 ===> Const
conv2/BatchNorm/cond/FusedBatchNorm ===> FusedBatchNorm
conv2/BatchNorm/cond/FusedBatchNorm/Switch ===> Switch
conv2/BatchNorm/cond/FusedBatchNorm/Switch_1 ===> Switch
conv2/BatchNorm/cond/FusedBatchNorm/Switch_2 ===> Switch
conv2/BatchNorm/cond/FusedBatchNorm_1 ===> FusedBatchNorm
conv2/BatchNorm/cond/FusedBatchNorm_1/Switch ===> Switch
conv2/BatchNorm/cond/FusedBatchNorm_1/Switch_1 ===> Switch
conv2/BatchNorm/cond/FusedBatchNorm_1/Switch_2 ===> Switch
conv2/BatchNorm/cond/FusedBatchNorm_1/Switch_3 ===> Switch
conv2/BatchNorm/cond/FusedBatchNorm_1/Switch_4 ===> Switch
conv2/BatchNorm/cond/Merge ===> Merge
conv2/CRelu/Neg ===> Neg
conv2/CRelu/axis ===> Const
conv2/CRelu ===> ConcatV2
conv2/CRelu/Relu ===> Relu
pool2/MaxPool ===> MaxPool
Flatten/flatten/Shape ===> Shape
Flatten/flatten/strided_slice/stack ===> Const
Flatten/flatten/strided_slice/stack_1 ===> Const
Flatten/flatten/strided_slice/stack_2 ===> Const
Flatten/flatten/strided_slice ===> StridedSlice
Flatten/flatten/Reshape/shape/1 ===> Const
Flatten/flatten/Reshape/shape ===> Pack
Flatten/flatten/Reshape ===> Reshape
fc1/weights ===> Const
fc1/weights/read ===> Identity
fc1/MatMul ===> MatMul
fc1/BatchNorm/Reshape/shape ===> Const
fc1/BatchNorm/Reshape ===> Reshape
fc1/BatchNorm/beta ===> Const
fc1/BatchNorm/beta/read ===> Identity
fc1/BatchNorm/Const ===> Const
fc1/BatchNorm/moving_mean ===> Const
fc1/BatchNorm/moving_mean/read ===> Identity
fc1/BatchNorm/moving_variance ===> Const
fc1/BatchNorm/moving_variance/read ===> Identity
fc1/BatchNorm/cond/Switch ===> Switch
fc1/BatchNorm/cond/switch_t ===> Identity
fc1/BatchNorm/cond/pred_id ===> Identity
fc1/BatchNorm/cond/Const ===> Const
fc1/BatchNorm/cond/Const_1 ===> Const
fc1/BatchNorm/cond/FusedBatchNorm ===> FusedBatchNorm
fc1/BatchNorm/cond/FusedBatchNorm/Switch ===> Switch
fc1/BatchNorm/cond/FusedBatchNorm/Switch_1 ===> Switch
fc1/BatchNorm/cond/FusedBatchNorm/Switch_2 ===> Switch
fc1/BatchNorm/cond/FusedBatchNorm_1 ===> FusedBatchNorm
fc1/BatchNorm/cond/FusedBatchNorm_1/Switch ===> Switch
fc1/BatchNorm/cond/FusedBatchNorm_1/Switch_1 ===> Switch
fc1/BatchNorm/cond/FusedBatchNorm_1/Switch_2 ===> Switch
fc1/BatchNorm/cond/FusedBatchNorm_1/Switch_3 ===> Switch
fc1/BatchNorm/cond/FusedBatchNorm_1/Switch_4 ===> Switch
fc1/BatchNorm/cond/Merge ===> Merge
fc1/BatchNorm/Shape ===> Shape
fc1/BatchNorm/Reshape_1 ===> Reshape
fc1/CRelu/Neg ===> Neg
fc1/CRelu/axis ===> Const
fc1/CRelu ===> ConcatV2
fc1/CRelu/Relu ===> Relu
Dropout/sub/x ===> Const
Dropout/sub ===> Sub
Dropout/sub_1/x ===> Const
Dropout/sub_1 ===> Sub
Dropout/dropout_1/Shape ===> Shape
Dropout/dropout_1/random_uniform/min ===> Const
Dropout/dropout_1/random_uniform/max ===> Const
Dropout/dropout_1/random_uniform/RandomUniform ===> RandomUniform
Dropout/dropout_1/random_uniform/sub ===> Sub
Dropout/dropout_1/random_uniform/mul ===> Mul
Dropout/dropout_1/random_uniform ===> Add
Dropout/dropout_1/add ===> Add
Dropout/dropout_1/Floor ===> Floor
Dropout/dropout_1/div ===> RealDiv
Dropout/dropout_1/mul ===> Mul
logits/weights ===> Const
logits/weights/read ===> Identity
logits/MatMul ===> MatMul
logits/BatchNorm/Reshape/shape ===> Const
logits/BatchNorm/Reshape ===> Reshape
logits/BatchNorm/beta ===> Const
logits/BatchNorm/beta/read ===> Identity
logits/BatchNorm/Const ===> Const
logits/BatchNorm/moving_mean ===> Const
logits/BatchNorm/moving_mean/read ===> Identity
logits/BatchNorm/moving_variance ===> Const
logits/BatchNorm/moving_variance/read ===> Identity
logits/BatchNorm/cond/Switch ===> Switch
logits/BatchNorm/cond/switch_t ===> Identity
logits/BatchNorm/cond/pred_id ===> Identity
logits/BatchNorm/cond/Const ===> Const
logits/BatchNorm/cond/Const_1 ===> Const
logits/BatchNorm/cond/FusedBatchNorm ===> FusedBatchNorm
logits/BatchNorm/cond/FusedBatchNorm/Switch ===> Switch
logits/BatchNorm/cond/FusedBatchNorm/Switch_1 ===> Switch
logits/BatchNorm/cond/FusedBatchNorm/Switch_2 ===> Switch
logits/BatchNorm/cond/FusedBatchNorm_1 ===> FusedBatchNorm
logits/BatchNorm/cond/FusedBatchNorm_1/Switch ===> Switch
logits/BatchNorm/cond/FusedBatchNorm_1/Switch_1 ===> Switch
logits/BatchNorm/cond/FusedBatchNorm_1/Switch_2 ===> Switch
logits/BatchNorm/cond/FusedBatchNorm_1/Switch_3 ===> Switch
logits/BatchNorm/cond/FusedBatchNorm_1/Switch_4 ===> Switch
logits/BatchNorm/cond/Merge ===> Merge
logits/BatchNorm/Shape ===> Shape
logits/BatchNorm/Reshape_1 ===> Reshape
It seems that the BN para are already constant
what should I do to solver the problem?
good luck to you thanks
The text was updated successfully, but these errors were encountered: