Update handler.py
Browse files- handler.py +13 -7
handler.py
CHANGED
@@ -504,14 +504,20 @@ def run_anything_task(input_image, text_prompt, task_type, inpaint_prompt, box_t
|
|
504 |
for box, label in zip(boxes_filt, pred_phrases):
|
505 |
show_box(box.cpu().numpy(), plt.gca(), label)
|
506 |
plt.axis('off')
|
507 |
-
|
508 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
509 |
plt.clf()
|
510 |
-
plt.close('all')
|
511 |
-
segment_image_result = cv2.cvtColor(cv2.imread(image_path), cv2.COLOR_BGR2RGB)
|
512 |
-
os.remove(image_path)
|
513 |
-
output_images.append(Image.fromarray(segment_image_result))
|
514 |
-
run_task_time, time_cost_str = get_time_cost(run_task_time, time_cost_str)
|
515 |
|
516 |
print(sam_predictor)
|
517 |
|
|
|
504 |
for box, label in zip(boxes_filt, pred_phrases):
|
505 |
show_box(box.cpu().numpy(), plt.gca(), label)
|
506 |
plt.axis('off')
|
507 |
+
|
508 |
+
# Save the plot to a BytesIO object in memory
|
509 |
+
buf = io.BytesIO()
|
510 |
+
plt.savefig(buf, format='jpeg', bbox_inches='tight')
|
511 |
+
buf.seek(0)
|
512 |
+
|
513 |
+
# Convert the image in memory to a PIL Image
|
514 |
+
segment_image_result = Image.open(buf).convert('RGB')
|
515 |
+
output_images.append(segment_image_result)
|
516 |
+
|
517 |
+
# Clearing memory
|
518 |
+
buf.close()
|
519 |
plt.clf()
|
520 |
+
plt.close('all')
|
|
|
|
|
|
|
|
|
521 |
|
522 |
print(sam_predictor)
|
523 |
|