# inpaint4shadow **Repository Path**: wan-guorui/inpaint4shadow ## Basic Information - **Project Name**: inpaint4shadow - **Description**: 一个专注于图像修复的开源项目,使用深度学习技术填补图片中的阴影区域,提升图像质量和视觉效果。 - **Primary Language**: Python - **License**: MulanPSL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2026-03-28 - **Last Updated**: 2026-03-28 ## Categories & Tags **Categories**: Uncategorized **Tags**: Python, PyTorch ## README # Leveraging Inpainting for Single-Image Shadow Removal, Accepted by ICCV2023 In this work, we find that pretraining shadow removal networks on the image inpainting dataset can reduce the shadow remnants significantly: a naive encoder-decoder network gets competitive restoration quality w.r.t. the state-of-the-art methods via only 10% shadow & shadow-free image pairs. After analyzing networks with/without inpainting pretraining via the information stored in the weight (IIW), we find that inpainting pretraining improves restoration quality in non-shadow regions and enhances the generalization ability of networks significantly. Additionally, shadow removal fine-tuning enables networks to fill in the details of shadow regions. Inspired by these observations we formulate shadow removal as an adaptive fusion task that takes advantage of both shadow removal and image inpainting. The extensive experiments show that our method empowered with inpainting outperforms all state-of-the-art methods.[[ArXiv]](https://arxiv.org/abs/2302.05361)


Try our method in Google Colab

![Framework](./images/framework.png) ## Prerequisites - Python 3 - PyTorch >= 1.0 ``` conda create -n inpaint4shadow python=3.7 conda activate inpaint4shadow conda install pytorch==1.7.0 torchvision==0.8.0 torchaudio==0.7.0 cudatoolkit=10.1 -c pytorch pip install -r requirements.txt ``` ## Dataset - [ISTD+](https://github.com/cvlab-stonybrook/SID) - SRD[(please email the author)](https://people.ucas.edu.cn/~tianjd) - For data folder path (ISTD+) organize them as following: ```shell --ISTD+ --train --train_A (shadow images) --1.png --2.png --3.png --train_B (ground truth shadow masks) --1.png --2.png --3.png --train_C (ground truth) --1.png --2.png --3.png --test --test_A (shadow images) --1.png --2.png --3.png --test_B (ground truth shadow masks) --1.png --2.png --3.png --test_B_detected (detected shadow masks) --1.png --2.png --3.png --test_C (ground truth) --1.png --2.png --3.png ``` - Generate the image list ``` python ./data/data_list.py ``` ## Pretrained models - [ISTD+](https://drive.google.com/drive/folders/1WjEwrSjeF7rBiaVuPQakc3uHGdFyGc5e?usp=sharing) - [SRD](https://drive.google.com/drive/folders/1WjEwrSjeF7rBiaVuPQakc3uHGdFyGc5e?usp=sharing) ## De-shadowed results - [ISTD+](https://drive.google.com/drive/folders/1gna_0-ECys93k77bUFCo_9npJ8Av8iqm?usp=sharing) - [SRD](https://drive.google.com/drive/folders/1gna_0-ECys93k77bUFCo_9npJ8Av8iqm?usp=sharing) ## Training - #### Inpainting pretraining Setup parameters: ./Inpainting_pretraining/checkpoints/config.yml ``` python ./Inpainting_pretraining/train.py ``` - #### Shadow removal fine-tuning Setup parameters: ./shadow_removal/checkpoints/config.yml ``` python ./shadow_removal/train.py ``` ## Testing - #### Shadow removal on ISTD+ dataset 1. Downloaded the "ISTD+.pth" and put that under ./shadow_removal/checkpoints. 2. Update "MODEL_LOAD: ISTD+.pth" in ./shadow_removal/checkpoints/config.yml. 3. Update the test dataset path in ./shadow_removal/checkpoints/config.yml. ``` python ./shadow_removal/test.py ``` - #### Evaluation 1. The RMSE results reported in the paper are calculated by the matlab script. Our evaluation code will print the metrics calculated by python code and save the de-shadowed results which will be used by the matlab script. 2. PSNR, SSIM, and LPIPS ``` python ./shadow_removal/Evaluation.py ``` ## Results - Comparsion with SOTA methods ![Framework](./images/comparison.png) - L1 difference on ISTD+ dataset ![Framework](./images/L1_diff_ISTD+.png) - L1 difference on SRD dataset ![Framework](./images/L1_diff_SRD.png) ## Bibtex ``` @article{li2023leveraging, title={Leveraging Inpainting for Single-Image Shadow Removal}, author={Li, Xiaoguang and Guo, Qing and Abdelfattah, Rabab and Lin, Di and Feng, Wei and Tsang, Ivor and Wang, Song}, journal={arXiv preprint arXiv:2302.05361}, year={2023} } ``` [//]: # (## Acknowledgments) [//]: # (Parts of this code were derived from:
) [//]: # (https://github.com/tsingqguo/efficientderain
) [//]: # (https://github.com/knazeri/edge-connect) 测试环境安装 conda install -p "D:\conda\envs\inpaint4shadow" pytorch==1.13.1 torchvision==0.14.1 pytorch-cuda=11.7 -c pytorch -c nvidia --dry-run 2>&1 | tail -20 我把conda安装在D:\conda\envs\inpaint4shadow,然后运行以下命令测试环境是否安装成功: conda run -p "D:\conda\envs\inpaint4shadow" python -c "import cv2; print('opencv:', cv2.__version__)" 2>&1 conda run -p "D:\conda\envs\inpaint4shadow" python -c "import skimage; print('skimage:', skimage.__version__)" 2>&1 conda run -p "D:\conda\envs\inpaint4shadow" python -c "import yaml; print('pyyaml: ok')" 2>&1 conda run -p "D:\conda\envs\inpaint4shadow" python -c "from PIL import Image; print('pillow: ok')" 2>&1 conda run -p "D:\conda\envs\inpaint4shadow" python -c "import lpips; print('lpips: ok')" 2>&1 修改文件inpaint4shadow\shadow_removal\checkpoints\config.yml中的文件路径改为本地Windows路径 #启动方式 以后启动 Web 演示只需: conda activate inpaint4shadow cd D:\Learn-Project\inpaint4shadow python web_demo.py 文件位置 Web 代码: web_demo.py 预训练权重: shadow_removal/checkpoints/ISTD+.pth 下一步建议 现在可以做的:打开 http://127.0.0.1:7860 试用,用手机拍几张有阴影的照片测试效果 下载完整 ISTD+ 数据集:补全 test_A/test_B 后可以跑标准评估指标 添加级联边界细化模块:提升阴影边界质量(你的创新点) 设置 share=True:在 web_demo.py 最后 demo.launch(share=True) 可生成公网链接分享给评委 训练完成了!最佳模型是 iter 4500,MAE: all=15.20, shadow=18.53, non-shadow=14.29。 训练指标趋势: Iteration MAE All MAE Shadow MAE Non-Shadow 500 15.64 18.99 14.73 500 (improved) 15.29 18.74 14.35 1000 15.32 18.68 14.41 3500 15.29 18.68 14.35 4500 15.20 18.53 14.29