Focused fork of the original jferments/watermark_remover project.
This fork keeps the original workflow: detect likely watermark regions with a YOLO model, build a mask, and inpaint the masked region with SimpleLama. The changes here focus on safer batch processing, backend selection, fallback behavior, reporting, and benchmark output.
Use this tool only for local processing of images you own or have permission to modify. Removing watermarks from images may violate copyright or other rights.
- Batch watermark detection and inpainting.
- Recursive folder processing with the original directory structure preserved.
- CPU mode.
- CUDA mode where supported by the original PyTorch/YOLO/SimpleLama workflow.
- Experimental DirectML mode with safe CPU fallback.
--copy-cleanand--no-copy-cleanbehavior for images with no detected watermark.- Per-image
processing_report.csv. - Per-session
benchmark_summary.json. - Detection, mask, inpainting, write, and total image timings.
- End-of-session benchmark summary.
- Optional debug mask output.
- Python 3.11 recommended on Windows.
On Windows, Python 3.11 is recommended.
git clone https://github.com/jferments/watermark_remover.git
cd watermark_remover
py -3.11 -m venv venv
.\venv\Scripts\Activate.ps1
python -m pip install --upgrade pip setuptools wheel
python -m pip install -r requirements.txtOn Linux/macOS:
python3 -m venv venv
source venv/bin/activate
python -m pip install --upgrade pip setuptools wheel
python -m pip install -r requirements.txtDownload the YOLO watermark detection checkpoint used by the original project:
wget https://huggingface.co/spaces/fancyfeast/joycaption-watermark-detection/resolve/main/yolo11x-train28-best.ptOptional DirectML support for Windows AMD GPUs:
python -m pip install -r requirements-directml.txtor:
python -m pip install torch-directmltorch-directml is intentionally optional and is not included in the base requirements.
Use --device to choose the AI backend:
--device auto: use CUDA if available, otherwise try DirectML, otherwise use CPU.--device cpu: force CPU detection and CPU inpainting.--device cuda: require CUDA. The command exits with a clear error if CUDA is unavailable.--device directmlor--device dml: try DirectML for YOLO detection.
DirectML support is experimental. On the tested Windows + AMD Radeon RX 6900 XT setup, DirectML initialized, but YOLO detection fell back to CPU because prediction/result extraction failed with:
Cannot set version_counter for inference tensor
SimpleLama inpainting also runs on CPU in DirectML mode. GPU acceleration is not guaranteed. This fork prioritizes reliable processing, reporting, and safe fallback over guaranteed AMD GPU acceleration.
CPU:
python watermark_remover.py -i C:\tmp\input -o C:\tmp\output_cpu -R --device cpu --debugExperimental DirectML:
python watermark_remover.py -i C:\tmp\input -o C:\tmp\output_dml -R --device directml --debugCUDA:
python watermark_remover.py -i C:\tmp\input -o C:\tmp\output_cuda -R --device cuda --debugNo-copy mode for images with no detected watermark:
python watermark_remover.py -i C:\tmp\input -o C:\tmp\output -R --device cpu --no-copy-cleanBy default, images with no detected watermark are copied to the output folder and reported as no_watermark_copied. With --no-copy-clean, they are not written and are reported as no_watermark_skipped.
Each run writes processing_report.csv in the output folder. Important fields:
status:cleaned,no_watermark_copied,no_watermark_skipped, orfailed.requested_device: the CLI device requested by the user.detection_backend: the backend actually used for YOLO detection for that image.inpainting_backend: the backend used for SimpleLama inpainting.detections_count: number of detected watermark boxes.max_confidence: highest detection confidence for the image.detection_time_sec: YOLO prediction and result extraction time.mask_time_sec: mask creation, dilation, and debug mask preparation time.inpainting_time_sec: SimpleLama time only.write_time_sec: output/debug write or copy time.total_image_time_sec: full per-image processing time.error: failure details whenstatusisfailed.
Each run also writes benchmark_summary.json in the output folder with aggregate totals and averages for the session.
The console prints an end-of-session benchmark summary with total session time, processed images, failed images, timing totals, timing averages, and actual backend usage.
With --debug, the script writes debug masks under output/debug/ for images with detections:
<name>_mask_raw.png<name>_mask_preview.png
For debug runs, the console also prints per-image backend, detection count, confidence, timings, output path, and any error.
- Test on a representative sample first, for example 20 to 50 images.
- Run with
--debug. - Inspect output images and debug masks.
- Tune
--confand--dilateif needed. - Only then run a large batch.
Large runs can be interrupted with Ctrl+C. The script uses .processing_log.txt in the output folder to skip files already completed in a later run.
- Works best with visible, localized, text-like watermarks.
- May fail on sophisticated, low-opacity, repeated, logo-based, or image-blended watermarks.
- False positives and false negatives are possible.
- Large datasets can take many hours depending on image size and number of detections.
- Always test on a representative sample before processing a full dataset.
- This tool does not guarantee perfect watermark removal.
- DirectML is experimental and may fall back to CPU.
- Inpainting is CPU-bound in the tested AMD/Windows setup.
This script is provided for educational and technical demonstration purposes only. Users are solely responsible for ensuring they have the legal right to modify the images they process. The author and contributors assume no liability for misuse of this tool.