File size: 2,457 Bytes
14d2549
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# ResNet-50 Image Matting Baseline

This repository provides a robust image matting baseline leveraging a **ResNet-50** backbone, inspired by the training philosophies of **AEMatter**.

## ๐Ÿ“Š Experimental Results

We evaluate our model using standard matting metrics. The results below demonstrate the performance of the provided checkpoints. 

| Checkpoint | SAD โ†“ | MSE โ†“ | Grad โ†“ | Conn โ†“ |
| :--- | :--- | :--- | :--- | :--- |
| `model.ckpt` | 23.82677 | 0.00427 | 8.08990 | 19.02270 |
| **`model_better.ckpt`** | **23.47848** | **0.00396** | **7.80796** | **18.89092** |

> **Note:** `model_better.ckpt` represents the state-of-the-art (SOTA) performance for this baseline configuration.

---

## ๐Ÿ’ก Key Optimization: Eval-Mode Fine-Tuning

The superior performance of `model_better.ckpt` is attributed to a specific optimization strategy: **Fine-tuning the entire network in `eval()` mode** for a final epoch.

### Technical Intuition
In many image restoration tasks (such as Super-Resolution and Matting), Batch Normalization (BN) layers can introduce noise if the mini-batch statistics fluctuate significantly during the final stages of convergence. 

To achieve a more stable and high-performance result:
1. **The Strategy**: After standard training, we perform one additional fine-tuning epoch.
2. **The Mechanism**: The model is switched to `.eval()` mode, but gradients are **not** frozen. 
3. **The Benefit**: By keeping the BN layers in evaluation mode, we use the stable, pre-calculated global running statistics instead of batch-specific statistics. This allows the weights to strictly optimize for the loss objective without being affected by batch-level variance.
4. **Validation**: This approach has been proven effective in various low-level vision benchmarks to refine details and improve global consistency.

---

## ๐Ÿ›  Reproducing the Result

To replicate the performance of `model_better.ckpt`, ensure you run the final fine-tuning step as follows:
```python
# Final Fine-tuning in Eval Mode
model.eval() # Use global BN stats, but keep gradients active
optimizer = torch.optim.Adam(model.parameters(), lr=1e-5) # Use a smaller LR

for images, trimaps, gt in final_refinement_loader:
    optimizer.zero_grad()
    output = model(images, trimaps)
    loss = criterion(output, gt)
    loss.backward()
    optimizer.step()

# Save the refined model
save_checkpoint(model, "model_better.ckpt")

---
license: apache-2.0
---