InternImage icon indicating copy to clipboard operation
InternImage copied to clipboard

export.py for segmentation model

Open calebhemara opened this issue 1 year ago • 10 comments

Hello! I'm attempting to build an onnx for segmentation inference, and I noticed there's a export.py for the classification folder, but not for segmentation folder...

Is this a possibility in the future? Or, a release of onnx direct?

Thank you!

calebhemara avatar Mar 22 '23 03:03 calebhemara

Hello, we are preparing the onnx for segmentation inference, could you please wait for some days?

czczup avatar Mar 24 '23 07:03 czczup

Sounds great! Thanks

calebhemara avatar Mar 25 '23 11:03 calebhemara

Thank you for your issue.

We have now uploaded the script for segmentation, you can refer to here.

Weiyun1025 avatar Mar 27 '23 08:03 Weiyun1025

Hi! I am very excited for this. Currently, I am having error on export. File "/Users/caleb/dev/Deepwork/deepworkenv/lib/python3.10/site-packages/mmseg/apis/inference.py", line 36, in init_segmentor model.CLASSES = checkpoint['meta']['CLASSES'] KeyError: 'meta'

I have tried with both XL and H checkpoints, and their respective configs. Adjusting for 'core_op='DCNv3_pytorch' as I'm on M1 Max.

Any idea? Thanks

calebhemara avatar Mar 28 '23 00:03 calebhemara

Hi! I am very excited for this. Currently, I am having error on export. File "/Users/caleb/dev/Deepwork/deepworkenv/lib/python3.10/site-packages/mmseg/apis/inference.py", line 36, in init_segmentor model.CLASSES = checkpoint['meta']['CLASSES'] KeyError: 'meta'

I have tried with both XL and H checkpoints, and their respective configs. Adjusting for 'core_op='DCNv3_pytorch' as I'm on M1 Max.

Any idea? Thanks

Missing CLASSES information in our released checkpoints seems to be the source of this issue. We will update them as soon as possible to fix this issue. Thank you for your issue!

You can currently run the following code to fix this issue:

import torch
from mmseg.core import get_classes

ckpt_path = '/path/to/ckpt.pth'
ckpt = torch.load(ckpt_path, map_location='cpu')
ckpt['meta'] = {}
ckpt['meta']['CLASSES'] = get_classes('ade20k')

torch.save(ckpt, ckpt_path)

Weiyun1025 avatar Mar 28 '23 03:03 Weiyun1025

Thanks for that. I ended up editing that to add a "PALETTE" value too, and the onnx file exported. But now I am having the following error: onnxruntime.capi.onnxruntime_pybind11_state.Fail: [ONNXRuntimeError] : 1 : FAIL : Load model from /Users/caleb/dev/Deepwork/InternImage-main/segmentation/end2end.onnx failed:Fatal error: mmdeploy:grid_sampler(-1) is not a registered function/op

Suggesting that mmdeploy method isn't within onnx runtime framework. Any solution here?

calebhemara avatar Mar 28 '23 10:03 calebhemara

Thanks for that. I ended up editing that to add a "PALETTE" value too, and the onnx file exported. But now I am having the following error: onnxruntime.capi.onnxruntime_pybind11_state.Fail: [ONNXRuntimeError] : 1 : FAIL : Load model from /Users/caleb/dev/Deepwork/InternImage-main/segmentation/end2end.onnx failed:Fatal error: mmdeploy:grid_sampler(-1) is not a registered function/op

Suggesting that mmdeploy method isn't within onnx runtime framework. Any solution here?

This error is casued by the absense of the corresponding custom operator in onnxruntime. However, we have not implemented this custom operator for onnxruntime engine yet.

If you still want to inference with onnxruntime as your engine, you can try to replace the core_op='DCNv3' with core_op='DCNv3_pytorch' so that you can avoid the issue of custom operator. You can refer to issue #41 for more details about how to replace this operator.

Weiyun1025 avatar Mar 28 '23 11:03 Weiyun1025

Thanks! I had already done this though. Any other suggestions?

calebhemara avatar Mar 28 '23 22:03 calebhemara

i have this error" Traceback (most recent call last): File "/content/InternImage/segmentation/deploy.py", line 12, in from mmdeploy.apis import (create_calib_input_data, extract_model, ModuleNotFoundError: No module named 'mmdeploy'"

ranamohamed12 avatar May 01 '23 19:05 ranamohamed12

@calebhemara hello,do you achieve the segmentation model convert. I meet some problem

GitHubYuxiao avatar Jan 24 '24 03:01 GitHubYuxiao