diegokauer commited on
Commit
9d83fe7
·
1 Parent(s): 959cf76

Update model.py

Browse files
Files changed (1) hide show
  1. model.py +19 -17
model.py CHANGED
@@ -76,23 +76,25 @@ class Model(LabelStudioMLBase):
76
  x, y, x2, y2 = tuple(box)
77
 
78
  if self.id2label[label.item()] == 'Propuesta':
79
- pred_label_id = str(uuid4())
80
- image = image.crop((x.item(), y.item(), x2.item(), y2.item()))
81
- inputs = self.seg_image_processor(images=image, return_tensors="pt")
82
- logits = self.seg_model(**inputs).logits
83
- logits = torch.exp(logits)
84
- preds = logits > 0.5
85
- preds = [self.seg_id2label[i] for i, pred in enumerate(preds)]
86
- preds = ["No Reportado"] if "No Reportado" in preds else preds
87
- result_list.append({
88
- "value": {
89
- "choices": preds
90
- },
91
- "id": pred_label_id,
92
- "from_name": "propuesta",
93
- "to_name": "image",
94
- "type": "choices"
95
- })
 
 
96
 
97
  result_list.append({
98
  'id': label_id,
 
76
  x, y, x2, y2 = tuple(box)
77
 
78
  if self.id2label[label.item()] == 'Propuesta':
79
+ with torch.no_grad():
80
+ pred_label_id = str(uuid4())
81
+ image = image.crop((x.item(), y.item(), x2.item(), y2.item()))
82
+ inputs = self.seg_image_processor(images=image, return_tensors="pt")
83
+ logits = self.seg_model(**inputs).logits
84
+ logits = torch.exp(logits)
85
+ print(logits)
86
+ preds = logits > 0.5
87
+ preds = [self.seg_id2label[i] for i, pred in enumerate(preds)]
88
+ preds = ["No Reportado"] if "No Reportado" in preds else preds
89
+ result_list.append({
90
+ "value": {
91
+ "choices": preds
92
+ },
93
+ "id": pred_label_id,
94
+ "from_name": "propuesta",
95
+ "to_name": "image",
96
+ "type": "choices"
97
+ })
98
 
99
  result_list.append({
100
  'id': label_id,