đ UPerNet Model Card
This UPerNet model is designed for image segmentation tasks. It provides a straightforward way to load a trained model, understand its initialization parameters, and work with a specific dataset.
đ Quick Start
You can quickly start using the UPerNet model by following these steps. Click the button below to open the example in Google Colab:

Installation
First, install the required libraries:
pip install -U segmentation_models_pytorch albumentations
Inference
Then, run the inference code:
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-convnext-xlarge"
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()
⨠Features
- Easy to Use: The model can be easily loaded from a pre - trained checkpoint and used for inference.
- Flexible Initialization: You can customize the model's initialization parameters according to your needs.
đĻ Installation
To install the necessary libraries for this model, run the following command:
pip install -U segmentation_models_pytorch albumentations
đģ Usage Examples
Basic Usage
The above quick - start code shows the basic usage of loading a pre - trained model, preprocessing an image, performing inference, and post - processing the output mask.
Advanced Usage
You can customize the model's initialization parameters to adapt to different tasks. Here is an example of model initialization parameters:
model_init_params = {
"encoder_name": "tu-convnext_xlarge",
"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
}
đ Documentation
Model Init Parameters
The following are the parameters for initializing the model:
model_init_params = {
"encoder_name": "tu-convnext_xlarge",
"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
}
Dataset
The model uses the ADE20K dataset.
More Information
- Library: https://github.com/qubvel/segmentation_models.pytorch
- Docs: https://smp.readthedocs.io/en/latest/
This model has been pushed to the Hub using the PytorchModelHubMixin
đ License
This project is licensed under the MIT license.