Open4
mmdetection + UniverseNet
$ git clone https://github.com/open-mmlab/mmcv.git && cd mmcv
$ MMCV_WITH_OPS=1 pip3 install -e .
$ sudo pip3 install mmdet
ONNXのエクスポーターの動作確認
$ git clone https://github.com/shinya7y/UniverseNet.git && UniverseNet
$ python3 tools/pytorch2onnx.py -h
usage: pytorch2onnx.py
[-h]
[--input-img INPUT_IMG]
[--show]
[--output-file OUTPUT_FILE]
[--opset-version OPSET_VERSION]
[--verify]
[--shape SHAPE [SHAPE ...]]
[--mean MEAN [MEAN ...]]
[--std STD [STD ...]]
config checkpoint
Convert MMDetection models to ONNX
positional arguments:
config test config file path
checkpoint checkpoint file
optional arguments:
-h, --help show this help message and exit
--input-img INPUT_IMG
Images for input
--show show onnx graph
--output-file OUTPUT_FILE
--opset-version OPSET_VERSION
--verify verify the onnx model output against pytorch output
--shape SHAPE [SHAPE ...]
input image size
--mean MEAN [MEAN ...]
mean value used for preprocess input data
--std STD [STD ...] variance value used for preprocess input data
$ wget https://github.com/shinya7y/UniverseNet/releases/download/20.12/universenet50_2008s_fp16_4x16_micro_mstrain_128_256_2x_coco_20201111_epoch_24-2655e5d3.pth && \
wget https://github.com/shinya7y/UniverseNet/releases/download/20.12/universenet50_2008s_fp16_4x16_mini_mstrain_320_640_2x_coco_20201110_epoch_24-d2655d05.pth
$ sed -i "s/mmcv_maximum_version = '1.2'/mmcv_maximum_version = '9.0.0'/g" mmdet/__init__.py
$ sed -i "s/one_img = torch.from_numpy(one_img).unsqueeze(0).float()/one_img = torch.from_numpy(one_img).unsqueeze(0).float().cpu()/g" tools/pytorch2onnx.py
$ python3 tools/pytorch2onnx.py \
--shape 224 224 \
--input-img demo/demo.jpg \
--output-file universenet50_2008s_224x224_float32.onnx \
configs/universenet/universenet50_2008s_fp16_4x16_micro_mstrain_128_256_2x_coco.py \
universenet50_2008s_fp16_4x16_micro_mstrain_128_256_2x_coco_20201111_epoch_24-2655e5d3.pth