# dnn::readNetFromTensorflow() fail on loading pre-trained network on age-gender detection

Dear opencv dnn developers,

[Environment] TensorFlow 1.5 python 3.5 Win7 opencv3.4

I am very new to the Tensor flow. Recently I found a pretrained dnn for age gender detection https://github.com/BoyuanJiang/Age-Gender-Estimate-TF. The model is defined in "inception_resnet_v1.py" and the latest model checkpoints can be found https://mega.nz/#!kaZkWDjb!xQvWi9B--FgyIPtIYfjzLDoJeh2PUBEZPotmzO9N6_M

I loaded model with the latest check point into Tensor Flow and running detection ok, and managed to freeze the graph using freeze_graph.py but when I load this frozen graph by cv::dnn::readNetFromTensorflow("XXX.pb"), it gets error:..."Unknown layer type shape in op map/Shape)".... or I tried cv::dnn::readNetFromTensorflow("XXX.pb", "XXX.pbtxt"), it also gets error:...unknown enumeration values of "DT_RESOURCE" for field "type..."

I have searched over the internet trying to find a solution... someone suggested using "optimize_for_inference" or "graph_transform" might help. As I have limited Tensor Flow knowledge, I do not understand how these two processes can solve the problem. and Also, cv::dnn::readNetFromTensorflow() method has the 2nd argument, which I also do not know in what situation I should/should not provide a .pbtxt for it?

Please help. If there is any further information needed to clarify the question, just let me know and I will supply.

Thanks in advance

@Paul Kuo, please attach a reference to a frozen graph.

Hi, dkurt, Thank you for your reply. The detail of getting the frozen graph is described below... .....

## after loading the model, we perform some age-gendger detection and then save it again and is going to convet to a frozen graph

saver.save(sess, "./pbs/model_XXX.ckpt") #save to a check point

tf.train.write_graph(sess.graph_def, ".\pbs", "graphDef.pb", as_text=False) # saved in binary form

tf.train.write_graph(sess.graph_def, ".\pbs", "graphDef.pbtxt", as_text=True) # saved in text form .....

And then run freeze_graph.py (provided from tensorflow/python/tools) with the script below...

python freeze_graph.py --input_graph=./pbs/graphDef.pb --input_checkpoint=./pbs/model_XXX.ckpt --output_graph =./pbs/frozenGraph.pb --output_node_names=genderOut,ageOut --input_binary=true

then a frozenGraph.pb is generated.

Here you can download my generated "graphDef.pb" "graphDef.pbtxt" and "frozenGraph.pb" from https://www.dropbox.com/sh/l48teumzewpece8/AAA8T2brnQBnanh_gGMkY4Fra?dl=0 and see if anyone can figure out any error from it...

Thanks

Hi @dkurt, is there any luck to fix this problem...?

Everyone, any suggestions will be appreciated...

Thank you