XiaoMi / mace

MACE is a deep learning inference framework optimized for mobile heterogeneous computing platforms.
Apache License 2.0
4.94k stars 819 forks source link

Error converting original ResNet_v1_50 Caffe model #233

Closed muendelezaji closed 6 years ago

muendelezaji commented 6 years ago

System information

Environment

$ uname -v -m
#35~16.04.1-Ubuntu SMP Thu Jan 25 10:13:43 UTC 2018 x86_64

$ git describe --long --tags
v0.9.0-246-g1d40ca5

$ python --version
Python 2.7.12

$ bazel version
Starting local Bazel server and connecting to it...
...........
Build label: 0.13.0
Build target: bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Mon Oct 18 21:33:40 +50297 (1525078013620)
Build timestamp: 1525078013620
Build timestamp as int: 1525078013620

$ cmake --version
cmake version 3.11.4

CMake suite maintained and supported by Kitware (kitware.com/cmake).

$ pip list | egrep -i '^(jinja2|pyyaml|sh|numpy|six|tensorflow|scipy|filelock) '
filelock                           3.0.0
Jinja2                             2.10
numpy                              1.14.0
PyYAML                             3.12
scipy                              1.0.0
sh                                 1.12.14
six                                1.11.0
tensorflow                         1.6.0

$ sed -n '/^Pkg.Revision/p' $ANDROID_NDK_HOME/source.properties
Pkg.Revision = 16.1.4479499

$ adb --version
Android Debug Bridge version 1.0.40
Version 4797878
Installed as /home/ML/.android/platform-tools/adb

Model deploy file (*.yml)

library_name: resnet-v1-50-caffe
target_abis: [arm64-v8a]
model_graph_format: file
model_data_format: file
models:
  resnet_v1_50_caffe:
    platform: caffe
    model_file_path: /home/ML/xiaomi/convert/resnet50/model.prototxt
    model_sha256_checksum: 4a2a788a24ad7fa839cf3246d7356b9abd6ae59ae87960db06f0bcbed08db7de
    weight_file_path: /home/ML/xiaomi/convert/resnet50/model.caffemodel
    weight_sha256_checksum: bdb40cf5c3839e7989dce17d3ecfa31a755df25817d9ad2d2fedaf0b04383780
    subgraphs:
      - input_tensors: input
        output_tensors: resnet_v1_50/predictions/Reshape_1
        input_shapes: 1,224,224,3
        output_shapes: 1,1001
    runtime: cpu+gpu
    limit_opencl_kernel_time: 0
    nnlib_graph_mode: 0
    obfuscate: 0
    winograd: 0

Describe the problem

I tried following the user guide to convert the original ResNet v1 50 model but it fails with the following error:

  File "/home/ML/xiaomi/mace/bazel-bin/mace/python/tools/converter.runfiles/mace/mace/python/tools/converter_tool/shape_inference.py", line 87, in infer_shape_conv_pool_shape
    input_shape = self._output_shape_cache[op.input[0]]
KeyError: u'data'

To Reproduce

Steps to reproduce the problem:

1. cd /path/to/mace
2. python tools/converter.py convert --config=../mace-models/resnet-v1-50/resnet-v1-50-caffe.yml --target_abis=arm64-v8a

Error information / logs

$ python tools/converter.py convert --config=../mace-models/resnet-v1-50/resnet-v1-50-caffe.yml --target_abis=arm64-v8a
-----------------------------------------
           Common Configuration
-----------------------------------------
|        key        |       value       |
=========================================
|       library_name| resnet-v1-50-caffe|
-----------------------------------------
|        target_abis|      ['arm64-v8a']|
-----------------------------------------
|        target_socs|                 []|
-----------------------------------------
| model_graph_format|               file|
-----------------------------------------
|  model_data_format|               file|
-----------------------------------------

****************************************************
          Convert resnet_v1_50_caffe model
****************************************************

INFO: Analysed target //mace/python/tools:converter (0 packages loaded).
INFO: Found 1 target...
Target //mace/python/tools:converter up-to-date:
  bazel-bin/mace/python/tools/converter
INFO: Elapsed time: 0.363s, Critical Path: 0.00s
INFO: 0 processes.
INFO: Build completed successfully, 1 total action

Transform model to one that can better run on device
Traceback (most recent call last):
  File "/home/ML/xiaomi/mace/bazel-bin/mace/python/tools/converter.runfiles/mace/mace/python/tools/converter.py", line 352, in <module>
    main(unused_args=[sys.argv[0]] + unparsed)
  File "/home/ML/xiaomi/mace/bazel-bin/mace/python/tools/converter.runfiles/mace/mace/python/tools/converter.py", line 165, in main
    output_graph_def = converter.run()
  File "/home/ML/xiaomi/mace/bazel-bin/mace/python/tools/converter.runfiles/mace/mace/python/tools/converter_tool/caffe_converter.py", line 218, in run
    shape_inferer.run()
  File "/home/ML/xiaomi/mace/bazel-bin/mace/python/tools/converter.runfiles/mace/mace/python/tools/converter_tool/shape_inference.py", line 66, in run
    self._op_shape_inference[op.type](op)
  File "/home/ML/xiaomi/mace/bazel-bin/mace/python/tools/converter.runfiles/mace/mace/python/tools/converter_tool/shape_inference.py", line 87, in infer_shape_conv_pool_shape
    input_shape = self._output_shape_cache[op.input[0]]
KeyError: u'data'
Traceback (most recent call last):
  File "tools/converter.py", line 1778, in <module>
    flags.func(flags)
  File "tools/converter.py", line 856, in convert_func
    convert_model(configs, flags.cl_mem_type)
  File "tools/converter.py", line 781, in convert_model
    ",".join(model_config.get(YAMLKeyword.graph_optimize_options, [])))
  File "/home/ML/xiaomi/mace/tools/sh_commands.py", line 601, in gen_model_code
    _fg=True)
  File "/home/ML/xiaomi/lib/python2.7/site-packages/sh.py", line 1413, in __call__
    raise exc
sh.ErrorReturnCode_1:

  RAN: /home/ML/xiaomi/bin/python bazel-bin/mace/python/tools/converter -u --platform=caffe --model_file=/home/ML/xiaomi/convert/resnet50/model.prototxt --weight_file=/home/ML/xiaomi/convert/resnet50/model.caffemodel --model_checksum=4a2a788a24ad7fa839cf3246d7356b9abd6ae59ae87960db06f0bcbed08db7de --weight_checksum=bdb40cf5c3839e7989dce17d3ecfa31a755df25817d9ad2d2fedaf0b04383780 --input_node=input --output_node=resnet_v1_50/predictions/Reshape_1 --runtime=cpu+gpu --template=mace/python/tools --model_tag=resnet_v1_50_caffe --input_shape=1,224,224,3 --input_range= --dsp_mode=0 --embed_model_data=False --winograd=0 --quantize=0 --quantize_range_file= --change_concat_ranges=0 --obfuscate=0 --output_dir=mace/codegen/models/resnet_v1_50_caffe --model_graph_format=file --data_type=fp16_fp32 --graph_optimize_options= --cl_mem_type=image

  STDOUT:

  STDERR:
liyinhgqw commented 6 years ago

Can you check the input tensor name of this model? Is it 'input' or 'data'?

muendelezaji commented 6 years ago

Ah, I missed that when porting. Input should have been data and output prob. Thanks