Skip to content

Instantly share code, notes, and snippets.

@pbamotra
Created April 25, 2021 01:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pbamotra/d48b2940d84a214475dff9be6b5dab8c to your computer and use it in GitHub Desktop.
Save pbamotra/d48b2940d84a214475dff9be6b5dab8c to your computer and use it in GitHub Desktop.
Cascade Tabnet to Onnx
!pip install cython==0.28.5
!pip install mmdet==2.10.0 requests
!pip install torch==1.7.0+cu110 torchvision==0.8.1+cu110 -f https://download.pytorch.org/whl/torch_stable.html
!pip install mmcv-full==1.2.7+torch1.7.0+cu110 -f https://openmmlab.oss-accelerate.aliyuncs.com/mmcv/dist/index.html
!pip install onnx onnxruntime onnxruntime-gpu onnxoptimizer
!git clone --branch v2.10.0 https://github.com/open-mmlab/mmdetection.git
# Download conf and weights from
# https://github.com/iiLaurens/CascadeTabNet/blob/mmdet2x/Demo/Cascade_Tabnet_mmdet_v2_cpu_only_demo.ipynb
!cd mmdetection && python tools/deployment/pytorch2onnx.py \
cascade_mask_rcnn_hrnetv2p_w32_20e.py\
General.Model.table.detection.v2.pth \
--output-file General.Model.table.detection.v2.onnx \
--input-img demo.png \
--shape 800 800 \
--simplify
# Changes you must do to pytorch2onnx.py
# General.Model.table.detection.v2.pth is for general table detection, it does
# not produces masks
# Delete the following lines
# if model.with_mask:
# output_names.append('masks')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment