PortraitNet
Lightweight MobileNet-v2 U-shape net that segments portraits in real time on a phone.
Segmentation · 234 operations Checked
Click or tap a spot to read it up close. Scroll or drag inside the diagram to move through it. Zoom with + and − or Ctrl and scroll. Press 0 for the whole graph. Swipe inside the diagram to move through it. Use + and − to zoom.
At a glance
- Task
- Segmentation
- Parameters
- 2.1M
- Operations
- 234
- Framework
- PyTorch
- Recurrent
- No
- Published
- Computers & Graphics (CAD/Graphics 2019)
- Cited by
- 50 (as of 5 October 2026)
- Authors
- Song-Hai Zhang, Xin Dong, Jia Li and others
- Source
- GitHub: dong-x16/PortraitNet
- Checked
- Passed: the trace was replayed operation by operation and matched the model's own output for this input.
Files
The file opened in a new tab. Use your browser's Save command there to keep it.
The diagram is a drawing of a TorchLens trace of the source code. It contains no code or weights.
Details
- Stable ID
- m14405
- Graph hash
- 2612772dff1272da22c91d750c4899d89d8e51c02dc0f28254bba2ee5d5c4281
- Skeleton hash
- ca11baf6dad6b20ccc76209d148e024b452c095f929754e5ebacaf963a07afa6
- Architecture hash
- feb46bf5b0fb956a029870ca14480022b45f1c7460f16c8df27df364b96a5e75
- Diagram SHA-256
- 0af990312f6721c3128c0b4ed163d1399a2a07347b9a26fae9f344e4f0bb8154
- TorchLens version
- 2.36.0
- Renderer
- graphviz 2.43.0+pyvips 3.2.0+libvips 8.18.7+render-opts@06c1f0d3
- Check
- Forward pass replayed in PyTorch
What it is
PortraitNet is a small segmentation network built to cut a person out of a selfie fast enough for live background replacement on a phone. It is a lightweight U-shape network with a MobileNet-v2 encoder, and the paper reports it processing 224 × 224 RGB images at 30 FPS on an iPhone 7. The encoder downsamples by 32× to get a large receptive field cheaply, and the decoder upsamples back with deconvolutions and residual transition blocks whose convolutions are depthwise separable.
The interesting part is what happens only at training time: two auxiliary losses that cost nothing at inference. A boundary loss adds one convolution layer in parallel with the mask layer to predict portrait edges, with Canny-derived boundary targets 4 pixels wide and focal loss to cope with the heavy class imbalance. A consistency constraint loss makes the network its own teacher: a deformed image A and a texture-degraded copy A’ should give the same heatmap, so the cleaner output supervises the noisier one through a KL divergence. The authors frame this as a cheap alternative to model distillation, which would need a large teacher and more data.
With both losses the paper reports 96.62% on EG1800 and 93.43% on Supervise-Portrait, a dataset the authors assembled from Supervise.ly with the same face-crop process as EG1800. Because several EG1800 image links had gone dead, training used 1447 images and validation 289. The captured build keeps the boundary convolution, so it returns two 224 × 224 two-channel maps, the segmentation and the boundary map, even though the paper says the boundary layer is not used for segmentation inference. The released code targets Python 2.7 and PyTorch 0.3.0.post4.
Key idea. A MobileNet-v2 U-shape segmenter made accurate enough for mobile portraits by a boundary loss and a self-supervised consistency constraint loss that act only during training.
- PortraitNet
- portrait segmentation
- real-time segmentation
- mobile segmentation
- background replacement
- selfie matting
- MobileNetV2
- EG1800
- Supervise-Portrait
- boundary loss
- consistency constraint loss
AI-written summary, checked automatically against its sources; not reviewed by a person. Corrections welcome.
Cite the paper
@article{Zhang_2019, title={PortraitNet: Real-time portrait segmentation network for mobile device}, volume={80}, ISSN={0097-8493}, url={http://dx.doi.org/10.1016/j.cag.2019.03.007}, DOI={10.1016/j.cag.2019.03.007}, journal={Computers & Graphics}, publisher={Elsevier BV}, author={Zhang, Song-Hai and Dong, Xin and Li, Hui and Li, Ruilong and Yang, Yong-Liang}, year={2019}, month=May, pages={104–113} }