beingamit99 commited on
Commit
1059070
·
1 Parent(s): 20180c2

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +21 -0
README.md ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ from PIL import Image
3
+ # Load model directly
4
+ from transformers import AutoImageProcessor, AutoModelForImageClassification
5
+
6
+ processor = AutoImageProcessor.from_pretrained("beingamit99/car_damage_detection")
7
+ model = AutoModelForImageClassification.from_pretrained("beingamit99/car_damage_detection")
8
+ image = Image.open(IMAGE)
9
+ inputs = processor(images=image, return_tensors="pt")
10
+ outputs = model(**inputs)
11
+ logits = outputs.logits.detach().cpu().numpy()
12
+
13
+ # Get the most likely class and its probability
14
+ predicted_class_id = np.argmax(logits)
15
+ predicted_proba = np.max(logits)
16
+
17
+ # Get the class name from the model's label map
18
+ label_map = model.config.id2label
19
+ predicted_class_name = label_map[predicted_class_id]
20
+
21
+ print(f"Predicted class: {predicted_class_name} (probability: {predicted_proba:.4f})")