Hi,
I was working on Keras to train a model. I have used ResNet50 model with imageNet weights and I did fine-tuning on model and save weights as *.h5.
I have looked documentation convert tensorflow to IR and seen that freezing is required, I write a python code to convert .h5 file to .pb(with freeze operation). However when I tried model_optimizer to convert my model to IR there are some erros that I couldn't figure out.
python mo.py --input_model <path_to_model>
[ ERROR ] FusedBatchNorm doesn't support is_training=True
[ ERROR ] FusedBatchNorm doesn't support is_training=True
[ ERROR ] FusedBatchNorm doesn't support is_training=True
[ ERROR ] FusedBatchNorm doesn't support is_training=True
[ ERROR ] FusedBatchNorm doesn't support is_training=True
[ ERROR ] FusedBatchNorm doesn't support is_training=True
[ ERROR ] FusedBatchNorm doesn't support is_training=True
[ ERROR ] FusedBatchNorm doesn't support is_training=True
[ ERROR ] FusedBatchNorm doesn't support is_training=True
[ ERROR ] FusedBatchNorm doesn't support is_training=True
[ ERROR ] FusedBatchNorm doesn't support is_training=True
[ ERROR ] FusedBatchNorm doesn't support is_training=True
[ ERROR ] FusedBatchNorm doesn't support is_training=True
[ ERROR ] FusedBatchNorm doesn't support is_training=True
[ ERROR ] FusedBatchNorm doesn't support is_training=True
[ ERROR ] FusedBatchNorm doesn't support is_training=True
[ ERROR ] FusedBatchNorm doesn't support is_training=True
[ ERROR ] FusedBatchNorm doesn't support is_training=True
[ ERROR ] FusedBatchNorm doesn't support is_training=True
[ ERROR ] FusedBatchNorm doesn't support is_training=True
[ ERROR ] FusedBatchNorm doesn't support is_training=True
[ ERROR ] FusedBatchNorm doesn't support is_training=True
[ ERROR ] FusedBatchNorm doesn't support is_training=True
[ ERROR ] FusedBatchNorm doesn't support is_training=True
[ ERROR ] FusedBatchNorm doesn't support is_training=True
[ ERROR ] FusedBatchNorm doesn't support is_training=True
[ ERROR ] FusedBatchNorm doesn't support is_training=True
[ ERROR ] FusedBatchNorm doesn't support is_training=True
[ ERROR ] FusedBatchNorm doesn't support is_training=True
[ ERROR ] FusedBatchNorm doesn't support is_training=True
[ ERROR ] FusedBatchNorm doesn't support is_training=True
[ ERROR ] FusedBatchNorm doesn't support is_training=True
[ ERROR ] FusedBatchNorm doesn't support is_training=True
[ ERROR ] FusedBatchNorm doesn't support is_training=True
[ ERROR ] FusedBatchNorm doesn't support is_training=True
[ ERROR ] FusedBatchNorm doesn't support is_training=True
[ ERROR ] FusedBatchNorm doesn't support is_training=True
[ ERROR ] FusedBatchNorm doesn't support is_training=True
[ ERROR ] FusedBatchNorm doesn't support is_training=True
[ ERROR ] FusedBatchNorm doesn't support is_training=True
[ ERROR ] FusedBatchNorm doesn't support is_training=True
[ ERROR ] FusedBatchNorm doesn't support is_training=True
[ ERROR ] FusedBatchNorm doesn't support is_training=True
[ ERROR ] FusedBatchNorm doesn't support is_training=True
[ ERROR ] FusedBatchNorm doesn't support is_training=True
[ ERROR ] FusedBatchNorm doesn't support is_training=True
[ ERROR ] FusedBatchNorm doesn't support is_training=True
[ ERROR ] FusedBatchNorm doesn't support is_training=True
[ ERROR ] FusedBatchNorm doesn't support is_training=True
[ ERROR ] FusedBatchNorm doesn't support is_training=True
[ ERROR ] FusedBatchNorm doesn't support is_training=True
[ ERROR ] FusedBatchNorm doesn't support is_training=True
[ ERROR ] FusedBatchNorm doesn't support is_training=True
[ ERROR ] Cannot infer shapes or values for node "sequential_1/dropout_1/cond/Switch".
[ ERROR ] 0
[ ERROR ]
[ ERROR ] It can happen due to bug in custom shape infer function <function tf_native_tf_node_infer at 0x7f5e93619378>.
[ ERROR ] Or because the node inputs have incorrect values/shapes.
[ ERROR ] Or because input shapes are incorrect (embedded to the model or passed via --input_shape).
[ ERROR ] Run Model Optimizer with --log_level=DEBUG for more information.
[ ERROR ] Stopped shape/value propagation at "sequential_1/dropout_1/cond/Switch" node.
For more information please refer to Model Optimizer FAQ (<INSTALL_DIR>/deployment_tools/documentation/docs/MO_FAQ.html), question #38.
can anyone help me?
链接已复制
Hi,
Have tried building with keras and found out that
after saving the weights as *h5,
1)remove all dropout and batch normalisation layers from your keras model
2)then freeze graph to .pb file
3)then use model_optimizer to convert model to IR
and you should be able to get the resulted xml and bin files.
Dear Kürsat and Kai,
I created a python file (PM me to get it) that basically resumes the steps described by Kai, the line: K.set_learning_phase(0) sets the model in inference mode (withdrawing the dropout and modifying the BatchNorm layer). Then, the model is converted to Tensorflow and is frozen. It is a simplified version of this code: https://github.com/alanswx/keras_to_tensorflow/blob/master/convertkeras.py
Best,
Severine
Habert, Severine (Intel) wrote:Dear Kürsat and Kai,
I created a python file (PM me to get it) that basically resumes the steps described by Kai, the line: K.set_learning_phase(0) sets the model in inference mode (withdrawing the dropout and modifying the BatchNorm layer). Then, the model is converted to Tensorflow and is frozen. It is a simplified version of this code: https://github.com/alanswx/keras_to_tensorflow/blob/master/convertkeras.py
Best,
Severine
Dear Severine, I used the code that you are mentioning, but the problem persists. Can you provide your script?
