Commit
·
df0396d
1
Parent(s):
4ac2cad
Update handler.py
Browse files- handler.py +5 -5
handler.py
CHANGED
|
@@ -71,7 +71,7 @@ class EndpointHandler:
|
|
| 71 |
pass
|
| 72 |
|
| 73 |
|
| 74 |
-
def
|
| 75 |
image_array = np.array(image_file)[:, :, ::-1] # BGR
|
| 76 |
predictions, visualized_output = dense_captioning_demo.run_on_image(image_array)
|
| 77 |
buffer = BytesIO()
|
|
@@ -79,7 +79,7 @@ class EndpointHandler:
|
|
| 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,
|
|
@@ -96,11 +96,11 @@ class EndpointHandler:
|
|
| 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 __cal__(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()
|
|
|
|
| 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,
|
|
|
|
| 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
|