Skip to content
 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

watermark_remover

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.

Features

  • 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-clean and --no-copy-clean behavior 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.

Installation

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.txt

On Linux/macOS:

python3 -m venv venv
source venv/bin/activate

python -m pip install --upgrade pip setuptools wheel
python -m pip install -r requirements.txt

Download the YOLO watermark detection checkpoint used by the original project:

wget https://huggingface.co/spaces/fancyfeast/joycaption-watermark-detection/resolve/main/yolo11x-train28-best.pt

Optional DirectML support for Windows AMD GPUs:

python -m pip install -r requirements-directml.txt

or:

python -m pip install torch-directml

torch-directml is intentionally optional and is not included in the base requirements.

Device Modes

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 directml or --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.

Usage

CPU:

python watermark_remover.py -i C:\tmp\input -o C:\tmp\output_cpu -R --device cpu --debug

Experimental DirectML:

python watermark_remover.py -i C:\tmp\input -o C:\tmp\output_dml -R --device directml --debug

CUDA:

python watermark_remover.py -i C:\tmp\input -o C:\tmp\output_cuda -R --device cuda --debug

No-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-clean

By 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.

Reports

Each run writes processing_report.csv in the output folder. Important fields:

  • status: cleaned, no_watermark_copied, no_watermark_skipped, or failed.
  • 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 when status is failed.

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.

Debug Output

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.

Recommended Workflow

  1. Test on a representative sample first, for example 20 to 50 images.
  2. Run with --debug.
  3. Inspect output images and debug masks.
  4. Tune --conf and --dilate if needed.
  5. 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.

Known Limitations

  • 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.

Disclaimer

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.

About

Multi-GPU enabled fast batch removal of watermarks from large image datasets

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages