Inference Endpoints
Vishakaraj commited on
Commit
4ac2cad
1 Parent(s): 24b8876

Update handler.py

Browse files
Files changed (1) hide show
  1. handler.py +31 -31
handler.py CHANGED
@@ -71,36 +71,36 @@ class EndpointHandler:
71
  pass
72
 
73
 
74
- def __call__(self, image_file):
75
- image_array = np.array(image_file)[:, :, ::-1] # BGR
76
- predictions, visualized_output = dense_captioning_demo.run_on_image(image_array)
77
- buffer = BytesIO()
78
- visualized_output.fig.savefig(buffer, format="png")
79
- buffer.seek(0)
80
- detections = {}
81
- predictions = predictions["instances"].to(torch.device("cpu"))
82
-
83
- for box, description, score in zip(
84
- predictions.pred_boxes,
85
- predictions.pred_object_descriptions.data,
86
- predictions.scores,
87
- ):
88
- if description not in detections:
89
- detections[description] = []
90
- detections[description].append(
91
- {
92
- "xmin": float(box[0]),
93
- "ymin": float(box[1]),
94
- "xmax": float(box[2]),
95
- "ymax": float(box[3]),
96
- "score": float(score),
 
 
 
 
 
 
97
  }
98
- )
99
-
100
- output = {
101
- "dense_captioning_results": {
102
- "detections": detections,
103
  }
104
- }
105
-
106
- return Image.open(buffer), output
 
71
  pass
72
 
73
 
74
+ def __call__(self, image_file):
75
+ image_array = np.array(image_file)[:, :, ::-1] # BGR
76
+ predictions, visualized_output = dense_captioning_demo.run_on_image(image_array)
77
+ buffer = BytesIO()
78
+ visualized_output.fig.savefig(buffer, format="png")
79
+ buffer.seek(0)
80
+ detections = {}
81
+ predictions = predictions["instances"].to(torch.device("cpu"))
82
+
83
+ for box, description, score in zip(
84
+ predictions.pred_boxes,
85
+ predictions.pred_object_descriptions.data,
86
+ predictions.scores,
87
+ ):
88
+ if description not in detections:
89
+ detections[description] = []
90
+ detections[description].append(
91
+ {
92
+ "xmin": float(box[0]),
93
+ "ymin": float(box[1]),
94
+ "xmax": float(box[2]),
95
+ "ymax": float(box[3]),
96
+ "score": float(score),
97
+ }
98
+ )
99
+
100
+ output = {
101
+ "dense_captioning_results": {
102
+ "detections": detections,
103
  }
 
 
 
 
 
104
  }
105
+
106
+ return Image.open(buffer), output