This ONNX version of MODNet is provided by @manthan3C273 from the community.
Please note that the PyTorch version required for this ONNX export function is higher than the official MODNet code (torch==1.7.1 is recommended).
You can try MODNet - Image Matting Demo (ONNX version) in this Colab.
You can also download the ONNX version of the official Image Matting Model from this link.
To export the ONNX version of MODNet (assuming you are currently in project root directory):
-
Download the pre-trained Image Matting Model from this link and put the model into the folder
MODNet/pretrained/
. -
Install all dependencies by:
pip install -r onnx/requirements.txt
-
Export the ONNX version of MODNet by:
python -m onnx.export_onnx \ --ckpt-path=pretrained/modnet_photographic_portrait_matting.ckpt \ --output-path=pretrained/modnet_photographic_portrait_matting.onnx
-
Inference the ONNX model by:
python -m onnx.inference_onnx \ --image-path=$FILENAME_OF_INPUT_IMAGE$ \ --output-path=$FILENAME_OF_OUTPUT_MATTE$ \ --model-path=pretrained/modnet_photographic_portrait_matting.onnx