đ Segmentation-Models-PyTorch: DPT Model
This is a PyTorch-based image segmentation model, which can effectively perform semantic segmentation tasks on images.
đ Quick Start
Load trained model
You can load the trained model by following these steps. Click the button below to open the example in Google Colab:

- Install requirements.
pip install -U segmentation_models_pytorch albumentations
- Run inference.
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/dpt-large-ade20k"
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 = torch.nn.functional.interpolate(
output_mask, size=(image.height, image.width), mode="bilinear", align_corners=False
)
mask = mask.argmax(1).cpu().numpy()
đģ Usage Examples
Basic Usage
The above code example demonstrates the basic steps for loading and running inference on a trained model.
Advanced Usage
You can adjust the model initialization parameters according to your needs to achieve more advanced usage.
đ§ Technical Details
Model init parameters
model_init_params = {
"encoder_name": "tu-vit_large_patch16_384",
"encoder_depth": 4,
"encoder_weights": None,
"encoder_output_indices": None,
"decoder_intermediate_channels": (256, 512, 1024, 1024),
"decoder_fusion_channels": 256,
"dynamic_img_size": True,
"in_channels": 3,
"classes": 150,
"activation": None,
"aux_params": None
}
đ Documentation
Dataset
Dataset name: ADE20K
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.