Spaces:
Sleeping
Sleeping
Update inference.py
Browse files- inference.py +3 -11
inference.py
CHANGED
@@ -24,16 +24,8 @@ def prediction(image):
|
|
24 |
offset_mapping = encoding.pop('offset_mapping')
|
25 |
|
26 |
# Esegui l'inferenza con il modello fine-tuned
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
# Ottieni le etichette previste dal modello
|
31 |
-
logits = outputs.logits
|
32 |
-
predicted_ids = logits.argmax(-1).squeeze().tolist()
|
33 |
-
|
34 |
-
# Mappa gli ID predetti nelle etichette di classificazione
|
35 |
-
labels = processor.tokenizer.convert_ids_to_tokens(predicted_ids)
|
36 |
-
|
37 |
predictions = outputs.logits.argmax(-1).squeeze().tolist()
|
38 |
token_boxes = encoding.bbox.squeeze().tolist()
|
39 |
probabilities = torch.softmax(outputs.logits, dim=-1)
|
@@ -77,7 +69,7 @@ def prediction(image):
|
|
77 |
draw = ImageDraw.Draw(image, "RGBA")
|
78 |
font = ImageFont.load_default()
|
79 |
|
80 |
-
for prediction, box, confidence in zip(
|
81 |
draw.rectangle(box)
|
82 |
draw.text((box[0]+10, box[1]-10), text=str(prediction)+ ", "+ str(confidence), font=font, fill="black", font_size="15")
|
83 |
|
|
|
24 |
offset_mapping = encoding.pop('offset_mapping')
|
25 |
|
26 |
# Esegui l'inferenza con il modello fine-tuned
|
27 |
+
outputs = model(**encoding)
|
28 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
predictions = outputs.logits.argmax(-1).squeeze().tolist()
|
30 |
token_boxes = encoding.bbox.squeeze().tolist()
|
31 |
probabilities = torch.softmax(outputs.logits, dim=-1)
|
|
|
69 |
draw = ImageDraw.Draw(image, "RGBA")
|
70 |
font = ImageFont.load_default()
|
71 |
|
72 |
+
for prediction, box, confidence in zip(true_predictions, token_boxes, confidence_scores):
|
73 |
draw.rectangle(box)
|
74 |
draw.text((box[0]+10, box[1]-10), text=str(prediction)+ ", "+ str(confidence), font=font, fill="black", font_size="15")
|
75 |
|