Views
No views yet
1from transformers import AutoImageProcessor, AutoModelForImageClassification
2from PIL import Image
3
4# Load model and processor
5processor = AutoImageProcessor.from_pretrained("SIATCN/vit_tumor_classifier")
6model = AutoModelForImageClassification.from_pretrained("SIATCN/vit_tumor_classifier")
7
8# Load and process image
9image = Image.open("path_to_your_image.jpg")
10inputs = processor(image, return_tensors="pt")
11
12# Make prediction
13outputs = model(**inputs)
14predictions = outputs.logits.softmax(dim=-1)
15predicted_label = predictions.argmax().item()
16confidence = predictions[0][predicted_label].item()
17
18# Get class name
19class_names = ["non-tumor", "tumor"]
20print(f"Predicted: {class_names[predicted_label]} (confidence: {confidence:.2f})")