Spaces:
Runtime error
Runtime error
Tobias Cornille
commited on
Commit
·
8c3fbdd
1
Parent(s):
77a096a
Fix bitmap file output
Browse files
app.py
CHANGED
|
@@ -23,7 +23,6 @@ import argparse
|
|
| 23 |
import random
|
| 24 |
import warnings
|
| 25 |
import json
|
| 26 |
-
import tempfile
|
| 27 |
|
| 28 |
import gradio as gr
|
| 29 |
import numpy as np
|
|
@@ -263,11 +262,12 @@ def sam_mask_from_points(predictor, image_array, points):
|
|
| 263 |
|
| 264 |
|
| 265 |
def inds_to_segments_format(
|
| 266 |
-
panoptic_inds, thing_category_ids, stuff_category_ids,
|
| 267 |
):
|
| 268 |
panoptic_inds_array = panoptic_inds.numpy().astype(np.uint32)
|
| 269 |
bitmap_file = bitmap2file(panoptic_inds_array, is_segmentation_bitmap=True)
|
| 270 |
-
|
|
|
|
| 271 |
|
| 272 |
unique_inds = np.unique(panoptic_inds_array)
|
| 273 |
stuff_annotations = [
|
|
@@ -407,14 +407,14 @@ def generate_panoptic_mask(
|
|
| 407 |
for i, panoptic_name in enumerate(panoptic_names)
|
| 408 |
]
|
| 409 |
|
| 410 |
-
|
| 411 |
stuff_category_ids = [category_name_to_id[name] for name in stuff_category_names]
|
| 412 |
annotations = inds_to_segments_format(
|
| 413 |
-
panoptic_inds, thing_category_ids, stuff_category_ids,
|
| 414 |
)
|
| 415 |
annotations_json = json.dumps(annotations)
|
| 416 |
|
| 417 |
-
return (image_array, subsection_label_pairs),
|
| 418 |
|
| 419 |
|
| 420 |
config_file = "GroundingDINO/groundingdino/config/GroundingDINO_SwinT_OGC.py"
|
|
|
|
| 23 |
import random
|
| 24 |
import warnings
|
| 25 |
import json
|
|
|
|
| 26 |
|
| 27 |
import gradio as gr
|
| 28 |
import numpy as np
|
|
|
|
| 262 |
|
| 263 |
|
| 264 |
def inds_to_segments_format(
|
| 265 |
+
panoptic_inds, thing_category_ids, stuff_category_ids, output_file_path
|
| 266 |
):
|
| 267 |
panoptic_inds_array = panoptic_inds.numpy().astype(np.uint32)
|
| 268 |
bitmap_file = bitmap2file(panoptic_inds_array, is_segmentation_bitmap=True)
|
| 269 |
+
with open(output_file_path, "wb") as output_file:
|
| 270 |
+
output_file.write(bitmap_file.read())
|
| 271 |
|
| 272 |
unique_inds = np.unique(panoptic_inds_array)
|
| 273 |
stuff_annotations = [
|
|
|
|
| 407 |
for i, panoptic_name in enumerate(panoptic_names)
|
| 408 |
]
|
| 409 |
|
| 410 |
+
output_file_path = "tmp/segmentation_bitmap.png"
|
| 411 |
stuff_category_ids = [category_name_to_id[name] for name in stuff_category_names]
|
| 412 |
annotations = inds_to_segments_format(
|
| 413 |
+
panoptic_inds, thing_category_ids, stuff_category_ids, output_file_path
|
| 414 |
)
|
| 415 |
annotations_json = json.dumps(annotations)
|
| 416 |
|
| 417 |
+
return (image_array, subsection_label_pairs), output_file_path, annotations_json
|
| 418 |
|
| 419 |
|
| 420 |
config_file = "GroundingDINO/groundingdino/config/GroundingDINO_SwinT_OGC.py"
|