[Frontend][Tensorflow] Report NCHW error when convert tensorflow graph into ARM Mali runtime

I tried to freeze the graph on GPU server but still have this error warning:

only support NCHW convolution on mali

Loading
Loading Done
Compiling
Traceback (most recent call last):
  File "convert_net_1.py", line 52, in <module>
    convert(nnvm_net, nnvm_params, (1,513, 513, 3) ,'float32','llvm --system-lib -target=aarch64-linux-gnu -mattr=+neon')
  File "convert_net_1.py", line 24, in convert
    dtype=dtype, target_host=target_host)
  File "/root/.local/lib/python2.7/site-packages/nnvm-0.8.0-py2.7.egg/nnvm/compiler/build_module.py", line 294, in build
    graph = graph.apply("GraphFusePartition").apply("GraphFuseCompile")
  File "/root/.local/lib/python2.7/site-packages/nnvm-0.8.0-py2.7.egg/nnvm/graph.py", line 234, in apply
    check_call(_LIB.NNGraphApplyPasses(self.handle, npass, cpass, ctypes.byref(ghandle)))
  File "/root/.local/lib/python2.7/site-packages/nnvm-0.8.0-py2.7.egg/nnvm/_base.py", line 75, in check_call
    raise NNVMError(py_str(_LIB.NNGetLastError()))
nnvm._base.NNVMError: TVMCall CFunc Error:
Traceback (most recent call last):
  File "/root/.local/lib/python2.7/site-packages/tvm-0.4.0-py2.7-linux-x86_64.egg/tvm/_ffi/_ctypes/function.py", line 54, in cfun
    rv = local_pyfunc(*pyargs)
  File "/root/.local/lib/python2.7/site-packages/nnvm-0.8.0-py2.7.egg/nnvm/top/nn.py", line 106, in compute_conv2d
    inputs[0], kernel, strides, padding, layout, out_dtype=out_dtype)
  File "<decorator-gen-35>", line 2, in conv2d
  File "/root/.local/lib/python2.7/site-packages/tvm-0.4.0-py2.7-linux-x86_64.egg/tvm/target.py", line 345, in dispatch_func
    return dispatch_dict[k](*args, **kwargs)
  File "/root/.local/lib/python2.7/site-packages/topi-0.4.0-py2.7.egg/topi/mali/conv2d.py", line 110, in decl_conv2d
    assert layout == 'NCHW', "only support NCHW convolution on mali"
AssertionError: only support NCHW convolution on mali

Can you share more details of the script that you are using? Somehow it looks like you are passing another, unsupported data layout, e.g., (NHWC).

Sure, the code is pretty simple:

Freeze graph:

freeze_graph_with_def_protos(my_graph_def,
         input_checkpoint=checkpoint_file,
         input_saver_def=None,
         output_node_names=output_node_names,
         restore_op_name="save/restore_all",
         filename_tensor_name="save/Const:0",
         output_graph=frozen_model_file,
         clear_devices=False,
         initializer_nodes="")

Converting:

def convert(net, params, data_shape, dtype, target_host):
    # compile
    opt_level = 2 if dtype == 'float32' else 1
    with nnvm.compiler.build_config(opt_level=opt_level):
        print("Compiling")
        graph, lib, params = nnvm.compiler.build(
            net, tvm.target.mali(), shape={"image": data_shape}, params=params,
            dtype=dtype, target_host=target_host)
        print("Compiling Done")

    lib.export_library('./net1.tar')

    with open("./net1", "w") as fo:
        fo.write(graph.json())
    with open("./net1.params", "wb") as fo:
        fo.write(nnvm.compiler.save_param_dict(params))
model_name = 'frozen_model.pb'
with tf.gfile.FastGFile(os.path.join(
        "./", model_name), 'rb') as f:
    graph_def = tf.GraphDef()
    graph_def.ParseFromString(f.read())

    detection_graph = tf.Graph()
    with detection_graph.as_default():
        #graph_def = tf.GraphDef()
        graph = tf.import_graph_def(graph_def, name='')
        graph_def = tf.get_default_graph().as_graph_def(add_shapes=True)
    # Call the utility to import the graph definition into default graph.
    graph_def = nnvm.testing.tf.ProcessGraphDefParam(graph_def)

    tf.import_graph_def(graph_def, name='')
    graph_def = tf.get_default_graph().as_graph_def(add_shapes=True)
print("Loading")
nnvm_net, nnvm_params = nnvm.frontend.from_tensorflow(graph_def)
print("Loading Done")
convert(nnvm_net, nnvm_params, (1,513, 513, 3) ,'float32','llvm --system-lib -target=aarch64-linux-gnu -mattr=+neon')

Oh, it seems the pre-tained model conv2d layer constructed with NHWC.

https://www.tensorflow.org/api_docs/python/tf/nn/conv2d