Image Segmentation
Transformers
Safetensors
metpredict_dpt
feature-extraction
pathology
dpt
custom_code
Instructions to use RendeiroLab/MetPredict-lung-structure-segmentation with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use RendeiroLab/MetPredict-lung-structure-segmentation with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-segmentation", model="RendeiroLab/MetPredict-lung-structure-segmentation", trust_remote_code=True)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("RendeiroLab/MetPredict-lung-structure-segmentation", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
| library_name: transformers | |
| tags: | |
| - image-segmentation | |
| - pathology | |
| - dpt | |
| pipeline_tag: image-segmentation | |
| # Lung structures Segmentation (DPT) | |
| Pathology segmentation for lung structures (blood vessels and airways). | |
| - Encoder (freezed): H-optimus-0 ViT backbone (pretrained on histopathology data). | |
| - Decoder (trained): custom DPT head with multi-scale feature fusion. | |
| ## Usage | |
| The model expects a normalized `(B, 3, H, W)` float tensor as `pixel_values`. | |
| Use ImageNet mean/std — same stats applied at training time (matches the | |
| H-optimus-0 backbone's expected input distribution). | |
| Input image: 224x224 @ 1.5 MPP | |
| ```python | |
| import numpy as np | |
| import torch | |
| from PIL import Image | |
| from torchvision.transforms import ToTensor, Normalize, Resize, Compose | |
| from transformers import AutoModel | |
| model = AutoModel.from_pretrained("RendeiroLab/MetPredict-lung-structure-segmentation", trust_remote_code=True).eval() | |
| device = next(model.parameters()).device | |
| transform = Compose([ | |
| ToTensor(), | |
| Resize((224, 224)), | |
| Normalize( | |
| mean=[0.485, 0.456, 0.406], | |
| std=[0.229, 0.224, 0.225] | |
| ), | |
| ]) | |
| img = Image.open("tile.png").convert("RGB") | |
| x = transform(img) | |
| pixel_values = x.unsqueeze(0).to(device) | |
| with torch.inference_mode(): | |
| out = model(pixel_values) | |
| logits = out.logits # (1, n_classes, H, W) | |
| pred = logits.argmax(dim=1) # (1, H, W) | |
| ``` | |