🚀 UPerNet模型卡片
UPerNet是用于图像分割的模型,借助segmentation-models-pytorch
库,能方便地加载预训练模型进行推理。本README将介绍如何加载训练好的模型、模型初始化参数以及使用的数据集等信息。
🚀 快速开始
加载训练好的模型
你可以点击下面的按钮在Colab中运行示例代码:

步骤如下
- 安装所需依赖:
pip install -U segmentation_models_pytorch albumentations
- 运行推理代码:
import torch
import requests
import numpy as np
import albumentations as A
import segmentation_models_pytorch as smp
from PIL import Image
device = "cuda" if torch.cuda.is_available() else "cpu"
checkpoint = "smp-hub/upernet-swin-large"
model = smp.from_pretrained(checkpoint).eval().to(device)
preprocessing = A.Compose.from_pretrained(checkpoint)
url = "https://huggingface.co/datasets/hf-internal-testing/fixtures_ade20k/resolve/main/ADE_val_00000001.jpg"
image = Image.open(requests.get(url, stream=True).raw)
np_image = np.array(image)
normalized_image = preprocessing(image=np_image)["image"]
input_tensor = torch.as_tensor(normalized_image)
input_tensor = input_tensor.permute(2, 0, 1).unsqueeze(0)
input_tensor = input_tensor.to(device)
with torch.no_grad():
output_mask = model(input_tensor)
mask = mask.argmax(1).cpu().numpy()
✨ 主要特性
模型初始化参数
以下是模型初始化时的参数设置:
model_init_params = {
"encoder_name": "tu-swin_large_patch4_window12_384",
"encoder_depth": 5,
"encoder_weights": None,
"decoder_channels": 512,
"decoder_use_norm": "batchnorm",
"in_channels": 3,
"classes": 150,
"activation": None,
"upsampling": 4,
"aux_params": None,
"img_size": 512
}
数据集
本模型使用的数据集是 ADE20K。
📚 详细文档
更多信息
- 库地址:https://github.com/qubvel/segmentation_models.pytorch
- 文档地址:https://smp.readthedocs.io/en/latest/
本模型通过 PytorchModelHubMixin 推送到了模型中心。
📄 许可证
本项目采用 MIT 许可证。