{"id":24446254,"url":"https://github.com/fabio-sim/docshadow-onnx-tensorrt","last_synced_at":"2025-05-07T17:07:32.167Z","repository":{"id":191901175,"uuid":"685637573","full_name":"fabio-sim/DocShadow-ONNX-TensorRT","owner":"fabio-sim","description":"ONNX-compatible DocShadow: High-Resolution Document Shadow Removal. Supports TensorRT 🚀","archived":false,"fork":false,"pushed_at":"2023-09-13T14:05:26.000Z","size":147,"stargazers_count":20,"open_issues_count":2,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-20T23:52:33.022Z","etag":null,"topics":["coreml","deep-learning","docshadow","document-shadow-removal","machine-learning","onnx","onnxruntime","pytorch","shadow-removal","tensorrt"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fabio-sim.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-08-31T17:08:11.000Z","updated_at":"2024-12-27T08:59:50.000Z","dependencies_parsed_at":null,"dependency_job_id":"eceb35f0-a34b-4adf-8d49-10d5915a33d3","html_url":"https://github.com/fabio-sim/DocShadow-ONNX-TensorRT","commit_stats":null,"previous_names":["fabio-sim/docshadow-onnx-tensorrt"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabio-sim%2FDocShadow-ONNX-TensorRT","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabio-sim%2FDocShadow-ONNX-TensorRT/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabio-sim%2FDocShadow-ONNX-TensorRT/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabio-sim%2FDocShadow-ONNX-TensorRT/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fabio-sim","download_url":"https://codeload.github.com/fabio-sim/DocShadow-ONNX-TensorRT/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235527751,"owners_count":19004372,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["coreml","deep-learning","docshadow","document-shadow-removal","machine-learning","onnx","onnxruntime","pytorch","shadow-removal","tensorrt"],"created_at":"2025-01-20T23:50:16.219Z","updated_at":"2025-01-25T02:07:48.617Z","avatar_url":"https://github.com/fabio-sim.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![GitHub](https://img.shields.io/github/license/fabio-sim/DocShadow-ONNX-TensorRT)](/LICENSE)\n[![ONNX](https://img.shields.io/badge/ONNX-grey)](https://onnx.ai/)\n[![TensorRT](https://img.shields.io/badge/TensorRT-76B900)](https://developer.nvidia.com/tensorrt)\n[![GitHub Repo stars](https://img.shields.io/github/stars/fabio-sim/DocShadow-ONNX-TensorRT)](https://github.com/fabio-sim/DocShadow-ONNX-TensorRT/stargazers)\n[![GitHub all releases](https://img.shields.io/github/downloads/fabio-sim/DocShadow-ONNX-TensorRT/total)](https://github.com/fabio-sim/DocShadow-ONNX-TensorRT/releases)\n\n# DocShadow-ONNX-TensorRT\nOpen Neural Network Exchange (ONNX) compatible implementation of [DocShadow: High-Resolution Document Shadow Removal via A Large-scale Real-world Dataset and A Frequency-aware Shadow Erasing Net](https://github.com/CXH-Research/DocShadow-SD7K). Supports TensorRT 🚀.\n\n\u003cp align=\"center\"\u003e\u003cimg src=\"assets/latency.png\" alt=\"Latency figure\" width=80%\u003e\u003cbr\u003e\u003cem\u003eDocShadow ONNX TensorRT provides up to a 2x speedup over PyTorch.\u003c/em\u003e\u003c/p\u003e\n\n## 🔥 ONNX Export\n\nPrior to exporting the ONNX models, please install the [requirements](/requirements.txt).\n\nTo convert the DocShadow models to ONNX, run [`export.py`](/export.py).\n\n\u003cdetails\u003e\n\u003csummary\u003eExport Example\u003c/summary\u003e\n\u003cpre\u003e\npython export.py \\\n    --weights sd7k \\\n    --dynamic_img_size --dynamic_batch\n\u003c/pre\u003e\n\u003c/details\u003e\n\nIf you would like to try out inference right away, you can download ONNX models that have already been exported [here](https://github.com/fabio-sim/DocShadow-ONNX-TensorRT/releases) or run `./weights/download.sh`.\n\n## ⚡ ONNX Inference\n\nWith ONNX models in hand, one can perform inference on Python using ONNX Runtime (see [requirements-onnx.txt](/requirements-onnx.txt)).\n\nThe DocShadow inference pipeline has been encapsulated into a runner class:\n\n```python\nfrom onnx_runner import DocShadowRunner\n\nimages = DocShadowRunner.preprocess(image_array)\n# images.shape == (B, 3, H, W)\n\n# Create ONNXRuntime runner\nrunner = DocShadowRunner(\n    onnx_path=\"weights/docshadow_sd7k.onnx\",\n    providers=[\"CUDAExecutionProvider\", \"CPUExecutionProvider\"],\n    # TensorrtExecutionProvider\n)\n\n# Run inference\nresult = runner.run(images)\n```\nAlternatively, you can also run [`infer.py`](/infer.py).\n\n\u003cdetails\u003e\n\u003csummary\u003eInference Example\u003c/summary\u003e\n\u003cpre\u003e\npython infer.py \\\n    --img_path assets/sample.jpg \\\n    --img_size 256 256 \\\n    --onnx_path weights/docshadow_sd7k.onnx \\\n    --viz\n\u003c/pre\u003e\n\u003c/details\u003e\n\n## 🚀 TensorRT Support\n\nTensorRT offers the best performance and greatest memory efficiency.\n\nTensorRT inference is supported for the DocShadow model via the TensorRT Execution Provider in ONNXRuntime. Please follow the [official documentation](https://docs.nvidia.com/deeplearning/tensorrt/install-guide/index.html) to install TensorRT.\n\n\u003cdetails\u003e\n\u003csummary\u003eTensorRT Example\u003c/summary\u003e\n\u003cpre\u003e\nCUDA_MODULE_LOADING=LAZY \u0026\u0026 python infer.py \\\n  --img_path assets/sample.jpg \\\n  --onnx_path weights/docshadow_sd7k.onnx \\\n  --img_size 256 256 \\\n  --trt \\\n  --viz\n\u003c/pre\u003e\n\u003c/details\u003e\n\nThe first run will take longer because TensorRT needs to initialise the `.engine` and `.profile` files. Subsequent runs should use the cached files. Only static input shapes are supported. Note that TensorRT will rebuild the cache if it encounters a different input shape.\n\n## Credits\nIf you use any ideas from the papers or code in this repo, please consider citing the authors of [DocShadow](https://arxiv.org/abs/2308.14221). Lastly, if the ONNX or TensorRT versions helped you in any way, please also consider starring this repository.\n\n```bibtex\n@article{docshadow_sd7k,\n  title={High-Resolution Document Shadow Removal via A Large-Scale Real-World Dataset and A Frequency-Aware Shadow Erasing Net},\n  author={Li, Zinuo and Chen, Xuhang and Pun, Chi-Man and Cun, Xiaodong},\n  journal={arXiv preprint arXiv:2308.14221},\n  year={2023}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffabio-sim%2Fdocshadow-onnx-tensorrt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffabio-sim%2Fdocshadow-onnx-tensorrt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffabio-sim%2Fdocshadow-onnx-tensorrt/lists"}