Views
No views yet
1from transformers import pipeline
2
3# Specify the model you want to use
4model_name = "amaye15/ViT-Standford-Dogs" # Example: Vision Transformer
5
6# Load the image classification pipeline with the specified model
7image_classifier = pipeline("image-classification", model=model_name)
8
9# Path or URL to your image
10image_path_or_url = "path_or_url_to_your_image"
11
12# Get predictions
13predictions = image_classifier(image_path_or_url)
14
15# Define the number of top predictions you want to see (top k)
16top_k = 5
17
18# Print the top k predictions
19for prediction in predictions[:top_k]:
20 print(f"Class: {prediction['label']}, Confidence: {prediction['score']:.2f}")