Views
No views yet
1import requests
2from PIL import Image
3import io
4
5API_URL = "https://api-inference.huggingface.co/models/bsustersic/wood-identifier-resnet18"
6headers = {"Authorization": "Bearer YOUR_HF_TOKEN"}
7
8def identify_wood(image_path):
9 with open(image_path, "rb") as f:
10 data = f.read()
11 response = requests.post(API_URL, headers=headers, data=data)
12 return response.json()
13
14# Example usage
15predictions = identify_wood("wood_sample.jpg")
16print(predictions)1from transformers import AutoImageProcessor, AutoModelForImageClassification
2from PIL import Image
3
4processor = AutoImageProcessor.from_pretrained("bsustersic/wood-identifier-resnet18")
5model = AutoModelForImageClassification.from_pretrained("bsustersic/wood-identifier-resnet18")
6
7image = Image.open("wood_sample.jpg")
8inputs = processor(image, return_tensors="pt")
9outputs = model(**inputs)
10predictions = outputs.logits.softmax(dim=1)
11
12# Get top prediction
13predicted_class = predictions.argmax().item()
14confidence = predictions[0][predicted_class].item()
15print(f"Predicted: {model.config.id2label[predicted_class]} ({confidence:.2%})")