YAML Metadata Warning:empty or missing yaml metadata in repo card

Check out the documentation for more information.

AMD Classifier Model

This repository contains an AMD classifier model based on EfficientNet-B4. The model is designed to detect Age-related Macular Degeneration (AMD) using preprocessed retinal fundus images. The architecture has been fine-tuned on a custom dataset using various data augmentation techniques and preprocessing steps.

Model Details

  • Architecture: EfficientNet-B4 (modified for binary classification)
  • Pretrained: Yes, with additional fine-tuning
  • Input: Preprocessed retinal fundus images (size: 380x380)
  • Output: Binary prediction indicating presence (1) or absence (0) of AMD

Training Details

  • Framework: PyTorch
  • Optimizer: Adam
  • Loss Function: BCEWithLogitsLoss (with positive weight adjustment)
  • Data Augmentation: Includes zooming, rotation, flipping, brightness/contrast adjustment, gamma correction, noise and blur augmentations.
  • Training Data: Processed tensors from multiple curated datasets (AMD, AMDNet23, ODIR 5K)

Intended Use

This model is intended for research and educational purposes to assist in the early detection of AMD from retinal images. It is not a certified diagnostic tool and should be used only for non-clinical applications.

Evaluation Metrics

The evaluation of the model on several datasets yielded the following metrics (examples):

  • Training Loss: 0.1100
  • Validation Loss: 0.1029
  • Sensitivity: 0.9711
  • Specificity: 0.9633
  • Validation AUC: 0.9963
  • Precision: 0.9439

Performance may vary when applied to different datasets, especially those with domain shifts from training data.

Limitations

  • The model has been primarily trained on curated retinal images. Its performance on images from different populations or imaging devices may vary.
  • Augmentation techniques were applied extensively, which might introduce artifacts.
  • The model should be used as a supplementary tool and not a standalone diagnostic solution.

How to Use

Inference Example

AMD Classifier Model

This repository contains an AMD classifier model based on EfficientNet-B4. The model is designed to detect Age-related Macular Degeneration (AMD) from retinal fundus images. The architecture has been fine-tuned on a custom dataset with extensive preprocessing and augmentation techniques.

Preprocessing

A custom preprocessing function, preprocess_fundus, was developed specifically to handle the challenges associated with fundus images. This function performs the following steps:

  • Converts images to a uniform RGB format.
  • Removes black borders using an intensity threshold.
  • Resizes images to 380×380.
  • Optionally enhances contrast via CLAHE and a weighted blending with a Gaussian blurred version of the image.

Below is the implementation of the function:

def preprocess_fundus(
    image: Union[np.ndarray, Image.Image],
    target_size: Tuple[int, int] = (380, 380),
    enhance_contrast: bool = True,
) -> np.ndarray:
    """
    Preprocess fundus images for AMD detection.

    Args:
        image: Input image (numpy array or PIL Image)
        target_size: Target size for resizing (default: 380x380)
        enhance_contrast: Whether to apply contrast enhancement

    Returns:
        Preprocessed image as numpy array
    """
    # Convert PIL Image to numpy array if needed
    if isinstance(image, Image.Image):
        image = np.array(image)

    # Ensure RGB format
    if len(image.shape) == 2:  # Grayscale to RGB
        image = np.stack((image,) * 3, axis=-1)
    elif image.shape[2] == 4:  # RGBA to RGB
        image = image[:, :, :3]

    # Convert BGR to RGB if needed
    if image.dtype == np.uint8 and len(image.shape) == 3:
        image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

    # Crop black borders using intensity threshold
    def crop_black_borders(img, threshold=10):
        mask = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY) > threshold
        coords = np.argwhere(mask)
        x_min, y_min = coords.min(axis=0)
        x_max, y_max = coords.max(axis=0)
        return img[x_min:x_max, y_min:y_max]

    image = crop_black_borders(image)

    # Resize to target size
    image = cv2.resize(image, target_size, interpolation=cv2.INTER_LANCZOS4)

    if enhance_contrast:
        # Apply CLAHE (Contrast Limited Adaptive Histogram Equalization)
        lab = cv2.cvtColor(image, cv2.COLOR_RGB2LAB)
        clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8, 8))
        lab[..., 0] = clahe.apply(lab[..., 0])
        image = cv2.cvtColor(lab, cv2.COLOR_LAB2RGB)

        # Add weighted combination for local contrast enhancement
        gaussian_blurred = cv2.GaussianBlur(image, (0, 0), 10)
        image = cv2.addWeighted(image, 4, gaussian_blurred, -4, 128)

    # Ensure proper value range and data type
    image = np.clip(image, 0, 255)
    image = image.astype(np.uint8)

    return image

# Example prediction
image_path = "path_to_your_fundus_image.jpg"
image = preprocess_fundus(image_path)
image = transform(image).unsqueeze(0).to(device)

with torch.no_grad():
    output = model(image)
    prediction = (output > 0.5).float()
    print("Prediction:", prediction.item())

Citation

If you use this model in your work, please cite it as:

@misc{AMDClassifier2025,
  author = {Varun Patani},
  title = {AMD Classifier Model based on EfficientNet-B4},
  year = {2025},
  howpublished = {\\url{}},
}

License

MIT License

Copyright (c) 2025 Your Name

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

Acknowledgments

  • Thanks to the contributors in the field of retinal imaging.
  • Leveraged PyTorch and torchvision libraries for feature extraction and model training.

This model card is provided as-is for research and educational purposes.

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support