Image Classification
Transformers
Safetensors
swin_b
generative-ai
medical-imaging
swin-transformer
breast-cancer
classification
Instructions to use keanteng/swin-v1-breast-cancer-classification-0716 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use keanteng/swin-v1-breast-cancer-classification-0716 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-classification", model="keanteng/swin-v1-breast-cancer-classification-0716") pipe("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/parrots.png")# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("keanteng/swin-v1-breast-cancer-classification-0716", device_map="auto") - Notebooks
- Google Colab
- Kaggle
| license: agpl-3.0 | |
| datasets: | |
| - keanteng/miniddbs-jpeg | |
| base_model: | |
| - microsoft/swin-base-patch4-window8-256 | |
| pipeline_tag: image-classification | |
| library_name: transformers | |
| tags: | |
| - generative-ai | |
| - medical-imaging | |
| - swin-transformer | |
| - breast-cancer | |
| - classification | |
| # Breast Cancer Classification with Swin Transformer | |
| > This is a new version trained with some pipelines and parameters modification. | |
| This repository contains a fine-tuned Swin Transformer model for breast cancer classification based on mammography images. | |
| Due to the indistinguishable nature of the dataset various runs had been conducted to perform the original 3 classes classification according to the original DDSM dataset but the accuracy obtained is dismal (approx 67%) contrary to literature review of (>90%). | |
| I have also explored dual input Swin Transformer using the Tumour Mask, however, similar dismal accuracy is obtained. We can look at the dataset and notice that the images all looks about the same except Normal. Thus, the detection strategy becomes detecting the presence of cancer by merging to Benign and Cancer images as a class against the Normal images. | |
| With such approach, accuracy significant increases and achieve reliable performance. | |
| ## Model Description | |
| The model is based on the [Swin Transformer Base](https://huggingface.co/microsoft/swinv2-base-patch4-window8-256) architecture, fine-tuned on the [Mini-DDBS-JPEG](https://huggingface.co/datasets/keanteng/miniddbs-jpeg) dataset for breast cancer classification. It uses a custom classification head consisting of a multi-layer perceptron with dropout for regularization. | |
| ### Key Features | |
| - Based on Swin Transformer architecture | |
| - Input image size: 256x256 pixels | |
| - Binary classification task (malignant vs benign) | |
| - Mixed precision training for improved performance | |
| ## Performance | |
| The model was trained with class balancing techniques to handle data imbalance. Performance metrics on the test set: | |
| | Metric | Value | | |
| |--------|-------| | |
| | Test Accuracy | 0.7365728900255755 | | |
| | Test Loss | 0.48903981148434417 | | |
| For detailed performance metrics including precision, recall, and F1-score per class, please check the [training notebook](https://github.com/keanteng/wqd7025). | |
| ## Usage | |
| ### With Transformers Pipeline | |
| ```python | |
| from transformers import pipeline | |
| classifier = pipeline("image-classification", model="keanteng/swin_v1_breast_cancer_classification-0716") | |
| result = classifier("path/to/mammogram.jpg") | |
| print(result) | |
| ``` | |
| ``` | |
| from transformers import AutoFeatureExtractor, AutoModelForImageClassification | |
| from PIL import Image | |
| # Load model and feature extractor | |
| model = AutoModelForImageClassification.from_pretrained("keanteng/swin_v1_breast_cancer_classification-0716") | |
| feature_extractor = AutoFeatureExtractor.from_pretrained("keanteng/swin_v1_breast_cancer_classification-0716") | |
| # Prepare image | |
| image = Image.open("path/to/mammogram.jpg").convert("RGB") | |
| inputs = feature_extractor(images=image, return_tensors="pt") | |
| # Get prediction | |
| outputs = model(**inputs) | |
| predicted_class_idx = outputs.logits.argmax(-1).item() | |
| print(f"Predicted class: model.config.id2label[predicted_class_idx]") | |
| ``` | |