mace: Segmentation fault for DepthwiseConv2d INT8 (CAFFE)

Before you open an issue, please make sure you have tried the following steps:

  1. Make sure your environment is the same with (https://mace.readthedocs.io/en/latest/installation/env_requirement.html).
  2. Have you ever read the document for your usage?
  3. Check if your issue appears in HOW-TO-DEBUG or FAQ.
  4. The form below must be filled.

System information

  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Ubuntu 16.04
  • NDK version(e.g., 15c): 18b
  • GCC version(if compiling for host, e.g., 5.4.0): 5.4.0
  • MACE version (Use the command: git describe --long --tags): 0.11.0-rc0
  • Python version(2.7): 2.7
  • Bazel version (e.g., 0.13.0): 0.16.0

Model deploy file (*.yml)

# The name of library
library_name: model
target_abis: [arm64-v8a]
model_graph_format: file
model_data_format: file
models:
  sp: # model tag, which will be used in model loading and must be specific.
    platform: caffe
    # path to your tensorflow model's pb file. Support local path, http:// and https://
    model_file_path: /models/sp/model-nofc.prototxt
    weight_file_path: /models/sp/model-nofc.caffemodel
    # sha256_checksum of your model's pb file.
    # use this command to get the sha256_checksum --> sha256sum path/to/your/pb/file
    model_sha256_checksum: 54479f5ec821884f5bfcc03cb1f4558275541c6e80d9f33f65cc58562fffe91b 
    weight_sha256_checksum: e9599be0e9d5a5f08b85f9b98d2a76b55463ecb6820efc3bcdbc3ea0050f62a0 
    subgraphs:
      - input_tensors:
          - data
        input_shapes:
          - 1,3,112,112
        input_data_formats:
          - NCHW
        output_tensors:
          - fc1bn
        output_shapes:
          - 1,1,1,512
    obfuscate: 0
    quantize: 1
    quantize_range_file: /mace/overall_range
    runtime: cpu # cpu, gpu or cpu+gpu or dsp
    winograd: 0

Describe the problem

Segmentation fault happens when running quantized depthwise conv2d.

To Reproduce

Steps to reproduce the problem:

1. cd /path/to/mace
2. python tools/converter.py convert --config_file=/path/to/your/model_deployment_file
2. python tools/converter.py run --config_file=/path/to/your/model_deployment_file

Error information / logs

Please include the full log and/or traceback here. https://gist.github.com/gasgallo/619eb23800d7caf46e6e97ed23bfc38a

Additional context

Models runs fine w/o quantization.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 22 (17 by maintainers)

Most upvoted comments

Besides, lee-bin and lu229 are both on vocation. Maybe you can consult them after the Spring Festival.

@gasgallo It’s caused by filter format of depthwise conv in caffe. You can use this patch to fix it (apply on newest master code):

diff --git a/tools/python/transform/transformer.py b/tools/python/transform/transformer.py
index 69411e4..b3df498 100644
--- a/tools/python/transform/transformer.py
+++ b/tools/python/transform/transformer.py
@@ -1116,6 +1116,17 @@ class Transformer(base_converter.ConverterInterface):
                     filter.float_data[:] = filter_data.flat
                     filter.dims[:] = filter_data.shape
                     transposed_filter.add(op.input[1])
+                elif ConverterUtil.get_arg(
+                        op, MaceKeyword.mace_framework_type_str).i == \
+                                FrameworkType.CAFFE.value and \
+                                op.type == MaceOp.DepthwiseConv2d.name:
+                    filter = self._consts[op.input[1]]
+                    filter_data = np.array(filter.float_data).reshape(
+                        filter.dims)
+                    filter_data = filter_data.transpose(2, 3, 1, 0)
+                    filter.float_data[:] = filter_data.flat
+                    filter.dims[:] = filter_data.shape
+                    transposed_filter.add(op.input[1])
             # deconv's filter's output channel and input channel is reversed
             for op in net.op:
                 if op.type == MaceOp.Deconv2D.name and \

@gasgallo I don’t think the error on arm64-v8a is the same as the armeabi-v7a. the filter’s shape format should be OIHW, please reference: CPU runtime memory layout