Teach NNVM recognize tensorflow model

Hi, everyone, I want to teach NNVM recognize tensorflow model. I want to know anyone knows the tensorflow model specification like ONNX (https://github.com/onnx/onnx/blob/master/docs/IR.md) and NVVM’s model specification? Morever, anyone knows when to convert tensorflow model to NVVM, anythings I need to take care? Are there any existing tests I could leverage to make sure my conversion is right?

Thanks.

Currently we have ONNX to NNVM converter. If ONNX supports importing tf model, it shroud be able to convert to NNVM as well.

Another option is to directly add tf to nnvm converter, like existing frontend converters: https://github.com/dmlc/nnvm/tree/master/python/nnvm/frontend
You can start from those operators required by your application. For testing, you can refer to mxnet converter testing: https://github.com/dmlc/nnvm/tree/master/tests/python/frontend/mxnet

Thanks for replying. I have tested ONNX, but it seems that it is not mature, I convert mobilenet model occurred error(https://github.com/onnx/tensorflow-onnx/issues/7). So I think support tf to nnvm directly is good option.

For testing, thanks for the advice, I will leverage it in my implementation.

there is also related discussion on https://github.com/dmlc/nnvm/issues/234

My team also want to compile tensorflow model in the near future in order to deploy on server-class CPU. I found this link might be helpful (https://www.tensorflow.org/extend/tool_developers/)

However, seems that that guy doesn’t provide pull request and any further information.

Thanks for the information. I noticed that but it just list overview of tf model, doesn’t list more detail information such as op like ONNX / NNVM does.

We are working on tvm for now. You may get started on supporting tf first, guys in our team can join you soon.

Great! Glad to hear this. I will start to implement tf from next week.

How about the status? Have you implemented tf now? If yes, could you share it? Thanks.

Is it possible that import tf model to mxnet, then convert to NNVM? Is there any problem for this kind of conversion? Thanks.

https://github.com/dmlc/tvm/pull/1188

PR under review for tensorflow frontend.

Works good for InceptionV1 & V3.
Mobilenet also works for me with few changes which is yet to PR.

Hi,

I found your discussion of performance of resnet50 on tensorflow and tvm on https://github.com/dmlc/nnvm/issues/440.

Could you share how you converted tensorflow resnet50 model to nnvm? I tried to but failed, as Anyone successful converting tensorflow resnet50 model to nnvm?. If you would not mind sharing your advice, I appreciate it very much.

Thanks!

We have one fork of tvm. We have done many things on CoreML frontend. And we convert TF resnet50 to CoreML, then we conver CoreML to NNVM.

Did you encounter problems in converting resnet50 tf model to coreml? I had error messages as https://github.com/tf-coreml/tf-coreml/issues/210, but I saw you reported the error message on a different model. Any advice on how to solve the resnet50 conversion issue? Thanks a lot.

I don’t meet this error when to convert resnet50. You could try the way I mentioned in that issue.

@FrozenGene

I followed your advice converting tf resnet50 to coreml, and had the above problems.

My resnet50 model is the pretrained model ResNet-50 v1 or ResNet-50 v2 from https://github.com/tensorflow/models/tree/master/official/resnet. The model is in saved_model format. I freezed the model by

python freeze_graph.py --input_saved_model_dir=saved_model_dir --output_graph=frozen_model.pb --output_node_names=ArgMax --clear_devices

Freezing was successful. But both models raise
ValueError: Length of the 'dim' parameter must be equal to 4
when converted to coreml.

Shoudl I use a different tf resnet50 model? Could you share which tf resnet50 model you use and how you freeze it, if this is public information?

Thank you very much.

Just official resnet50 model provided by Tensorflow, not special. https://github.com/tensorflow/models/tree/master/research/slim

@FrozenGene

Did you use v1 or v2 on that page? How did you freeze it?

I downloaded v1, and used
python freeze_graph.py --input_graph=resnet_v1_50_inf_graph.pb --input_checkpoint=resnet_v1_50.ckpt --input_binary=true --output_graph=frozen_resnet_v1_50_slim.pb --output_node_names=resnet_v1_50/predictions/Reshape_1
to freeze it. But I got an error:

File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.py", line 1759, in restore
    err, "a mismatch between the current graph and the graph")
tensorflow.python.framework.errors_impl.InvalidArgumentError: Restoring from checkpoint failed. This is most likely due to a mismatch between the current graph and the graph from the checkpoint. Please ensure that you have not altered the graph expected based on the checkpoint. Original error:

Assign requires shapes of both tensors to match. lhs shape= [1,1,2048,1001] rhs shape= [1,1,2048,1000]

I use resnetv2 provided by it. Your error I remember export_inference_graph.py have one parameter can control it. You could investigate it.