{ "cells": [ { "cell_type": "markdown", "id": "03cfffa3-2398-4d55-bf1e-fe3e01f10d68", "metadata": {}, "source": [ "## 1. PP-Matting model introduction\n", "\n", "\n", "In many image matting algorithms, in order to pursue precision, trimap is often provided as auxiliary information, but this greatly limits the application of the algorithm. PP-Matting, as a trimap-free image matting method, overcomes the disadvantages of auxiliary information and achieves SOTA performance in Composition-1k and Distinctions-646 datasets. PP-Matting uses Semantic Context Branch (SCB) to extract high-level semantic information of images and gradually guides high-resolution detail branch (HRDB) to extract details in transition area through Guidance Flow. Finally, alpha matte is obtained by fusing semantic map and detail map with fusion module.\n", "\n", "More details can be found in the paper: https://arxiv.org/abs/2204.09433.\n", "\n", "More about PaddleMatting,you can click https://github.com/PaddlePaddle/PaddleSeg/tree/develop/Matting to learn.\n", "\n" ] }, { "cell_type": "markdown", "id": "8cbcf510-dc56-43f9-9864-5e1de3c7b272", "metadata": {}, "source": [ "## 2. Model Effects and Application Scenarios\n", "The human matting effects of PP-Matting are as follows:\n", "
\n", "\n", "
\n" ] }, { "cell_type": "markdown", "id": "8d9da224-edd4-4c9e-ab2d-cba7ee5a92a4", "metadata": {}, "source": [ "## 3. How to Use the Model" ] }, { "cell_type": "markdown", "id": "2ac57be7-c00f-441e-ad82-635f6268b6bd", "metadata": {}, "source": [ "### 3.1 Model Inference\n", "* Download" ] }, { "cell_type": "code", "execution_count": null, "id": "3ea22cb4-5bed-4ce0-858b-3bbb342e8ccf", "metadata": { "scrolled": true, "tags": [] }, "outputs": [], "source": [ "!mkdir -p ~/work\n", "%cd ~/work\n", "!git clone --depth 1 https://gitee.com/paddlepaddle/PaddleSeg" ] }, { "cell_type": "markdown", "id": "fd7142e9-5202-4a4d-8a03-36fcc5ea0259", "metadata": {}, "source": [ "* Installation" ] }, { "cell_type": "code", "execution_count": null, "id": "a7fd9575-4116-4fa7-86ee-0b2db7417300", "metadata": { "scrolled": true, "tags": [] }, "outputs": [], "source": [ "%cd ~/work/PaddleSeg/Matting\n", "!pip install -r requirements.txt" ] }, { "cell_type": "markdown", "id": "a0dd2390-e635-432b-9e0b-d7c9323f81a9", "metadata": {}, "source": [ "* Quick experience\n", "\n", "Congratulations! Now that you've successfully installed PaddleSeg, let's get a quick feel at human matting." ] }, { "cell_type": "code", "execution_count": null, "id": "81736dd2-e90d-4dac-b3c0-58424e2e8dc4", "metadata": { "scrolled": true, "tags": [] }, "outputs": [], "source": [ "# Download pretrained model\n", "!wget https://paddleseg.bj.bcebos.com/matting/models/ppmatting-hrnet_w18-human_512.pdparams\n", "# Download image\n", "!wget https://user-images.githubusercontent.com/30919197/200645066-6898ec5a-f1c5-4bf7-aa41-473a29977a86.jpeg\n", "# Predicd one image in GPU\n", "!export CUDA_VISIBLE_DEVICES=0\n", "!python tools/predict.py \\\n", " --config configs/ppmatting/ppmatting-hrnet_w18-human_512.yml \\\n", " --model_path ppmatting-hrnet_w18-human_512.pdparams \\\n", " --image_path 200645066-6898ec5a-f1c5-4bf7-aa41-473a29977a86.jpeg \\\n", " --save_dir ./output/results \\\n", " --fg_estimate True" ] }, { "cell_type": "markdown", "id": "3ab60ad4-2908-40e2-9c08-34ac7978ef16", "metadata": {}, "source": [ "An alpha image and a rgba image are generated in the output/results folder.\n", "\n", "\n", "The results are as follows:\n", "