Transformers
ONNX
Safetensors
swinv2_segmenter
retinal-fundus
artery-vein-segmentation
medical-imaging
ophthalmology
swinv2
custom_code
Instructions to use JonathanFhima/RLAD-SwinV2-Large with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use JonathanFhima/RLAD-SwinV2-Large with Transformers:
# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("JonathanFhima/RLAD-SwinV2-Large", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Add Swinv2SegmenterImageProcessor (standard BaseImageProcessor) - verified bit-identical output to the old manual preprocess_image
a627c2e verified Download image_processing_lunetv2.py from JonathanFhima/RLAD-SwinV2-Large: direct link, hf CLI and curl.
- Browser
- Download file 1.1 kB
-
https://huggingface.co/JonathanFhima/RLAD-SwinV2-Large/resolve/main/image_processing_lunetv2.py
- Command line
-
hf download hf://JonathanFhima/RLAD-SwinV2-Large/image_processing_lunetv2.py
-
curl -L -o image_processing_lunetv2.py https://huggingface.co/JonathanFhima/RLAD-SwinV2-Large/resolve/main/image_processing_lunetv2.py
1.1 kB
| import torch | |
| from PIL import Image | |
| from torchvision import transforms | |
| from transformers.image_processing_utils import BaseImageProcessor, BatchFeature | |
| MODEL_CONTENT_SIZE = 1444 | |
| MODEL_PADDED_SIZE = 1472 | |
| PAD = (MODEL_PADDED_SIZE - MODEL_CONTENT_SIZE) // 2 | |
| class Swinv2SegmenterImageProcessor(BaseImageProcessor): | |
| model_input_names = ["pixel_values"] | |
| def preprocess(self, images, return_tensors=None, **kwargs): | |
| """Resize to 1444x1444, ImageNet-normalize, zero-pad to 1472x1472.""" | |
| if isinstance(images, Image.Image): | |
| images = [images] | |
| pixel_values = [] | |
| for image in images: | |
| resized = image.resize((MODEL_CONTENT_SIZE, MODEL_CONTENT_SIZE)) | |
| tensor = transforms.ToTensor()(resized)[:3] | |
| tensor = transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])(tensor) | |
| tensor = torch.nn.functional.pad(tensor, (PAD, PAD, PAD, PAD), value=0) | |
| pixel_values.append(tensor) | |
| return BatchFeature(data={"pixel_values": torch.stack(pixel_values)}, tensor_type=return_tensors) | |