Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -1,54 +1,187 @@
|
|
| 1 |
---
|
|
|
|
|
|
|
| 2 |
license: mit
|
|
|
|
| 3 |
tags:
|
| 4 |
- image-segmentation
|
| 5 |
- watermark-removal
|
| 6 |
-
- pytorch
|
| 7 |
- unet
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
---
|
| 9 |
|
| 10 |
-
# Watermark Remover
|
| 11 |
|
| 12 |
-
|
| 13 |
|
| 14 |
-
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
## Usage
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
```python
|
| 24 |
import torch
|
|
|
|
| 25 |
import segmentation_models_pytorch as smp
|
| 26 |
-
from
|
| 27 |
|
| 28 |
-
#
|
| 29 |
-
weights_path = hf_hub_download(
|
| 30 |
-
repo_id="christophernavas/watermark-remover",
|
| 31 |
-
filename="segmenter.pth"
|
| 32 |
-
)
|
| 33 |
-
|
| 34 |
-
# Load model
|
| 35 |
model = smp.UnetPlusPlus(
|
| 36 |
encoder_name="efficientnet-b4",
|
| 37 |
encoder_weights=None,
|
| 38 |
in_channels=3,
|
| 39 |
classes=1,
|
| 40 |
-
activation=None,
|
| 41 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
model.load_state_dict(torch.load(weights_path, map_location="cpu"))
|
| 43 |
model.eval()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
```
|
| 45 |
|
| 46 |
-
##
|
| 47 |
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
## License
|
| 53 |
|
| 54 |
-
MIT
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
language:
|
| 3 |
+
- en
|
| 4 |
license: mit
|
| 5 |
+
library_name: segmentation-models-pytorch
|
| 6 |
tags:
|
| 7 |
- image-segmentation
|
| 8 |
- watermark-removal
|
|
|
|
| 9 |
- unet
|
| 10 |
+
- efficientnet
|
| 11 |
+
- devynlabs
|
| 12 |
+
- pixelforge
|
| 13 |
+
- pytorch
|
| 14 |
+
datasets:
|
| 15 |
+
- custom
|
| 16 |
+
metrics:
|
| 17 |
+
- iou
|
| 18 |
+
pipeline_tag: image-segmentation
|
| 19 |
+
model-index:
|
| 20 |
+
- name: watermark-remover
|
| 21 |
+
results:
|
| 22 |
+
- task:
|
| 23 |
+
type: image-segmentation
|
| 24 |
+
name: Image Segmentation
|
| 25 |
+
dataset:
|
| 26 |
+
name: Banana Watermarks
|
| 27 |
+
type: custom
|
| 28 |
+
metrics:
|
| 29 |
+
- type: iou
|
| 30 |
+
value: 0.9748
|
| 31 |
+
name: IoU
|
| 32 |
+
- type: accuracy
|
| 33 |
+
value: 0.95
|
| 34 |
+
name: Detection Rate
|
| 35 |
---
|
| 36 |
|
| 37 |
+
# Watermark Remover
|
| 38 |
|
| 39 |
+
Modèle de segmentation pour détecter et supprimer les watermarks dans les images.
|
| 40 |
|
| 41 |
+
Développé par [DevynLabs](https://devynlabs.com) dans le cadre du projet [PixelForge](https://github.com/christophernavas/pixelforge).
|
| 42 |
|
| 43 |
+
## Description
|
| 44 |
+
|
| 45 |
+
Watermark Remover utilise un pipeline en deux étapes :
|
| 46 |
+
|
| 47 |
+
1. **Segmentation** : UNet++ avec encodeur EfficientNet-B4 pour détecter les watermarks
|
| 48 |
+
2. **Inpainting** : LaMa pour reconstruire les zones masquées
|
| 49 |
+
|
| 50 |
+
```
|
| 51 |
+
Image → UNet++ (EfficientNet-B4) → Masque → LaMa → Image propre
|
| 52 |
+
```
|
| 53 |
+
|
| 54 |
+
## Performance
|
| 55 |
+
|
| 56 |
+
| Métrique | Score |
|
| 57 |
+
|----------|-------|
|
| 58 |
+
| IoU (validation) | **97.48%** |
|
| 59 |
+
| Taux de détection | **95%** (20/21 images) |
|
| 60 |
+
|
| 61 |
+
### Détails
|
| 62 |
+
|
| 63 |
+
- Entraîné sur des watermarks Banana (style texte semi-transparent)
|
| 64 |
+
- 1 faux négatif sur fond très lumineux
|
| 65 |
+
- Excellent sur watermarks similaires au dataset
|
| 66 |
+
|
| 67 |
+
## Architecture
|
| 68 |
+
|
| 69 |
+
| Composant | Valeur |
|
| 70 |
+
|-----------|--------|
|
| 71 |
+
| Encoder | EfficientNet-B4 (pretrained ImageNet) |
|
| 72 |
+
| Decoder | UNet++ |
|
| 73 |
+
| Input size | 512x512 |
|
| 74 |
+
| Output | Masque binaire (probabilité watermark) |
|
| 75 |
+
| Inpainting | LaMa (simple-lama-inpainting) |
|
| 76 |
|
| 77 |
## Usage
|
| 78 |
|
| 79 |
+
### Installation
|
| 80 |
+
|
| 81 |
+
```bash
|
| 82 |
+
pip install segmentation-models-pytorch simple-lama-inpainting torch torchvision pillow
|
| 83 |
+
```
|
| 84 |
+
|
| 85 |
+
### Détection seule
|
| 86 |
+
|
| 87 |
```python
|
| 88 |
import torch
|
| 89 |
+
from PIL import Image
|
| 90 |
import segmentation_models_pytorch as smp
|
| 91 |
+
from torchvision import transforms
|
| 92 |
|
| 93 |
+
# Charger le modèle
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
model = smp.UnetPlusPlus(
|
| 95 |
encoder_name="efficientnet-b4",
|
| 96 |
encoder_weights=None,
|
| 97 |
in_channels=3,
|
| 98 |
classes=1,
|
|
|
|
| 99 |
)
|
| 100 |
+
|
| 101 |
+
# Charger les poids depuis HuggingFace
|
| 102 |
+
from huggingface_hub import hf_hub_download
|
| 103 |
+
weights_path = hf_hub_download("christophernavas/watermark-remover", "segmenter.pth")
|
| 104 |
model.load_state_dict(torch.load(weights_path, map_location="cpu"))
|
| 105 |
model.eval()
|
| 106 |
+
|
| 107 |
+
# Préparer l image
|
| 108 |
+
transform = transforms.Compose([
|
| 109 |
+
transforms.Resize((512, 512)),
|
| 110 |
+
transforms.ToTensor(),
|
| 111 |
+
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
|
| 112 |
+
])
|
| 113 |
+
|
| 114 |
+
image = Image.open("image_with_watermark.png").convert("RGB")
|
| 115 |
+
input_tensor = transform(image).unsqueeze(0)
|
| 116 |
+
|
| 117 |
+
# Prédiction
|
| 118 |
+
with torch.no_grad():
|
| 119 |
+
mask = torch.sigmoid(model(input_tensor))
|
| 120 |
+
mask = (mask > 0.5).float()
|
| 121 |
+
|
| 122 |
+
# mask contient le masque binaire des watermarks détectés
|
| 123 |
```
|
| 124 |
|
| 125 |
+
### Pipeline complet (détection + suppression)
|
| 126 |
|
| 127 |
+
```python
|
| 128 |
+
from simple_lama_inpainting import SimpleLama
|
| 129 |
+
|
| 130 |
+
# Après avoir obtenu le masque...
|
| 131 |
+
lama = SimpleLama()
|
| 132 |
+
result = lama(image, mask)
|
| 133 |
+
result.save("image_clean.png")
|
| 134 |
+
```
|
| 135 |
+
|
| 136 |
+
## Training
|
| 137 |
+
|
| 138 |
+
- **Framework**: PyTorch + segmentation-models-pytorch
|
| 139 |
+
- **Loss**: BCE + Dice Loss
|
| 140 |
+
- **Optimizer**: Adam (lr=1e-4)
|
| 141 |
+
- **Augmentations**: Rotation, flip, color jitter, noise
|
| 142 |
+
- **Platform**: [Modal](https://modal.com) (GPU T4)
|
| 143 |
+
- **Epochs**: 50
|
| 144 |
+
|
| 145 |
+
### Dataset
|
| 146 |
+
|
| 147 |
+
Images synthétiques générées avec des watermarks Banana :
|
| 148 |
+
- Variations de position, taille, opacité
|
| 149 |
+
- Différents fonds (photos, illustrations)
|
| 150 |
+
|
| 151 |
+
## Cas d usage
|
| 152 |
+
|
| 153 |
+
- Nettoyage d images pour e-commerce
|
| 154 |
+
- Préparation de datasets ML
|
| 155 |
+
- Restoration de photos
|
| 156 |
+
|
| 157 |
+
## Limitations
|
| 158 |
+
|
| 159 |
+
- Optimisé pour watermarks textuels semi-transparents (style Banana)
|
| 160 |
+
- Peut avoir des difficultés avec :
|
| 161 |
+
- Watermarks très opaques
|
| 162 |
+
- Watermarks sur fonds très lumineux/blancs
|
| 163 |
+
- Logos complexes (non-textuels)
|
| 164 |
+
- LaMa peut introduire des artefacts sur les textures complexes
|
| 165 |
|
| 166 |
## License
|
| 167 |
|
| 168 |
+
MIT - Usage commercial autorisé.
|
| 169 |
+
|
| 170 |
+
## Citation
|
| 171 |
+
|
| 172 |
+
```bibtex
|
| 173 |
+
@misc{watermarkremover2024,
|
| 174 |
+
author = {Christopher Navas},
|
| 175 |
+
title = {Watermark Remover: UNet++ Segmentation for Watermark Detection},
|
| 176 |
+
year = {2024},
|
| 177 |
+
publisher = {HuggingFace},
|
| 178 |
+
url = {https://huggingface.co/christophernavas/watermark-remover}
|
| 179 |
+
}
|
| 180 |
+
```
|
| 181 |
+
|
| 182 |
+
## Links
|
| 183 |
+
|
| 184 |
+
- [DevynLabs](https://devynlabs.com)
|
| 185 |
+
- [PixelForge Documentation](https://florinha.com/docs/projets/pixelforge)
|
| 186 |
+
- [segmentation-models-pytorch](https://github.com/qubvel/segmentation_models.pytorch)
|
| 187 |
+
- [LaMa Inpainting](https://github.com/advimman/lama)
|