Views
No views yet
Input: [B, 4, 256, 256] — RGB face crop + binary hair mask
│
┌───────────────┤ MobileNetV3-Small Encoder
│ │ (pretrained ImageNet)
s0 [16,128,128] ├── stage0 ────┤ stride-2 stem conv
s1 [16, 64, 64] ├── stage1 ────┤ InvertedResidual
s2 [24, 32, 32] ├── stage2 ────┤ InvertedResidual ×2
s3 [40, 16, 16] ├── stage3 ────┤ InvertedResidual ×3
s4 [96, 8, 8] └── stage4 ────┘ InvertedResidual ×5 (bottleneck)
│
│ DWS Decoder (bilinear↑ + DW conv + PW conv)
d3 [64, 16, 16] ├── dec3(s4+s3)
d2 [48, 32, 32] ├── dec2(d3+s2)
d1 [32, 64, 64] ├── dec1(d2+s1)
d0 [24,128,128] ├── dec0(d1+s0)
│
Output: [B, 3, 256, 256] — RGB bald face (via bilinear↑ + 1×1 conv + Tanh)| Metric | Value |
|---|---|
| Parameters | 891K |
| fp16 size | 1.7 MB |
| CoreML package | ~3-4 MB (6-bit palettized) |
| Target latency | <40 ms on A17 ANE |
| Input | 4-ch (RGB + hair mask), 256×256 |
| Output | 3-ch RGB, 256×256 |
gen_bald_pairs.py pipeline:1# Install dependencies
2pip install torch torchvision accelerate lpips onnxruntime-gpu trackio huggingface_hub
3
4# Single GPU (debug)
5python train.py --data_dir /path/to/data --batch_size 16 --num_epochs 2
6
7# 8×A100 distributed
8bash launch_train.sh1import torch
2from model import UNetMobile
3
4model = UNetMobile(in_channels=4, out_channels=3, pretrained=False)
5state_dict = torch.load('generator_latest.pt', map_location='cpu')
6model.load_state_dict(state_dict)
7model.eval()
8
9# Input: [1, 4, 256, 256] — RGB in [-1,1] + mask in [0,1]
10input_4ch = torch.cat([face_rgb_normalized, hair_mask], dim=1)
11with torch.no_grad():
12 bald_face = model(input_4ch) # [-1, 1]
13 bald_face = (bald_face + 1) / 2 # → [0, 1]1python export_coreml.py \
2 --checkpoint generator_latest.pt \
3 --output UNetMobileBald.mlpackage \
4 --compress 6bit1let config = MLModelConfiguration()
2config.computeUnits = .all // CPU + GPU + ANE
3let model = try UNetMobileBald(configuration: config)
4
5// Input: MLMultiArray [1, 4, 256, 256], pixel values 0-255
6let prediction = try model.prediction(input_image: inputArray)
7let output = prediction.output_image // [1, 3, 256, 256], values 0-255| File | Description |
|---|---|
model.py | UNet-Mobile architecture |
losses.py | L1 + LPIPS + PatchGAN + ArcFace losses |
dataset.py | Dataset loader for bald-pair data |
train.py | Full training script (Accelerate DDP) |
export_coreml.py | PyTorch → CoreML mlprogram conversion |
launch_train.sh | 8×A100 launch script |
accelerate_config.yaml | Accelerate distributed config |