Can not compile Tensorflow mobilenet_v2 model

I was able to successfully compile non-quantized Tensorflow mobilenet_v1 model mobilenet_v1_1.0_224_frozen.pb

but when I tried to compile v2 model mobilenet_v2_1.0_224_frozen.pb I got the following error:

Traceback (most recent call last):
  File "./compile.py", line 32, in <module>
    sym, params = relay.frontend.from_tensorflow(graph_def, shape={'input:0': (1, 224, 224, 3)}, layout='NCHW')
  File "/usr/local/lib/python3.5/dist-packages/tvm-0.6.dev0-py3.5-linux-x86_64.egg/tvm/relay/frontend/tensorflow.py", line 2347, in from_tensorflow
    sym, params = g.from_tensorflow(graph, layout, shape, outputs)
  File "/usr/local/lib/python3.5/dist-packages/tvm-0.6.dev0-py3.5-linux-x86_64.egg/tvm/relay/frontend/tensorflow.py", line 1992, in from_tensorflow
    op = self._convert_operator(node.op, inputs, attr, graph)
  File "/usr/local/lib/python3.5/dist-packages/tvm-0.6.dev0-py3.5-linux-x86_64.egg/tvm/relay/frontend/tensorflow.py", line 2310, in _convert_operator
    sym = convert_map[op_name](inputs, attrs, self._params)
  File "/usr/local/lib/python3.5/dist-packages/tvm-0.6.dev0-py3.5-linux-x86_64.egg/tvm/relay/frontend/tensorflow.py", line 736, in _impl
    return _op.clip(inputs[0], a_min=0, a_max=6)
IndexError: list index out of range

# _relu6 inputs: []

I looked at tensorflow.py line 736. It is _relu6() method. For some reasons inputs parameter is empty list

v1 model was downloaded from
https://github.com/tensorflow/models/blob/master/research/slim/nets/mobilenet_v1.md
v2 model was downloaded from https://github.com/tensorflow/models/blob/master/research/slim/nets/mobilenet/README.md

i have the same erroe, who can solve it?

I solved the problem by running transform_graph tensorflow util
Resulting file mobilenet_v2_1.0_224_opt.pb can be compiled by TVM.

transform_graph \
--in_graph=mobilenet_v2_1.0_224_frozen.pb \
--out_graph=mobilenet_v2_1.0_224_opt.pb \
--inputs='input' \
--outputs='MobilenetV2/Predictions/Reshape_1' \
--transforms='
strip_unused_nodes(type=float, shape="1,224,224,3")
remove_nodes(op=Identity, op=CheckNumerics)
fold_constants(ignore_errors=true)
fold_batch_norms
fold_old_batch_norms'

More details: https://github.com/tensorflow/tensorflow/tree/master/tensorflow/tools/graph_transforms#optimizing-for-deployment

1 Like

what’s the big difference between these two .pb files? thanks

$ summarize_graph --in_graph="./mobilenet_v2_1.0_224_opt.pb"
Found 1 possible inputs: (name=input, type=float(1), shape=None) 
No variables spotted.
Found 1 possible outputs: (name=MobilenetV2/Predictions/Reshape_1, op=Reshape) 
Found 3510507 (3.51M) const parameters, 0 (0) variable parameters, and 0 control_edges
Op types used: 158 Const, 36 BiasAdd, 36 Conv2D, 35 Relu6, 17 DepthwiseConv2dNative, 17 FusedBatchNorm, 10 Add, 2 Reshape, 1 AvgPool, 1 Placeholder, 1 Shape, 1 Softmax, 1 Squeeze

$ summarize_graph --in_graph="./mobilenet_v2_1.0_224_frozen.pb"
Found 1 possible inputs: (name=input, type=float(1), shape=None) 
No variables spotted.
Found 1 possible outputs: (name=MobilenetV2/Predictions/Reshape_1, op=Reshape) 
Found 3510507 (3.51M) const parameters, 0 (0) variable parameters, and 0 control_edges
Op types used: 158 Const, 36 BiasAdd, 36 Conv2D, 35 Relu6, 17 DepthwiseConv2dNative, 17 FusedBatchNorm, 10 Add, 2 Reshape, 1 AvgPool, 1 Placeholder, 1 Shape, 1 Softmax, 1 Squeeze


$ ls -la ./mobilenet_v2_1.0_224_opt.pb
-rw-r--r-- 1 root root 14083955 Jun 26 22:43 ./mobilenet_v2_1.0_224_opt.pb

$ ls -la ./mobilenet_v2_1.0_224_frozen.pb
-rw-r--r-- 1 root root 14083951 Mar 21  2018 ./mobilenet_v2_1.0_224_frozen.pb

Files can be downloaded here: