Downloads · 30 days
66
23% of all-time downloads
sukhmani1303/lung-cancer-vit-model
lung-cancer-vit-model is a machine learning model from sukhmani1303. Use it for the machine learning task on the model card, and read the license before you ship it in a product. The card lists the license as mit.
Classifies lung CT images as Normal or Cancer using a Vision Transformer (ViT).
Downloads · 30 days
66
23% of all-time downloads
All-time downloads
282
Public
Repo size
1 GB
Likes
0
Public
Click a slice to open those files.
.bin343 MB · 100%
From the Hugging Face model README
Classifies lung CT images as Normal or Cancer using a Vision Transformer (ViT).
timm.vit_base_patch16_224, fine-tunedreport.txt and classification_report.txt)import torch
import timm
import cv2
import numpy as np
# Load model
model = timm.create_model('vit_base_patch16_224', pretrained=False, num_classes=2)
model.load_state_dict(torch.load('pytorch_model.bin'))
model.eval()
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
model.to(device)
# Preprocess image
img = cv2.imread('path_to_image.jpg')
img = cv2.resize(img, (224, 224))
img = img.astype(np.float32) / 255.0
img = torch.tensor(img).permute(2, 0, 1).unsqueeze(0).to(device)
# Predict
with torch.no_grad():
outputs = model(img)
probs = torch.softmax(outputs, dim=1)
predicted_idx = outputs.max(1)[1].item()
class_names = ['Cancer', 'Normal']
confidence = probs[0][predicted_idx].item()
print(f'Classified as: {class_names[predicted_idx]}, Confidence: {confidence:.4f}')
pytorch_model.bin: Model weightsconfig.json: Model configurationreport.txt: Comprehensive training reportclassification_report.txt: Test set classification metricsconfusion_matrix.png: Confusion matrix plotroc_curve.png: ROC curve with AUCtraining_plots.png: Training loss and validation accuracy plotsSee report.txt and classification_report.txt for details on dataset, hyperparameters, and performance.
For educational purposes only. Consult healthcare professionals for diagnosis.
Try the model interactively at Hugging Face Space.