open-mmlab / mmdeploy

OpenMMLab Model Deployment Framework
https://mmdeploy.readthedocs.io/en/latest/
Apache License 2.0
2.74k stars 627 forks source link

[Bug] #2222

Closed chen-del closed 1 year ago

chen-del commented 1 year ago

Checklist

Describe the bug

I am not very proficient in using mmdeploy. The framework configuration that originally exported the model is no longer applicable. I used torch.onnx.export for direct export, but I encountered a problem, and a TypeError: forward() missing 1 appeared. required positional argument: 'data_samples', what is the reason for this? Thanks!

Reproduction

import argparse import warnings

import numpy as np import torch import io from mmpose.apis import init_model

from mmcv.runner import load_checkpoint

try: import onnx import onnxruntime as rt except ImportError as e: raise ImportError(f'Please install onnx and onnxruntime first. {e}')

def _convert_batchnorm(module): """Convert the syncBNs into normal BN3ds.""" module_output = module if isinstance(module, torch.nn.SyncBatchNorm): module_output = torch.nn.BatchNorm3d(module.num_features, module.eps, module.momentum, module.affine, module.track_running_stats) if module.affine: module_output.weight.data = module.weight.data.clone().detach() module_output.bias.data = module.bias.data.clone().detach()

keep requires_grad unchanged

        module_output.weight.requires_grad = module.weight.requires_grad
        module_output.bias.requires_grad = module.bias.requires_grad
    module_output.running_mean = module.running_mean
    module_output.running_var = module.running_var
    module_output.num_batches_tracked = module.num_batches_tracked
for name, child in module.named_children():
    module_output.add_module(name, _convert_batchnorm(child))
del module
return module_output

def pytorch2onnx(model, opset_version=11, out='tmp.onnx'): """Convert pytorch model to onnx model.

Args:
    model (:obj:`nn.Module`): The pytorch model to be exported.
    opset_version (int): Opset version of onnx used. Default: 11.
    out (str): Output onnx model name. Default: 'tmp.onnx'.
"""
print(model)
model.cpu().eval()

inputs = torch.ones(1,3,256,256)
# inputs = torch.randn(input_shape)
with torch.no_grad():
    with io.BytesIO() as f:
        torch.onnx.export(
            model,
            inputs,
            f,
            opset_version=opset_version,
            export_params=True,
            strip_doc_string=True,
            keep_initializers_as_inputs=True,
            do_constant_folding=True,
            input_names=["input_0"],
            output_names=["output"]
        )
        onnx_model = onnx.load_from_string(f.getvalue())

return onnx_model

def parse_args(): parser = argparse.ArgumentParser( description='Convert MMPose models to ONNX') parser.add_argument('config', help='test config file path') parser.add_argument('checkpoint', help='checkpoint file') parser.add_argument('--out', type=str, default='tmp.onnx') parser.add_argument('--opset-version', type=int, default=11) args = parser.parse_args() return args

if name == 'main': args = parse_args()

Following strings of text style are from colorama package

model = init_model(args.config, args.checkpoint, device='cpu')

model = _convert_batchnorm(model)
onnx_model = pytorch2onnx(
    model,
    opset_version=args.opset_version,
    out=args.out)

onnx.helper.printable_graph(onnx_model.graph)
print('saving model in {}'.format(args.out))
onnx.save(onnx_model, args.out)

Environment

06/28 16:44:42 - mmengine - INFO - 

06/28 16:44:42 - mmengine - INFO - **********Environmental information**********
06/28 16:44:43 - mmengine - INFO - sys.platform: linux
06/28 16:44:43 - mmengine - INFO - Python: 3.8.13 (default, Mar 28 2022, 11:38:47) [GCC 7.5.0]
06/28 16:44:43 - mmengine - INFO - CUDA available: True
06/28 16:44:43 - mmengine - INFO - numpy_random_seed: 2147483648
06/28 16:44:43 - mmengine - INFO - GPU 0,1: NVIDIA GeForce RTX 3090
06/28 16:44:43 - mmengine - INFO - CUDA_HOME: /usr/local/cuda-11.4
06/28 16:44:43 - mmengine - INFO - NVCC: Cuda compilation tools, release 11.4, V11.4.100
06/28 16:44:43 - mmengine - INFO - GCC: gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
06/28 16:44:43 - mmengine - INFO - PyTorch: 1.10.0+cu111
06/28 16:44:43 - mmengine - INFO - PyTorch compiling details: PyTorch built with:
  - GCC 7.3
  - C++ Version: 201402
  - Intel(R) Math Kernel Library Version 2020.0.0 Product Build 20191122 for Intel(R) 64 architecture applications
  - Intel(R) MKL-DNN v2.2.3 (Git Hash 7336ca9f055cf1bfa13efb658fe15dc9b41f0740)
  - OpenMP 201511 (a.k.a. OpenMP 4.5)
  - LAPACK is enabled (usually provided by MKL)
  - NNPACK is enabled
  - CPU capability usage: AVX512
  - CUDA Runtime 11.1
  - NVCC architecture flags: -gencode;arch=compute_37,code=sm_37;-gencode;arch=compute_50,code=sm_50;-gencode;arch=compute_60,code=sm_60;-gencode;arch=compute_70,code=sm_70;-gencode;arch=compute_75,code=sm_75;-gencode;arch=compute_80,code=sm_80;-gencode;arch=compute_86,code=sm_86
  - CuDNN 8.0.5
  - Magma 2.5.2
  - Build settings: BLAS_INFO=mkl, BUILD_TYPE=Release, CUDA_VERSION=11.1, CUDNN_VERSION=8.0.5, CXX_COMPILER=/opt/rh/devtoolset-7/root/usr/bin/c++, CXX_FLAGS= -Wno-deprecated -fvisibility-inlines-hidden -DUSE_PTHREADPOOL -fopenmp -DNDEBUG -DUSE_KINETO -DUSE_FBGEMM -DUSE_QNNPACK -DUSE_PYTORCH_QNNPACK -DUSE_XNNPACK -DSYMBOLICATE_MOBILE_DEBUG_HANDLE -DEDGE_PROFILER_USE_KINETO -O2 -fPIC -Wno-narrowing -Wall -Wextra -Werror=return-type -Wno-missing-field-initializers -Wno-type-limits -Wno-array-bounds -Wno-unknown-pragmas -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wno-unused-function -Wno-unused-result -Wno-unused-local-typedefs -Wno-strict-overflow -Wno-strict-aliasing -Wno-error=deprecated-declarations -Wno-stringop-overflow -Wno-psabi -Wno-error=pedantic -Wno-error=redundant-decls -Wno-error=old-style-cast -fdiagnostics-color=always -faligned-new -Wno-unused-but-set-variable -Wno-maybe-uninitialized -fno-math-errno -fno-trapping-math -Werror=format -Wno-stringop-overflow, LAPACK_INFO=mkl, PERF_WITH_AVX=1, PERF_WITH_AVX2=1, PERF_WITH_AVX512=1, TORCH_VERSION=1.10.0, USE_CUDA=ON, USE_CUDNN=ON, USE_EXCEPTION_PTR=1, USE_GFLAGS=OFF, USE_GLOG=OFF, USE_MKL=ON, USE_MKLDNN=ON, USE_MPI=OFF, USE_NCCL=ON, USE_NNPACK=ON, USE_OPENMP=ON, 

06/28 16:44:43 - mmengine - INFO - TorchVision: 0.11.0+cu111
06/28 16:44:43 - mmengine - INFO - OpenCV: 4.7.0
06/28 16:44:43 - mmengine - INFO - MMEngine: 0.7.1
06/28 16:44:43 - mmengine - INFO - MMCV: 2.0.0rc4
06/28 16:44:43 - mmengine - INFO - MMCV Compiler: GCC 7.3
06/28 16:44:43 - mmengine - INFO - MMCV CUDA Compiler: 11.1
06/28 16:44:43 - mmengine - INFO - MMDeploy: 1.0.0rc3+0196cd0
06/28 16:44:43 - mmengine - INFO - 

06/28 16:44:43 - mmengine - INFO - **********Backend information**********
06/28 16:44:43 - mmengine - INFO - tensorrt:    8.2.3.0
06/28 16:44:43 - mmengine - INFO - tensorrt custom ops: NotAvailable
06/28 16:44:43 - mmengine - INFO - ONNXRuntime: 1.8.0
06/28 16:44:43 - mmengine - INFO - ONNXRuntime-gpu:     None
06/28 16:44:43 - mmengine - INFO - ONNXRuntime custom ops:      NotAvailable
06/28 16:44:43 - mmengine - INFO - pplnn:       None
06/28 16:44:43 - mmengine - INFO - ncnn:        None
06/28 16:44:43 - mmengine - INFO - snpe:        None
06/28 16:44:43 - mmengine - INFO - openvino:    None
06/28 16:44:43 - mmengine - INFO - torchscript: 1.10.0+cu111
06/28 16:44:43 - mmengine - INFO - torchscript custom ops:      NotAvailable
06/28 16:44:43 - mmengine - INFO - rknn-toolkit:        None
06/28 16:44:43 - mmengine - INFO - rknn-toolkit2:       None
06/28 16:44:43 - mmengine - INFO - ascend:      None
06/28 16:44:43 - mmengine - INFO - coreml:      None
06/28 16:44:43 - mmengine - INFO - tvm: None
06/28 16:44:43 - mmengine - INFO - vacc:        None
06/28 16:44:43 - mmengine - INFO - 

06/28 16:44:43 - mmengine - INFO - **********Codebase information**********
06/28 16:44:43 - mmengine - INFO - mmdet:       3.0.0
06/28 16:44:43 - mmengine - INFO - mmseg:       None
06/28 16:44:43 - mmengine - INFO - mmcls:       1.0.0rc5
06/28 16:44:43 - mmengine - INFO - mmocr:       None
06/28 16:44:43 - mmengine - INFO - mmedit:      None
06/28 16:44:43 - mmengine - INFO - mmdet3d:     None
06/28 16:44:43 - mmengine - INFO - mmpose:      1.0.0
06/28 16:44:43 - mmengine - INFO - mmrotate:    None
06/28 16:44:43 - mmengine - INFO - mmaction:    None
06/28 16:44:43 - mmengine - INFO - mmrazor:     None

Error traceback

bash demo.sh
Loads checkpoint by local backend from path: /home/dell/cc_word/home/darkpull/develop/mmpose/work_dirs/pose-cls-person/epoch_300.pth
The model and loaded state dict do not match exactly

size mismatch for head.final_layer.weight: copying a param with shape torch.Size([3, 8, 7, 7]) from checkpoint, the shape in current model is torch.Size([3, 512, 7, 7]).
TopdownPoseEstimator(
  (data_preprocessor): PoseDataPreprocessor()
  (backbone): CSPNeXt(
    (stem): Sequential(
      (0): ConvModule(
        (conv): Conv2d(3, 16, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False)
        (bn): _BatchNormXd(16, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
        (activate): SiLU(inplace=True)
      )
      (1): ConvModule(
        (conv): Conv2d(16, 16, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (bn): _BatchNormXd(16, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
        (activate): SiLU(inplace=True)
      )
      (2): ConvModule(
        (conv): Conv2d(16, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (bn): _BatchNormXd(32, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
        (activate): SiLU(inplace=True)
      )
    )
    (stage1): Sequential(
      (0): ConvModule(
        (conv): Conv2d(32, 64, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False)
        (bn): _BatchNormXd(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
        (activate): SiLU(inplace=True)
      )
      (1): CSPLayer(
        (main_conv): ConvModule(
          (conv): Conv2d(64, 32, kernel_size=(1, 1), stride=(1, 1), bias=False)
          (bn): _BatchNormXd(32, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
          (activate): SiLU(inplace=True)
        )
        (short_conv): ConvModule(
          (conv): Conv2d(64, 32, kernel_size=(1, 1), stride=(1, 1), bias=False)
          (bn): _BatchNormXd(32, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
          (activate): SiLU(inplace=True)
        )
        (final_conv): ConvModule(
          (conv): Conv2d(64, 64, kernel_size=(1, 1), stride=(1, 1), bias=False)
          (bn): _BatchNormXd(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
          (activate): SiLU(inplace=True)
        )
        (blocks): Sequential(
          (0): CSPNeXtBlock(
            (conv1): ConvModule(
              (conv): Conv2d(32, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
              (bn): _BatchNormXd(32, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
              (activate): SiLU(inplace=True)
            )
            (conv2): DepthwiseSeparableConvModule(
              (depthwise_conv): ConvModule(
                (conv): Conv2d(32, 32, kernel_size=(5, 5), stride=(1, 1), padding=(2, 2), groups=32, bias=False)
                (bn): _BatchNormXd(32, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                (activate): SiLU(inplace=True)
              )
              (pointwise_conv): ConvModule(
                (conv): Conv2d(32, 32, kernel_size=(1, 1), stride=(1, 1), bias=False)
                (bn): _BatchNormXd(32, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                (activate): SiLU(inplace=True)
              )
            )
          )
        )
        (attention): ChannelAttention(
          (global_avgpool): AdaptiveAvgPool2d(output_size=1)
          (fc): Conv2d(64, 64, kernel_size=(1, 1), stride=(1, 1))
          (act): Hardsigmoid()
        )
      )
    )
    (stage2): Sequential(
      (0): ConvModule(
        (conv): Conv2d(64, 128, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False)
        (bn): _BatchNormXd(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
        (activate): SiLU(inplace=True)
      )
      (1): CSPLayer(
        (main_conv): ConvModule(
          (conv): Conv2d(128, 64, kernel_size=(1, 1), stride=(1, 1), bias=False)
          (bn): _BatchNormXd(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
          (activate): SiLU(inplace=True)
        )
        (short_conv): ConvModule(
          (conv): Conv2d(128, 64, kernel_size=(1, 1), stride=(1, 1), bias=False)
          (bn): _BatchNormXd(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
          (activate): SiLU(inplace=True)
        )
        (final_conv): ConvModule(
          (conv): Conv2d(128, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)
          (bn): _BatchNormXd(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
          (activate): SiLU(inplace=True)
        )
        (blocks): Sequential(
          (0): CSPNeXtBlock(
            (conv1): ConvModule(
              (conv): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
              (bn): _BatchNormXd(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
              (activate): SiLU(inplace=True)
            )
            (conv2): DepthwiseSeparableConvModule(
              (depthwise_conv): ConvModule(
                (conv): Conv2d(64, 64, kernel_size=(5, 5), stride=(1, 1), padding=(2, 2), groups=64, bias=False)
                (bn): _BatchNormXd(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                (activate): SiLU(inplace=True)
              )
              (pointwise_conv): ConvModule(
                (conv): Conv2d(64, 64, kernel_size=(1, 1), stride=(1, 1), bias=False)
                (bn): _BatchNormXd(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                (activate): SiLU(inplace=True)
              )
            )
          )
          (1): CSPNeXtBlock(
            (conv1): ConvModule(
              (conv): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
              (bn): _BatchNormXd(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
              (activate): SiLU(inplace=True)
            )
            (conv2): DepthwiseSeparableConvModule(
              (depthwise_conv): ConvModule(
                (conv): Conv2d(64, 64, kernel_size=(5, 5), stride=(1, 1), padding=(2, 2), groups=64, bias=False)
                (bn): _BatchNormXd(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                (activate): SiLU(inplace=True)
              )
              (pointwise_conv): ConvModule(
                (conv): Conv2d(64, 64, kernel_size=(1, 1), stride=(1, 1), bias=False)
                (bn): _BatchNormXd(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                (activate): SiLU(inplace=True)
              )
            )
          )
        )
        (attention): ChannelAttention(
          (global_avgpool): AdaptiveAvgPool2d(output_size=1)
          (fc): Conv2d(128, 128, kernel_size=(1, 1), stride=(1, 1))
          (act): Hardsigmoid()
        )
      )
    )
    (stage3): Sequential(
      (0): ConvModule(
        (conv): Conv2d(128, 256, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False)
        (bn): _BatchNormXd(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
        (activate): SiLU(inplace=True)
      )
      (1): CSPLayer(
        (main_conv): ConvModule(
          (conv): Conv2d(256, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)
          (bn): _BatchNormXd(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
          (activate): SiLU(inplace=True)
        )
        (short_conv): ConvModule(
          (conv): Conv2d(256, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)
          (bn): _BatchNormXd(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
          (activate): SiLU(inplace=True)
        )
        (final_conv): ConvModule(
          (conv): Conv2d(256, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)
          (bn): _BatchNormXd(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
          (activate): SiLU(inplace=True)
        )
        (blocks): Sequential(
          (0): CSPNeXtBlock(
            (conv1): ConvModule(
              (conv): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
              (bn): _BatchNormXd(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
              (activate): SiLU(inplace=True)
            )
            (conv2): DepthwiseSeparableConvModule(
              (depthwise_conv): ConvModule(
                (conv): Conv2d(128, 128, kernel_size=(5, 5), stride=(1, 1), padding=(2, 2), groups=128, bias=False)
                (bn): _BatchNormXd(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                (activate): SiLU(inplace=True)
              )
              (pointwise_conv): ConvModule(
                (conv): Conv2d(128, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)
                (bn): _BatchNormXd(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                (activate): SiLU(inplace=True)
              )
            )
          )
          (1): CSPNeXtBlock(
            (conv1): ConvModule(
              (conv): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
              (bn): _BatchNormXd(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
              (activate): SiLU(inplace=True)
            )
            (conv2): DepthwiseSeparableConvModule(
              (depthwise_conv): ConvModule(
                (conv): Conv2d(128, 128, kernel_size=(5, 5), stride=(1, 1), padding=(2, 2), groups=128, bias=False)
                (bn): _BatchNormXd(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                (activate): SiLU(inplace=True)
              )
              (pointwise_conv): ConvModule(
                (conv): Conv2d(128, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)
                (bn): _BatchNormXd(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                (activate): SiLU(inplace=True)
              )
            )
          )
        )
        (attention): ChannelAttention(
          (global_avgpool): AdaptiveAvgPool2d(output_size=1)
          (fc): Conv2d(256, 256, kernel_size=(1, 1), stride=(1, 1))
          (act): Hardsigmoid()
        )
      )
    )
    (stage4): Sequential(
      (0): ConvModule(
        (conv): Conv2d(256, 512, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False)
        (bn): _BatchNormXd(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
        (activate): SiLU(inplace=True)
      )
      (1): SPPBottleneck(
        (conv1): ConvModule(
          (conv): Conv2d(512, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)
          (bn): _BatchNormXd(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
          (activate): SiLU(inplace=True)
        )
        (poolings): ModuleList(
          (0): MaxPool2d(kernel_size=5, stride=1, padding=2, dilation=1, ceil_mode=False)
          (1): MaxPool2d(kernel_size=9, stride=1, padding=4, dilation=1, ceil_mode=False)
          (2): MaxPool2d(kernel_size=13, stride=1, padding=6, dilation=1, ceil_mode=False)
        )
        (conv2): ConvModule(
          (conv): Conv2d(1024, 512, kernel_size=(1, 1), stride=(1, 1), bias=False)
          (bn): _BatchNormXd(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
          (activate): SiLU(inplace=True)
        )
      )
      (2): CSPLayer(
        (main_conv): ConvModule(
          (conv): Conv2d(512, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)
          (bn): _BatchNormXd(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
          (activate): SiLU(inplace=True)
        )
        (short_conv): ConvModule(
          (conv): Conv2d(512, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)
          (bn): _BatchNormXd(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
          (activate): SiLU(inplace=True)
        )
        (final_conv): ConvModule(
          (conv): Conv2d(512, 512, kernel_size=(1, 1), stride=(1, 1), bias=False)
          (bn): _BatchNormXd(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
          (activate): SiLU(inplace=True)
        )
        (blocks): Sequential(
          (0): CSPNeXtBlock(
            (conv1): ConvModule(
              (conv): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
              (bn): _BatchNormXd(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
              (activate): SiLU(inplace=True)
            )
            (conv2): DepthwiseSeparableConvModule(
              (depthwise_conv): ConvModule(
                (conv): Conv2d(256, 256, kernel_size=(5, 5), stride=(1, 1), padding=(2, 2), groups=256, bias=False)
                (bn): _BatchNormXd(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                (activate): SiLU(inplace=True)
              )
              (pointwise_conv): ConvModule(
                (conv): Conv2d(256, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)
                (bn): _BatchNormXd(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                (activate): SiLU(inplace=True)
              )
            )
          )
        )
        (attention): ChannelAttention(
          (global_avgpool): AdaptiveAvgPool2d(output_size=1)
          (fc): Conv2d(512, 512, kernel_size=(1, 1), stride=(1, 1))
          (act): Hardsigmoid()
        )
      )
    )
  )
  (head): RTMCC_KPC_Head(
    (loss_module): CrossEntropyLoss()
    (final_layer): Conv2d(512, 3, kernel_size=(7, 7), stride=(1, 1), padding=(3, 3))
    (fc_model): Sequential(
      (0): Linear(in_features=32768, out_features=128, bias=True)
      (1): ReLU()
      (2): Dropout(p=0.5, inplace=False)
      (3): Linear(in_features=128, out_features=3, bias=True)
    )
  )
  init_cfg=[{'type': 'Normal', 'layer': ['Conv2d'], 'std': 0.001}, {'type': 'Constant', 'layer': 'BatchNorm2d', 'val': 1}, {'type': 'Normal', 'layer': ['Linear'], 'std': 0.01, 'bias': 0}]
)
/home/dell/anaconda3/envs/mzero/lib/python3.8/site-packages/torch/onnx/utils.py:97: UserWarning: `strip_doc_string' is deprecated and ignored. Will be removed in next PyTorch release. It's combined with `verbose' argument now. 
  warnings.warn("`strip_doc_string' is deprecated and ignored. Will be removed in "
Traceback (most recent call last):
  File "tools/torchserve/torch2onnx.py", line 89, in <module>
    onnx_model = pytorch2onnx(
  File "tools/torchserve/torch2onnx.py", line 56, in pytorch2onnx
    torch.onnx.export(
  File "/home/dell/anaconda3/envs/mzero/lib/python3.8/site-packages/torch/onnx/__init__.py", line 316, in export
    return utils.export(model, args, f, export_params, verbose, training,
  File "/home/dell/anaconda3/envs/mzero/lib/python3.8/site-packages/torch/onnx/utils.py", line 107, in export
    _export(model, args, f, export_params, verbose, training, input_names, output_names,
  File "/home/dell/anaconda3/envs/mzero/lib/python3.8/site-packages/torch/onnx/utils.py", line 724, in _export
    _model_to_graph(model, args, verbose, input_names,
  File "/home/dell/anaconda3/envs/mzero/lib/python3.8/site-packages/torch/onnx/utils.py", line 493, in _model_to_graph
    graph, params, torch_out, module = _create_jit_graph(model, args)
  File "/home/dell/anaconda3/envs/mzero/lib/python3.8/site-packages/torch/onnx/utils.py", line 437, in _create_jit_graph
    graph, torch_out = _trace_and_get_graph_from_model(model, args)
  File "/home/dell/anaconda3/envs/mzero/lib/python3.8/site-packages/torch/onnx/utils.py", line 388, in _trace_and_get_graph_from_model
    torch.jit._get_trace_graph(model, args, strict=False, _force_outplace=False, _return_inputs_states=True)
  File "/home/dell/anaconda3/envs/mzero/lib/python3.8/site-packages/torch/jit/_trace.py", line 1166, in _get_trace_graph
    outs = ONNXTracedModule(f, strict, _force_outplace, return_inputs, _return_inputs_states)(*args, **kwargs)
  File "/home/dell/anaconda3/envs/mzero/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1102, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/dell/anaconda3/envs/mzero/lib/python3.8/site-packages/torch/jit/_trace.py", line 127, in forward
    graph, out = torch._C._create_graph_by_tracing(
  File "/home/dell/anaconda3/envs/mzero/lib/python3.8/site-packages/torch/jit/_trace.py", line 118, in wrapper
    outs.append(self.inner(*trace_inputs))
  File "/home/dell/anaconda3/envs/mzero/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1102, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/dell/anaconda3/envs/mzero/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1090, in _slow_forward
    result = self.forward(*input, **kwargs)
TypeError: forward() missing 1 required positional argument: 'data_samples'
RunningLeon commented 1 year ago

@chen-del hi, pls install mmdeploy and then do model conversion

  1. https://mmdeploy.readthedocs.io/en/latest/get_started.html
  2. https://mmdeploy.readthedocs.io/en/latest/02-how-to-run/convert_model.html
chen-del commented 1 year ago

@RunningLeon ,I have installed mmdeploy, but the configuration inside is not usable. I have added classification branch training to mmpose and removed the test_cfg configuration parameter. None of the methods is applicable now. It has this error I have tried earlier -detection_onnxruntime_static, it has the following error e3a3b12842ee25369f11f8bdd7a3ff3

RunningLeon commented 1 year ago
  1. your model config has no test_cfg, could update your model config.
  2. you may need to add rewriting functions for model conversion and inference.
chen-del commented 1 year ago

Do you mean that I need to re-build inference mode and onnx derivation mode suitable for my model on mmdeply according to my model? Is there any quick way to do that?

github-actions[bot] commented 1 year ago

This issue is marked as stale because it has been marked as invalid or awaiting response for 7 days without any further response. It will be closed in 5 days if the stale label is not removed or if there is no further response.

github-actions[bot] commented 1 year ago

This issue is closed because it has been stale for 5 days. Please open a new issue if you have similar issues or you have any new updates now.