Upload README.md with huggingface_hub
Browse files
README.md
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: cc-by-nc-4.0
|
| 3 |
+
tags:
|
| 4 |
+
- mirror-detection
|
| 5 |
+
- image-segmentation
|
| 6 |
+
- computer-vision
|
| 7 |
+
- pytorch
|
| 8 |
+
---
|
| 9 |
+
|
| 10 |
+
# PMDNet — Progressive Mirror Detection
|
| 11 |
+
|
| 12 |
+
Pretrained weights for **PMDNet**, the model introduced in the CVPR 2020 paper [*Progressive Mirror Detection*](https://jiaying.link/cvpr2020-pgd/).
|
| 13 |
+
|
| 14 |
+
## Model Description
|
| 15 |
+
|
| 16 |
+
PMDNet progressively detects mirror surfaces by leveraging multi-scale contrast cues and relational context.
|
| 17 |
+
|
| 18 |
+
**Architecture overview:**
|
| 19 |
+
|
| 20 |
+
- **Backbone** — ResNeXt-101 (32×4d), producing feature maps at four scales.
|
| 21 |
+
- **Contrast Module** (`Contrast_Module_Deep`) — at each scale, dilated convolutions capture local–context differences, then four stacked `Contrast_Block_Deep` units compute pairwise local–context subtractions at two dilation rates. Outputs are aggregated with CBAM (channel + spatial attention).
|
| 22 |
+
- **Relation Attention** (`Relation_Attention` / `RAttention`) — criss-cross attention over rows, columns, and both diagonals, enabling long-range relational reasoning without a full self-attention map.
|
| 23 |
+
- **Decoder** — four transposed-convolution upsampling stages with CBAM refinement produce intermediate saliency predictions (`f4 → f1`), each gated by the previous scale's prediction for progressive focus.
|
| 24 |
+
- **Edge Branch** — extracts edge features from `layer1` fused with high-level `cbam_4` context, producing an explicit edge map.
|
| 25 |
+
- **Refinement** — a single 1×1 conv fuses the original image, all four scale predictions, and the edge map into the final mirror mask.
|
| 26 |
+
|
| 27 |
+
**Input:** RGB image, resized to 416×416.
|
| 28 |
+
**Output (eval):** `(f4, f3, f2, f1, edge, final)` — sigmoid-activated predictions at input resolution.
|
| 29 |
+
Optional CRF post-processing is applied to the final prediction.
|
| 30 |
+
|
| 31 |
+
## Weights
|
| 32 |
+
|
| 33 |
+
| File | Size | Description |
|
| 34 |
+
|------|------|-------------|
|
| 35 |
+
| `pmd.pth` | ~414 MB | Full model weights (ResNeXt-101 backbone + decoder) |
|
| 36 |
+
|
| 37 |
+
## Usage
|
| 38 |
+
|
| 39 |
+
```python
|
| 40 |
+
import torch
|
| 41 |
+
from torchvision import transforms
|
| 42 |
+
from PIL import Image
|
| 43 |
+
from model.pmd import PMD # from the official code release
|
| 44 |
+
|
| 45 |
+
model = PMD()
|
| 46 |
+
model.load_state_dict(torch.load("pmd.pth", map_location="cpu"))
|
| 47 |
+
model.eval()
|
| 48 |
+
|
| 49 |
+
transform = transforms.Compose([
|
| 50 |
+
transforms.Resize((416, 416)),
|
| 51 |
+
transforms.ToTensor(),
|
| 52 |
+
transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225]),
|
| 53 |
+
])
|
| 54 |
+
|
| 55 |
+
img = Image.open("your_image.jpg").convert("RGB")
|
| 56 |
+
x = transform(img).unsqueeze(0)
|
| 57 |
+
|
| 58 |
+
with torch.no_grad():
|
| 59 |
+
f4, f3, f2, f1, edge, final = model(x)
|
| 60 |
+
# `final` is the mirror mask prediction (values in [0, 1])
|
| 61 |
+
```
|
| 62 |
+
|
| 63 |
+
Full inference script with CRF post-processing: see [`code_minimal/infer.py`](https://jiaying.link/cvpr2020-pgd/).
|
| 64 |
+
|
| 65 |
+
## Dataset
|
| 66 |
+
|
| 67 |
+
Trained on the [PMD dataset](https://huggingface.co/datasets/garrying/PMD) (5,095 training images with mirror masks and edge maps).
|
| 68 |
+
|
| 69 |
+
## Performance
|
| 70 |
+
|
| 71 |
+
| Method | F_β | MAE |
|
| 72 |
+
|-----------|-------|-------|
|
| 73 |
+
| EGNet | 0.672 | 0.087 |
|
| 74 |
+
| MirrorNet | 0.748 | 0.061 |
|
| 75 |
+
| **PMDNet (ours)** | **0.790** | **0.032** |
|
| 76 |
+
|
| 77 |
+
Evaluated on the PMD test split (571 images).
|
| 78 |
+
|
| 79 |
+
## License
|
| 80 |
+
|
| 81 |
+
CC BY-NC 4.0 — non-commercial use only.
|
| 82 |
+
|
| 83 |
+
## Citation
|
| 84 |
+
|
| 85 |
+
```bibtex
|
| 86 |
+
@INPROCEEDINGS{PMD:2020,
|
| 87 |
+
Author = {Jiaying Lin and Guodong Wang and Rynson W.H. Lau},
|
| 88 |
+
Title = {Progressive Mirror Detection},
|
| 89 |
+
Booktitle = {Proc. CVPR},
|
| 90 |
+
Year = {2020}
|
| 91 |
+
}
|
| 92 |
+
```
|
| 93 |
+
|
| 94 |
+
## Contact
|
| 95 |
+
|
| 96 |
+
csjylin@gmail.com
|