mp-02 commited on
Commit
0326abd
·
verified ·
1 Parent(s): 0453cbe

Update inference.py

Browse files
Files changed (1) hide show
  1. 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
- with torch.no_grad():
28
- outputs = model(**encoding)
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(predictions, token_boxes, confidence_scores):
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