Open-source watermark segmentation by DiffusionDynamics.ai and clear.photo. Harness deep learning plus synthetic data augmentation in PyTorch to detect logos/text precisely. This minimal code references top research for robust, adaptable watermark removal.
Jupyter Notebook
79
3 commits
updated Apr 24, 2025
This repository by Diffusion Dynamics, showcases the core technology behind the watermark segmentation capabilities of our first product, clear.photo. This work leverages insights from research on diffusion models for image restoration tasks.
Effective watermark removal hinges on accurately identifying the watermark's precise location and shape within the image. This code tackles the first crucial step: watermark segmentation.
We present a deep learning approach trained to generate masks highlighting watermark regions. This repository focuses on segmenting logo-based watermarks, demonstrating a robust technique adaptable to various watermark types. The methodologies employed draw inspiration from advancements in image segmentation.
This repository aims to consolidate key ideas from recent research in visible watermark removal and segmentation, including techniques presented in:
It distills these concepts into a minimal, functional codebase focused purely on the segmentation task. The goal is to provide a clear, understandable baseline that is easy to modify and build upon, even allowing for fine-tuning on consumer hardware like laptops with Apple M-series chips. It serves as a foundational example demonstrating the core techniques applicable to building more complex tools like clear.photo.
A typical advanced watermark removal pipeline involves:
This project provides the necessary tools to train a watermark segmentation model and use it for inference. Key components include:
watermark-segmentation.ipynb: A Jupyter notebook containing the end-to-end workflow:
segmentation_models.pytorch library).dataset.py.pytorch-lightning.dataset.py: A Python script defining the Dataset class responsible for generating training data. It dynamically applies logo watermarks (from the logos/ directory) onto background images with randomized properties (scale, rotation, opacity, position, blend mode) to create diverse training samples and their corresponding ground truth masks. This data augmentation strategy is key to the model's robustness.requirements.txt: Lists all necessary Python dependencies.*.pth: Model weights from different training epochs.logos/: A directory for sample watermark logos. Populate this with logos relevant to your use case.lightning_logs/: Default directory where PyTorch Lightning saves training logs and checkpoints.Follow these steps to set up and run the project:
1. Prerequisites:
wget and unzip (or equivalent tools for downloading and extracting datasets).python --version
# Ensure it shows 3.10.x or newer
2. Clone the Repository:
git clone https://github.com/Diffusion-Dynamics/watermark-segmentation
cd watermark-segmentation
3. Install Dependencies:
It's recommended to use a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows use `virtual\Scripts\activate`
pip install -r requirements.txt
4. Download Pre-trained Model (Optional):
If you want to fine-tune the model or run inference without training from scratch, you can download a pre-trained checkpoint:
wget https://pub-1039b7ab1ee541c1a1f5ff68ddc309ce.r2.dev/best_watermark_model_mit_b5_best.pth
This checkpoint is compatible with the model architecture defined in the notebook.
5. Prepare Datasets:
# Example using Flickr8k
wget https://github.com/jbrownlee/Datasets/releases/download/Flickr8k/Flickr8k_Dataset.zip
unzip Flickr8k_Dataset.zip
# Ensure the notebook points to the 'Flicker8k_Dataset' directory
logos/ directory. The dataset.py script will randomly use these.6. Run the Notebook:
jupyter lab
watermark-segmentation.ipynb.The core segmentation model leverages standard segmentation architectures conveniently provided by hypothesized segmentation-models-pytorch library (https://github.com/qubvel-org/segmentation_models.pytorch). This library offers pre-implemented models with various backbones.
To accelerate training and reduce the need for vast amounts of training data, the model utilizes a backbone pre-trained on the ImageNet dataset.
The notebook also demonstrates loading a provided pre-trained checkpoint (*.pth). This serves as an excellent starting point for fine-tuning the model on your specific watermark types or even adapting it for related tasks, such as detecting other forms of synthetic image artifacts. Fine-tuning can significantly reduce the required training time and data compared to training from scratch.
Training is managed using pytorch-lightning, which simplifies the training loop, facilitates multi-GPU training, and integrates logging.
The training process is compatible with both Apple M-series chips (via MPS) and NVIDIA GPUs (via CUDA). While NVIDIA GPUs generally offer faster training, fine-tuning on an Apple M-series chip is feasible and can typically be completed within a few hours.
The key to achieving good performance and generalization lies in the data generation strategy within dataset.py. This involves synthetic data augmentation: dynamically applying diverse and randomized watermarks (varying size, position, opacity, rotation, blend modes) onto clean background images during training. This forces the model learns to identify watermarks under various conditions, making it robust to unseen watermarks and backgrounds. This approach is informed by techniques discussed in related image restoration research (arXiv:2502.02676).
The notebook (watermark-segmentation.ipynb) demonstrates how to:
The output mask precisely identifies the watermark regions, ready for use in downstream removal tasks.
Building a robust, production-ready watermark segmentation and removal system involves significant engineering challenges beyond the scope of this repository. If you require a fast, scalable, and reliable solution designed for real-world demands, consider using our platform: clear.photo.
3 commits
Jupyter Notebook
99.8%
Open-source watermark segmentation by DiffusionDynamics.ai and clear.photo. Harness deep learning plus synthetic data augmentation in PyTorch to detect logos/text precisely. This minimal code references top research for robust, adaptable watermark removal.
Jupyter Notebook
79
3 commits
updated Apr 24, 2025
This repository by Diffusion Dynamics, showcases the core technology behind the watermark segmentation capabilities of our first product, clear.photo. This work leverages insights from research on diffusion models for image restoration tasks.
Effective watermark removal hinges on accurately identifying the watermark's precise location and shape within the image. This code tackles the first crucial step: watermark segmentation.
We present a deep learning approach trained to generate masks highlighting watermark regions. This repository focuses on segmenting logo-based watermarks, demonstrating a robust technique adaptable to various watermark types. The methodologies employed draw inspiration from advancements in image segmentation.
This repository aims to consolidate key ideas from recent research in visible watermark removal and segmentation, including techniques presented in:
It distills these concepts into a minimal, functional codebase focused purely on the segmentation task. The goal is to provide a clear, understandable baseline that is easy to modify and build upon, even allowing for fine-tuning on consumer hardware like laptops with Apple M-series chips. It serves as a foundational example demonstrating the core techniques applicable to building more complex tools like clear.photo.
A typical advanced watermark removal pipeline involves:
This project provides the necessary tools to train a watermark segmentation model and use it for inference. Key components include:
watermark-segmentation.ipynb: A Jupyter notebook containing the end-to-end workflow:
segmentation_models.pytorch library).dataset.py.pytorch-lightning.dataset.py: A Python script defining the Dataset class responsible for generating training data. It dynamically applies logo watermarks (from the logos/ directory) onto background images with randomized properties (scale, rotation, opacity, position, blend mode) to create diverse training samples and their corresponding ground truth masks. This data augmentation strategy is key to the model's robustness.requirements.txt: Lists all necessary Python dependencies.*.pth: Model weights from different training epochs.logos/: A directory for sample watermark logos. Populate this with logos relevant to your use case.lightning_logs/: Default directory where PyTorch Lightning saves training logs and checkpoints.Follow these steps to set up and run the project:
1. Prerequisites:
wget and unzip (or equivalent tools for downloading and extracting datasets).python --version
# Ensure it shows 3.10.x or newer
2. Clone the Repository:
git clone https://github.com/Diffusion-Dynamics/watermark-segmentation
cd watermark-segmentation
3. Install Dependencies:
It's recommended to use a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows use `virtual\Scripts\activate`
pip install -r requirements.txt
4. Download Pre-trained Model (Optional):
If you want to fine-tune the model or run inference without training from scratch, you can download a pre-trained checkpoint:
wget https://pub-1039b7ab1ee541c1a1f5ff68ddc309ce.r2.dev/best_watermark_model_mit_b5_best.pth
This checkpoint is compatible with the model architecture defined in the notebook.
5. Prepare Datasets:
# Example using Flickr8k
wget https://github.com/jbrownlee/Datasets/releases/download/Flickr8k/Flickr8k_Dataset.zip
unzip Flickr8k_Dataset.zip
# Ensure the notebook points to the 'Flicker8k_Dataset' directory
logos/ directory. The dataset.py script will randomly use these.6. Run the Notebook:
jupyter lab
watermark-segmentation.ipynb.The core segmentation model leverages standard segmentation architectures conveniently provided by hypothesized segmentation-models-pytorch library (https://github.com/qubvel-org/segmentation_models.pytorch). This library offers pre-implemented models with various backbones.
To accelerate training and reduce the need for vast amounts of training data, the model utilizes a backbone pre-trained on the ImageNet dataset.
The notebook also demonstrates loading a provided pre-trained checkpoint (*.pth). This serves as an excellent starting point for fine-tuning the model on your specific watermark types or even adapting it for related tasks, such as detecting other forms of synthetic image artifacts. Fine-tuning can significantly reduce the required training time and data compared to training from scratch.
Training is managed using pytorch-lightning, which simplifies the training loop, facilitates multi-GPU training, and integrates logging.
The training process is compatible with both Apple M-series chips (via MPS) and NVIDIA GPUs (via CUDA). While NVIDIA GPUs generally offer faster training, fine-tuning on an Apple M-series chip is feasible and can typically be completed within a few hours.
The key to achieving good performance and generalization lies in the data generation strategy within dataset.py. This involves synthetic data augmentation: dynamically applying diverse and randomized watermarks (varying size, position, opacity, rotation, blend modes) onto clean background images during training. This forces the model learns to identify watermarks under various conditions, making it robust to unseen watermarks and backgrounds. This approach is informed by techniques discussed in related image restoration research (arXiv:2502.02676).
The notebook (watermark-segmentation.ipynb) demonstrates how to:
The output mask precisely identifies the watermark regions, ready for use in downstream removal tasks.
Building a robust, production-ready watermark segmentation and removal system involves significant engineering challenges beyond the scope of this repository. If you require a fast, scalable, and reliable solution designed for real-world demands, consider using our platform: clear.photo.
3 commits
Jupyter Notebook
99.8%