Semantic-Segmentation-Suite
Semantic-Segmentation-Suite copied to clipboard
Trained model into a pb file
I want to turn the trained model into a pb file, but I don't know how to do it. Any good methods or suggestions?
Hey @gulingfengze, check out this answer on stackoverflow.
Hi @gulingfengze
Did you succeed on generating the pb file? I am still struggling to do it.
Thanks.
@dtchuink I'm sorry, I tried many times, but failed to generate pb file successfully.
I was able to generate pb file and perform the inference with it.Output looks very good for me. i used front end as Mobilenetv2 and SUPPORTED_MODEL mobileunet. **Note:**while downloading the codes rename it to .py format to run in Python.
Step1: During training you have to use an extra line after loss = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(logits=network, labels=net_output)) New line is: new_network = tf.nn.softmax(network, name="softmax_output")#you can provide suitable output node name
Step2: Generate checkpoint file. it should contain 4 files. checkpoint,meta file,index file and a data file
Step3: Generate Pb file using below code:ckpt2pb.py ckpt2pb.txt
step4: You can optimize this graph using graph transformation tool:
bazel-bin/tensorflow/tools/graph_transforms/transform_graph
--in_graph=generated_graph.pb
--out_graph=optimized_graph.pb
--inputs='Placeholder'
--outputs='softmax_output'
--transforms='
add_default_attributes
strip_unused_nodes(type=float, shape="1,299,299,3")
remove_nodes(op=Identity, op=CheckNumerics)
fold_constants(ignore_errors=true)
fold_batch_norms
fold_old_batch_norms
quantize_weights
quantize_nodes
strip_unused_nodes
sort_by_execution_order'
step5: use this optimised pb file for inference using the below code:(slight modification made in the predict.py code):predictwithpb.py predictwithpb.txt
with the help of tensorboard, we can visualize this graph.
@snehasusan2142 hello, i found one question, i kan convert ckpt mokel to pb model, but the pb model is small ,just 700k, but the ckpt model is 10M , the ckpt model can give good result , but i load tflite model , the result is wrong, i can't find the reason. It's good if you can give me some sugestion. @GeorgeSeif