fabio-sim / DocShadow-ONNX-TensorRT

ONNX-compatible DocShadow: High-Resolution Document Shadow Removal. Supports TensorRT 🚀
MIT License
18 stars 2 forks source link

CoreML conversion #1

Open heorhiikalaichev opened 1 year ago

heorhiikalaichev commented 1 year ago

Hi!

Thank you for your job! Were you trying to convert this model to coreml? I faced some issues while handling this.

fabio-sim commented 1 year ago

Hi @heorhiikalaichev , thank you for your interest in DocShadow-ONNX-TensorRT.

I believe you were referred here from https://github.com/CXH-Research/DocShadow-SD7K/issues/6, but CoreML conversion does not need ONNX anymore. It is now recommended to convert directly from PyTorch via JIT tracing. Although I'm by no means an expert in CoreML, I think these are the issues you faced when naively tracing and converting the current DocShadow implementation to CoreML, in order:

  1. PyTorch convert function for op 'var' not implemented. (https://github.com/apple/coremltools/issues/1203)
  2. PyTorch convert function for op 'pythonop' not implemented. (https://github.com/apple/coremltools/issues/1135)
  3. PyTorch convert function for op 'upsample_bicubic2d' not implemented.

I provided a simple export script which patches these issues and converts successfully: https://github.com/fabio-sim/DocShadow-ONNX-TensorRT/blob/ec926bf36b4ac0778f836a2d34e27021447df27c/export_coreml.py#L1-L59

Please do confirm whether the exported models run correctly on CoreML.

heorhiikalaichev commented 1 year ago

Thank you so much for your answer. I just made the same changes as you and was able to convert this model.

I will test results and inform you in case they are different from pytorch model results.