Views
No views yet
pip install transformers torch1from transformers import AutoImageProcessor
2from PIL import Image
3
4# Load the processor
5processor = AutoImageProcessor.from_pretrained("iszt/eye-clahe-processor", trust_remote_code=True)
6
7# Process a single image
8image = Image.open("fundus_image.jpg")
9outputs = processor(image, return_tensors="pt")
10pixel_values = outputs["pixel_values"] # Shape: (1, 3, 512, 512)
11
12# Process on GPU
13outputs = processor(image, return_tensors="pt", device="cuda")1import torch
2from PIL import Image
3
4# Load multiple images
5images = [Image.open(f"image_{i}.jpg") for i in range(8)]
6
7# Process batch
8outputs = processor(images, return_tensors="pt", device="cuda")
9pixel_values = outputs["pixel_values"] # Shape: (8, 3, 512, 512)1import torch
2
3# Tensor input: (B, C, H, W) or (C, H, W)
4images = torch.rand(4, 3, 512, 512) # Batch of 4 images
5
6outputs = processor(images, return_tensors="pt")| Parameter | Default | Description |
|---|---|---|
size | 512 | Output image size (square) |
do_crop | true | Enable eye-centered cropping |
do_clahe | true | Enable CLAHE contrast enhancement |
crop_scale_factor | 1.1 | Padding around detected eye region |
clahe_grid_size | 8 | CLAHE tile grid size |
clahe_clip_limit | 2.0 | CLAHE histogram clip limit |
normalization_mode | "imagenet" | Normalization: "imagenet", "none", or "custom" |
min_radius_frac | 0.1 | Minimum eye radius as fraction of image |
max_radius_frac | 0.9 | Maximum eye radius as fraction of image |
allow_overflow | true | Allow crop box beyond image bounds (fills with black) |
softmax_temperature | 0.3 | Temperature for eye center detection (higher = smoother) |
1from transformers import AutoImageProcessor
2
3processor = AutoImageProcessor.from_pretrained(
4 "iszt/eye-clahe-processor",
5 trust_remote_code=True,
6 size=384,
7 normalization_mode="imagenet",
8 clahe_clip_limit=3.0,
9 softmax_temperature=0.3,
10)1from transformers import AutoImageProcessor, AutoModel
2from PIL import Image
3
4# Load processor and model
5processor = AutoImageProcessor.from_pretrained("iszt/eye-clahe-processor", trust_remote_code=True)
6model = AutoModel.from_pretrained("google/vit-base-patch16-224")
7
8# Process and run inference
9image = Image.open("fundus.jpg")
10inputs = processor(image, return_tensors="pt", device="cuda")
11
12# Update normalization for pretrained models
13inputs["pixel_values"] = (inputs["pixel_values"] - torch.tensor([0.485, 0.456, 0.406]).view(1,3,1,1).cuda()) / torch.tensor([0.229, 0.224, 0.225]).view(1,3,1,1).cuda()
14
15with torch.no_grad():
16 outputs = model(**inputs)scale_x, scale_y: Scale factors for coordinate mapping (shape: (B,))offset_x, offset_y: Offset values for coordinate mapping (shape: (B,))1orig_x = offset_x + cropped_x * scale_x
2orig_y = offset_y + cropped_y * scale_ycropped_x and cropped_y are coordinates in the processed image (range: [0, size-1]).1from PIL import Image
2
3# Process image
4processor = AutoImageProcessor.from_pretrained("iszt/eye-clahe-processor", trust_remote_code=True)
5image = Image.open("fundus.jpg")
6outputs = processor(image, return_tensors="pt")
7
8# Detected point in processed image (e.g., from a model prediction)
9detected_x, detected_y = 100.0, 150.0
10
11# Map back to original image coordinates
12orig_x = outputs['offset_x'] + detected_x * outputs['scale_x']
13orig_y = outputs['offset_y'] + detected_y * outputs['scale_y']
14
15print(f"Original coordinates: ({orig_x.item():.2f}, {orig_y.item():.2f})")1import torch
2
3# Process batch of images
4images = [Image.open(f"image_{i}.jpg") for i in range(4)]
5outputs = processor(images, return_tensors="pt")
6
7# Detected points for each image (B, N, 2) where N is number of points
8detected_points = torch.tensor([
9 [[50.0, 60.0], [100.0, 120.0]], # Image 0: 2 points
10 [[75.0, 80.0], [150.0, 160.0]], # Image 1: 2 points
11 [[90.0, 95.0], [180.0, 190.0]], # Image 2: 2 points
12 [[65.0, 70.0], [130.0, 140.0]], # Image 3: 2 points
13])
14
15# Map all points back to original coordinates
16B, N, _ = detected_points.shape
17scale_x = outputs['scale_x'].view(B, 1, 1)
18scale_y = outputs['scale_y'].view(B, 1, 1)
19offset_x = outputs['offset_x'].view(B, 1, 1)
20offset_y = outputs['offset_y'].view(B, 1, 1)
21
22orig_x = offset_x + detected_points[..., 0:1] * scale_x
23orig_y = offset_y + detected_points[..., 1:2] * scale_y
24
25original_points = torch.cat([orig_x, orig_y], dim=-1) # (B, N, 2)1@software{eye_clahe_processor,
2 title={EyeCLAHEImageProcessor: GPU-Native Fundus Image Preprocessing},
3 year={2026},
4 url={https://huggingface.co/iszt/eye-clahe-processor}
5}