Downloads · 30 days
0
PranayPalem/BYOL_Mammogram
BYOL_Mammogram is a image classification model from PranayPalem. Use it when you need a label for an image. It is set up for pytorch. The card lists the license as mit.
A self-supervised learning model for mammogram analysis using Bootstrap Your Own Latent (BYOL) pre-training with ResNet50 backbone.
Downloads · 30 days
0
Access
Public
Updated Sep 18, 2025
Repo size
1.1 GB
Likes
0
Public
Click a slice to open those files.
.pth1.1 GB · 100%
From the Hugging Face model README
A self-supervised learning model for mammogram analysis using Bootstrap Your Own Latent (BYOL) pre-training with ResNet50 backbone.
This model implements BYOL (Bootstrap Your Own Latent) self-supervised pre-training on mammogram breast tissue tiles, followed by fine-tuning for classification tasks. The model is designed specifically for medical imaging applications with aggressive background rejection and intelligent tissue segmentation.
import torch
from train_byol_mammo import MammogramBYOL
from torchvision import models
import torch.nn as nn
# Load the pre-trained BYOL model
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
# Create ResNet50 backbone
resnet = models.resnet50(weights=None)
backbone = nn.Sequential(*list(resnet.children())[:-1])
# Initialize BYOL model
model = MammogramBYOL(
backbone=backbone,
input_dim=2048,
hidden_dim=4096,
proj_dim=256
).to(device)
# Load pre-trained weights
checkpoint = torch.load('mammogram_byol_best.pth', map_location=device)
model.load_state_dict(checkpoint['model_state_dict'])
model.eval()
# Extract features from mammogram tiles
def extract_features(image_tensor):
with torch.no_grad():
features = model.get_features(image_tensor)
return features
# Example usage
image = torch.randn(1, 3, 512, 512).to(device) # Example input
features = extract_features(image) # Returns 2048-dim features
Use the provided train_classification.py script for downstream classification tasks:
python train_classification.py \
--byol_checkpoint ./mammogram_byol_best.pth \
--train_csv ./train_labels.csv \
--val_csv ./val_labels.csv \
--tiles_dir ./tiles/ \
--output_dir ./classification_results/
BYOL_Mammogram/
├── mammogram_byol_best.pth # Best BYOL checkpoint
├── mammogram_byol_final.pth # Final BYOL checkpoint
├── train_byol_mammo.py # BYOL pre-training script
├── train_classification.py # Classification fine-tuning
├── inference_classification.py # Inference script
├── classification_config.json # Classification configuration
├── CLASSIFICATION_GUIDE.md # Detailed training guide
└── requirements.txt # Dependencies
torch>=2.0.0
torchvision>=0.15.0
lightly>=1.4.0
opencv-python>=4.8.0
scipy>=1.10.0
numpy>=1.24.0
Pillow>=9.5.0
tqdm>=4.65.0
If you use this model in your research, please cite:
@model{byol_mammogram_2024,
title={BYOL Mammogram Classification Model},
author={PranayPalem},
year={2024},
url={https://huggingface.co/PranayPalem/BYOL_Mammogram}
}
MIT License - See LICENSE file for details.
This model is for research purposes only and should not be used for clinical diagnosis without proper validation and medical supervision. Always consult healthcare professionals for medical decisions.