diegokauer commited on
Commit
0e19682
1 Parent(s): ccf2cde

Update model.py

Browse files
Files changed (1) hide show
  1. model.py +20 -23
model.py CHANGED
@@ -36,35 +36,32 @@ class Model(LabelStudioMLBase):
36
  original_width, original_height = image.size
37
  with torch.no_grad():
38
 
39
- inputs = image_processor(images=image, return_tensors="pt")
40
- outputs = model(**inputs)
41
  target_sizes = torch.tensor([image.size[::-1]])
42
- results = image_processor.post_process_object_detection(outputs, threshold=0.5, target_sizes=target_sizes)[0]
43
 
44
  result_list = []
45
- for score, label, box in zip(results['scores'], results['labels'], scores['boxes']):
46
  label_id = str(uuid4())[:4]
47
  x, y, x2, y2 = tuple(box)
48
- result_list.append(
49
- {
50
- 'id': id,
51
- 'original_width': original_width,
52
- 'original_height': original_height,
53
- 'from_name': "label",
54
- 'to_name': "image",
55
- 'type': 'labels',
56
- 'score': score, # per-region score, visible in the editor
57
- 'value': {
58
- 'x': x,
59
- 'y': y,
60
- 'width': x2-x,
61
- 'height': y2-y,
62
- 'rotation': 0
63
- 'labels': [self.id2label[label]]
64
- }
65
  }
66
- )
67
-
68
 
69
  predictions.append({
70
  'score': results['scores'].mean(), # prediction overall score, visible in the data manager columns
 
36
  original_width, original_height = image.size
37
  with torch.no_grad():
38
 
39
+ inputs = self.image_processor(images=image, return_tensors="pt")
40
+ outputs = self.model(**inputs)
41
  target_sizes = torch.tensor([image.size[::-1]])
42
+ results = self.image_processor.post_process_object_detection(outputs, threshold=0.5, target_sizes=target_sizes)[0]
43
 
44
  result_list = []
45
+ for score, label, box in zip(results['scores'], results['labels'], results['boxes']):
46
  label_id = str(uuid4())[:4]
47
  x, y, x2, y2 = tuple(box)
48
+ result_list.append({
49
+ 'id': label_id,
50
+ 'original_width': original_width,
51
+ 'original_height': original_height,
52
+ 'from_name': "label",
53
+ 'to_name': "image",
54
+ 'type': 'labels',
55
+ 'score': score, # per-region score, visible in the editor
56
+ 'value': {
57
+ 'x': x,
58
+ 'y': y,
59
+ 'width': x2-x,
60
+ 'height': y2-y,
61
+ 'rotation': 0,
62
+ 'labels': [self.id2label[label]]
 
 
63
  }
64
+ })
 
65
 
66
  predictions.append({
67
  'score': results['scores'].mean(), # prediction overall score, visible in the data manager columns