Views
No views yet
1from transformers import ViTImageProcessor, ViTForImageClassification
2from PIL import Image
3
4# Load model and processor
5processor = ViTImageProcessor.from_pretrained("m7kael/yachtmaster-boat-classifier")
6model = ViTForImageClassification.from_pretrained("m7kael/yachtmaster-boat-classifier")
7
8# Load image
9image = Image.open("boat.jpg")
10
11# Process and predict
12inputs = processor(image, return_tensors="pt")
13outputs = model(**inputs)
14logits = outputs.logits
15
16# Get predictions
17predicted_class_idx = logits.argmax(-1).item()
18predicted_class = model.config.id2label[predicted_class_idx]
19print(f"Predicted class: {predicted_class}")1import requests
2
3API_URL = "https://api-inference.huggingface.co/models/m7kael/yachtmaster-boat-classifier"
4headers = {"Authorization": "Bearer YOUR_TOKEN"}
5
6def query(filename):
7 with open(filename, "rb") as f:
8 data = f.read()
9 response = requests.post(API_URL, headers=headers, data=data)
10 return response.json()
11
12# Example
13result = query("boat.jpg")
14print(result)