Downloads · 30 days
307
11% of all-time downloads
smp-hub/segformer-b2-512x512-ade-160k
segformer-b2-512x512-ade-160k is a image segmentation model from smp-hub. Use it for the image segmentation task on the model card, and read the license before you ship it in a product. It is set up for segmentation-models-pytorch. The card lists the license as other.
Table of Contents: - Load trained model - Model init parameters - Model metrics - Dataset
Downloads · 30 days
307
11% of all-time downloads
All-time downloads
2.9K
Public
Parameters
27.5M
110 MB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors110 MB · 100%
From the Hugging Face model README
Table of Contents:
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"
# Load pretrained model and preprocessing function
checkpoint = "smp-hub/segformer-b2-512x512-ade-160k"
model = smp.from_pretrained(checkpoint).eval().to(device)
preprocessing = A.Compose.from_pretrained(checkpoint)
# Load image
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)
# Preprocess image
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) # HWC -> BCHW
input_tensor = input_tensor.to(device)
# Perform inference
with torch.no_grad():
output_mask = model(input_tensor)
# Postprocess mask
mask = torch.nn.functional.interpolate(
output_mask, size=(image.height, image.width), mode="bilinear", align_corners=False
)
mask = mask.argmax(1).cpu().numpy() # argmax over predicted classes (channels dim)
model_init_params = {
"encoder_name": "mit_b2",
"encoder_depth": 5,
"encoder_weights": None,
"decoder_segmentation_channels": 768,
"in_channels": 3,
"classes": 150,
"activation": None,
"aux_params": None
}
Dataset name: ADE20K
This model has been pushed to the Hub using the PytorchModelHubMixin