Views
No views yet
1import numpy as np
2from PIL import Image
3from transformers import AutoImageProcessor, AutoModelForImageClassification
4
5# Load the model and image processor
6processor = AutoImageProcessor.from_pretrained("beingamit99/car_damage_detection")
7model = AutoModelForImageClassification.from_pretrained("beingamit99/car_damage_detection")
8
9# Load and process the image
10image = Image.open(IMAGE)
11inputs = processor(images=image, return_tensors="pt")
12
13# Make predictions
14outputs = model(**inputs)
15logits = outputs.logits.detach().cpu().numpy()
16predicted_class_id = np.argmax(logits)
17predicted_proba = np.max(logits)
18label_map = model.config.id2label
19predicted_class_name = label_map[predicted_class_id]
20
21# Print the results
22print(f"Predicted class: {predicted_class_name} (probability: {predicted_proba:.4f}")1from transformers import pipeline
2#Create a classification pipeline
3pipe = pipeline("image-classification", model="beingamit99/car_damage_detection")
4pipe(IMAGE)