Batch Watermark Removal at Scale: Open-Source Python Script Using YOLOv11 + LaMA, 1000+ Images/Min

9 days ago

Batch Watermark Removal at Scale: Open-Source Python Script Using YOLOv11 + LaMA, 1000+ Images/Min

Background

When working with large-scale image datasets, watermarks are a persistent headache. Training diffusion models on watermarked images causes artifacts to appear in generated outputs — the watermark pattern shows up in the corners. But manually removing watermarks from tens of thousands of images is simply not feasible.

A Reddit developer, jferments, faced exactly this problem: a dataset of 3.6 million images, over 500GB, spread across 180,000 subdirectories. Existing watermark removal tools work fine for single images or small batches, but none were designed for this scale.

His solution is an open-source Python script: watermark_remover. It combines a fine-tuned YOLOv11 model for watermark detection with LaMA for inpainting, and supports multi-GPU parallel processing. On a dual RTX 4090 machine, it achieves 1000+ images per minute.

Core Workflow

The script follows a simple pipeline:

  1. Recursively scan the input directory, preserving directory structure
  2. Use YOLOv11 (fine-tuned for watermark detection) to locate watermarks in each image
  3. Generate a watermark mask with optional dilation to cover edge artifacts
  4. Apply LaMA (Simple-LaMa) inpainting to reconstruct masked areas
  5. Output to the target directory, preserving the original folder structure

The entire process supports pause and resume — pressing Ctrl+C triggers a graceful shutdown that saves progress to .processing_log.txt. Re-running the same command automatically skips already-processed images.

Installation

git clone https://github.com/jferments/watermark_remover.git
cd watermark_remover
pip install -r requirements.txt

Download the watermark detection model weights:

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

Usage

# Basic: process a single directory
python3 watermark_remover.py -i /path/to/inputs -o /path/to/outputs

# Recursive: scan all subdirectories
python3 watermark_remover.py -i /path/to/inputs -o /path/to/outputs -R

Command-Line Options

OptionDescriptionDefault
-i, --inputInput folder path (required)
-o, --outputOutput folder path (required), preserves directory structure
-w, --weightsYOLOv11 model weights pathyolo11x-train28-best.pt
--confDetection confidence threshold (0.0-1.0); lower = more detections0.1
--dilateMask dilation in pixels; covers edge glow/aliasing; set 0 to disable15
-R, --recursiveRecursively scan all subdirectoriesOff
--cpu-workersCPU processes for writing outputAll CPU cores
--debugSave intermediate debug images (_mask_raw, _mask_preview)Off

Technical Details

YOLOv11 Watermark Detection

The detection model comes from the fancyfeast/joycaption-watermark-detection project on HuggingFace, fine-tuned from YOLOv11x on a large corpus of watermarked images. YOLO is known for real-time object detection, and the v11x variant is the largest in the family, offering the highest detection accuracy.

The confidence threshold is set to 0.1, meaning the model flags potential watermarks even with only 10% confidence — better to over-detect than miss. Combined with LaMA's inpainting, false positives are naturally reconstructed without visible artifacts.

Mask Dilation

Watermark edges often have a semi-transparent transition zone or glow. Detecting and removing only the core area can leave a visible "border line." The --dilate 15 setting expands the mask by 15 pixels to cover this transition zone. For most cases the default is sufficient, but you can increase it for watermarks with pronounced glow effects.

Multi-GPU Architecture

The script leverages PyTorch's multi-GPU support, distributing detection and inpainting tasks across available GPUs. CPU handles I/O (reading/writing images) while GPUs handle inference — pipeline parallelism that maximizes throughput.

Use Cases

  • Training data cleaning: Remove watermarks from large image datasets to prevent watermark artifacts in trained models
  • E-commerce image processing: Batch-remove platform watermarks or logos from product images
  • Archive cleanup: Clean copyright marks from legacy image archives
  • Academic research: Prepare clean images as training or testing data
  • Enterprise pipelines: Integrate into automated image processing workflows

Performance

HardwareProcessing SpeedBest For
Dual RTX 40901000+ images/minMillion-scale datasets
Single RTX 4090400-600 images/minHundred-thousand scale
RTX 3060/4060100-200 images/minTen-thousand scale
CPU only5-20 images/minSmall batches

Pause and Resume

Processing large datasets is rarely interruption-free. The script handles this gracefully:

  • Maintains a .processing_log.txt file in the output directory tracking processed files
  • Re-running the same command reads the log and skips already-processed files
  • Newly added images are handled correctly — same filename ≠ same image

This makes the script safe for long-running tasks, even across server reboots.

Comparison with Other Batch Solutions

SolutionScaleGPU RequiredAutomation
watermark_remover scriptMillion-scale✅ RequiredFully automatic, resume support
ComfyUI workflowsThousand-scale✅ RequiredSemi-automatic
Online batch toolsHundred-scale❌ Not neededAutomatic, quantity limits
Manual editingTens-scale❌ Not neededManual

Important Note

The script includes a clear disclaimer: it is provided for educational and technical demonstration purposes only. Removing watermarks may violate copyright or intellectual property rights. Users are solely responsible for legal compliance. For images you own or have explicit permission to modify, this tool is appropriate.

Summary

watermark_remover solves a very specific but painful problem: batch watermark removal from large datasets. It doesn't aim for a fancy UI or feature bloat — it focuses on one thing: fast, reliable processing of images at scale. YOLOv11's precise detection, LaMA's natural inpainting, multi-GPU parallelism, and checkpoint-based resume make it a pragmatic solution that engineers and researchers will appreciate.

Project page: https://github.com/jferments/watermark_remover

Author
Admin
Category