Spaces:
Sleeping
Sleeping
nicer
Browse files- app.py +4 -2
- maskrcnn_benchmark/engine/predictor_glip.py +15 -0
app.py
CHANGED
@@ -85,8 +85,10 @@ gr.Interface(
|
|
85 |
),
|
86 |
],
|
87 |
examples=[
|
88 |
-
["./1.jpg", "a
|
89 |
-
["./
|
|
|
|
|
90 |
],
|
91 |
article=Path("docs/intro.md").read_text()
|
92 |
).launch()
|
|
|
85 |
),
|
86 |
],
|
87 |
examples=[
|
88 |
+
["./1.jpg", "A clown making a balloon animal for a pretty lady.", "clown"],
|
89 |
+
["./1.jpg", "A clown kicking a soccer ball for a pretty lady.", "clown"],
|
90 |
+
["./2.jpg", "A kind of tool, wooden handle with a round head.", "tool"]
|
91 |
+
["./3.jpg", "Bumblebee, yellow with black accents.", "Bumblebee"],
|
92 |
],
|
93 |
article=Path("docs/intro.md").read_text()
|
94 |
).launch()
|
maskrcnn_benchmark/engine/predictor_glip.py
CHANGED
@@ -16,6 +16,7 @@ from maskrcnn_benchmark.structures.bounding_box import BoxList
|
|
16 |
from maskrcnn_benchmark import layers as L
|
17 |
from maskrcnn_benchmark.modeling.roi_heads.mask_head.inference import Masker
|
18 |
from maskrcnn_benchmark.utils import cv2_util
|
|
|
19 |
|
20 |
engine = inflect.engine()
|
21 |
nltk.download("punkt")
|
@@ -146,6 +147,13 @@ class GLIPDemo(object):
|
|
146 |
top_predictions = self._post_process(predictions, thresh)
|
147 |
|
148 |
result = original_image.copy()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
149 |
if self.show_mask_heatmaps:
|
150 |
return self.create_mask_montage(result, top_predictions)
|
151 |
|
@@ -261,6 +269,7 @@ class GLIPDemo(object):
|
|
261 |
for box, color in zip(boxes, colors):
|
262 |
box = box.to(torch.int64)
|
263 |
top_left, bottom_right = box[:2].tolist(), box[2:].tolist()
|
|
|
264 |
new_image = cv2.rectangle(new_image, tuple(top_left), tuple(bottom_right), tuple(color) if override_color is None else tuple(override_color), box_pixel)
|
265 |
|
266 |
image = cv2.addWeighted(new_image, box_alpha, image, 1 - box_alpha, 0)
|
@@ -328,6 +337,12 @@ class GLIPDemo(object):
|
|
328 |
|
329 |
if int(y) - text_offset_original < 20:
|
330 |
y += 50
|
|
|
|
|
|
|
|
|
|
|
|
|
331 |
cv2.putText(
|
332 |
image, s, (int(x), int(y)-text_offset_original),
|
333 |
cv2.FONT_HERSHEY_SIMPLEX, text_size,
|
|
|
16 |
from maskrcnn_benchmark import layers as L
|
17 |
from maskrcnn_benchmark.modeling.roi_heads.mask_head.inference import Masker
|
18 |
from maskrcnn_benchmark.utils import cv2_util
|
19 |
+
from PIL import Image
|
20 |
|
21 |
engine = inflect.engine()
|
22 |
nltk.download("punkt")
|
|
|
147 |
top_predictions = self._post_process(predictions, thresh)
|
148 |
|
149 |
result = original_image.copy()
|
150 |
+
def resize_image_by_height(img, new_height=500):
|
151 |
+
width, height = img.size
|
152 |
+
aspect_ratio = width / height
|
153 |
+
new_width = int(new_height * aspect_ratio)
|
154 |
+
resized_img = img.resize((new_width, new_height), Image.ANTIALIAS)
|
155 |
+
return resized_img
|
156 |
+
result = resize_image_by_height(result)
|
157 |
if self.show_mask_heatmaps:
|
158 |
return self.create_mask_montage(result, top_predictions)
|
159 |
|
|
|
269 |
for box, color in zip(boxes, colors):
|
270 |
box = box.to(torch.int64)
|
271 |
top_left, bottom_right = box[:2].tolist(), box[2:].tolist()
|
272 |
+
new_image = cv2.rectangle(new_image, tuple(top_left), tuple(bottom_right), tuple(255, 255, 255), box_pixel+3)
|
273 |
new_image = cv2.rectangle(new_image, tuple(top_left), tuple(bottom_right), tuple(color) if override_color is None else tuple(override_color), box_pixel)
|
274 |
|
275 |
image = cv2.addWeighted(new_image, box_alpha, image, 1 - box_alpha, 0)
|
|
|
337 |
|
338 |
if int(y) - text_offset_original < 20:
|
339 |
y += 50
|
340 |
+
text_size = cv2.getTextSize(s, cv2.FONT_HERSHEY_SIMPLEX, text_size, text_pixel)[0]
|
341 |
+
position = (int(x), int(y)-text_offset_original)
|
342 |
+
bottom_left_corner_of_text = (position[0], position[1] + text_size[1])
|
343 |
+
top_right_corner = (position[0] + text_size[0], position[1])
|
344 |
+
|
345 |
+
image[position[1]:bottom_left_corner_of_text[1], position[0]:top_right_corner[0]] = (255, 255, 255)
|
346 |
cv2.putText(
|
347 |
image, s, (int(x), int(y)-text_offset_original),
|
348 |
cv2.FONT_HERSHEY_SIMPLEX, text_size,
|