Spaces:
Paused
Paused
Dev Deploy: 5a596ff
Browse files- app.py +39 -0
- visualizer.gpu.toml +2 -0
- visualizer.hf.toml +2 -0
app.py
CHANGED
|
@@ -106,6 +106,22 @@ SEGFORMER_MODEL_NAME = str(config_value(
|
|
| 106 |
"segformer_model_name",
|
| 107 |
"nvidia/segformer-b2-finetuned-ade-512-512",
|
| 108 |
))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
DEPTH_MODEL_NAME = str(config_value(
|
| 110 |
"DEPTH_MODEL_NAME",
|
| 111 |
"models",
|
|
@@ -309,6 +325,27 @@ def hf_offline() -> bool:
|
|
| 309 |
return os.getenv("HF_HUB_OFFLINE") == "1" or os.getenv("TRANSFORMERS_OFFLINE") == "1"
|
| 310 |
|
| 311 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 312 |
def _load_segmentation_model():
|
| 313 |
global seg_processor, seg_model, segmentation_backend
|
| 314 |
|
|
@@ -319,6 +356,7 @@ def _load_segmentation_model():
|
|
| 319 |
ONEFORMER_MODEL_NAME,
|
| 320 |
local_files_only=hf_offline(),
|
| 321 |
)
|
|
|
|
| 322 |
seg_model = OneFormerForUniversalSegmentation.from_pretrained(
|
| 323 |
ONEFORMER_MODEL_NAME,
|
| 324 |
local_files_only=hf_offline(),
|
|
@@ -2116,6 +2154,7 @@ def build_segmentation_bundle(contents: bytes):
|
|
| 2116 |
"metadata": {
|
| 2117 |
"segmenter": segmenter_metadata_name(),
|
| 2118 |
"segmentationModel": models["segmentation"]["name"],
|
|
|
|
| 2119 |
"floorPixels": int(floor_mask.sum()),
|
| 2120 |
"surfacePixels": int(surface_mask.sum()),
|
| 2121 |
**edge_metadata,
|
|
|
|
| 106 |
"segformer_model_name",
|
| 107 |
"nvidia/segformer-b2-finetuned-ade-512-512",
|
| 108 |
))
|
| 109 |
+
# Resolution the segmenter runs at. The model's default (~640px shortest edge) decides the
|
| 110 |
+
# floor-mask boundary at low res and upscales it, which is the root cause of the coarse
|
| 111 |
+
# "pale rim" around objects. Raising this sharpens silhouettes at the cost of GPU VRAM /
|
| 112 |
+
# latency. Set 0 to keep the model default. Only applied to the OneFormer backend.
|
| 113 |
+
SEGMENTATION_SHORTEST_EDGE = int(config_value(
|
| 114 |
+
"SEGMENTATION_SHORTEST_EDGE",
|
| 115 |
+
"models",
|
| 116 |
+
"segmentation_shortest_edge",
|
| 117 |
+
"1024",
|
| 118 |
+
))
|
| 119 |
+
SEGMENTATION_LONGEST_EDGE = int(config_value(
|
| 120 |
+
"SEGMENTATION_LONGEST_EDGE",
|
| 121 |
+
"models",
|
| 122 |
+
"segmentation_longest_edge",
|
| 123 |
+
"2048",
|
| 124 |
+
))
|
| 125 |
DEPTH_MODEL_NAME = str(config_value(
|
| 126 |
"DEPTH_MODEL_NAME",
|
| 127 |
"models",
|
|
|
|
| 325 |
return os.getenv("HF_HUB_OFFLINE") == "1" or os.getenv("TRANSFORMERS_OFFLINE") == "1"
|
| 326 |
|
| 327 |
|
| 328 |
+
def _apply_segmentation_input_size(processor) -> dict | None:
|
| 329 |
+
"""Raise the segmenter's input resolution so the floor-mask boundary is decided at
|
| 330 |
+
higher resolution (sharper object silhouettes) instead of the model's low ~640px
|
| 331 |
+
default. Returns the applied size dict, or None if disabled/unsupported."""
|
| 332 |
+
if SEGMENTATION_SHORTEST_EDGE <= 0:
|
| 333 |
+
return None
|
| 334 |
+
image_processor = getattr(processor, "image_processor", processor)
|
| 335 |
+
try:
|
| 336 |
+
size = dict(getattr(image_processor, "size", {}) or {})
|
| 337 |
+
size["shortest_edge"] = SEGMENTATION_SHORTEST_EDGE
|
| 338 |
+
size["longest_edge"] = max(SEGMENTATION_LONGEST_EDGE, SEGMENTATION_SHORTEST_EDGE)
|
| 339 |
+
size.pop("height", None)
|
| 340 |
+
size.pop("width", None)
|
| 341 |
+
image_processor.size = size
|
| 342 |
+
print(f"Segmentation input size -> {size}", flush=True)
|
| 343 |
+
return size
|
| 344 |
+
except Exception as exc:
|
| 345 |
+
print(f"Could not override segmentation input size: {exc}", flush=True)
|
| 346 |
+
return None
|
| 347 |
+
|
| 348 |
+
|
| 349 |
def _load_segmentation_model():
|
| 350 |
global seg_processor, seg_model, segmentation_backend
|
| 351 |
|
|
|
|
| 356 |
ONEFORMER_MODEL_NAME,
|
| 357 |
local_files_only=hf_offline(),
|
| 358 |
)
|
| 359 |
+
_apply_segmentation_input_size(seg_processor)
|
| 360 |
seg_model = OneFormerForUniversalSegmentation.from_pretrained(
|
| 361 |
ONEFORMER_MODEL_NAME,
|
| 362 |
local_files_only=hf_offline(),
|
|
|
|
| 2154 |
"metadata": {
|
| 2155 |
"segmenter": segmenter_metadata_name(),
|
| 2156 |
"segmentationModel": models["segmentation"]["name"],
|
| 2157 |
+
"segmentationShortestEdge": SEGMENTATION_SHORTEST_EDGE,
|
| 2158 |
"floorPixels": int(floor_mask.sum()),
|
| 2159 |
"surfacePixels": int(surface_mask.sum()),
|
| 2160 |
**edge_metadata,
|
visualizer.gpu.toml
CHANGED
|
@@ -9,6 +9,8 @@ moge_model_name = "Ruicheng/moge-2-vitl-normal"
|
|
| 9 |
oneformer_model_name = "shi-labs/oneformer_ade20k_swin_large"
|
| 10 |
mask2former_model_name = "facebook/mask2former-swin-small-ade-semantic"
|
| 11 |
segformer_model_name = "nvidia/segformer-b2-finetuned-ade-512-512"
|
|
|
|
|
|
|
| 12 |
depth_model_name = "depth-anything/Depth-Anything-V2-Metric-Indoor-Large-hf"
|
| 13 |
intrinsic_model_version = "v2"
|
| 14 |
|
|
|
|
| 9 |
oneformer_model_name = "shi-labs/oneformer_ade20k_swin_large"
|
| 10 |
mask2former_model_name = "facebook/mask2former-swin-small-ade-semantic"
|
| 11 |
segformer_model_name = "nvidia/segformer-b2-finetuned-ade-512-512"
|
| 12 |
+
segmentation_shortest_edge = 1024
|
| 13 |
+
segmentation_longest_edge = 2048
|
| 14 |
depth_model_name = "depth-anything/Depth-Anything-V2-Metric-Indoor-Large-hf"
|
| 15 |
intrinsic_model_version = "v2"
|
| 16 |
|
visualizer.hf.toml
CHANGED
|
@@ -9,6 +9,8 @@ moge_model_name = "Ruicheng/moge-2-vitl-normal"
|
|
| 9 |
oneformer_model_name = "shi-labs/oneformer_ade20k_swin_large"
|
| 10 |
mask2former_model_name = "facebook/mask2former-swin-small-ade-semantic"
|
| 11 |
segformer_model_name = "nvidia/segformer-b2-finetuned-ade-512-512"
|
|
|
|
|
|
|
| 12 |
depth_model_name = "depth-anything/Depth-Anything-V2-Metric-Indoor-Large-hf"
|
| 13 |
intrinsic_model_version = "v2"
|
| 14 |
|
|
|
|
| 9 |
oneformer_model_name = "shi-labs/oneformer_ade20k_swin_large"
|
| 10 |
mask2former_model_name = "facebook/mask2former-swin-small-ade-semantic"
|
| 11 |
segformer_model_name = "nvidia/segformer-b2-finetuned-ade-512-512"
|
| 12 |
+
segmentation_shortest_edge = 1024
|
| 13 |
+
segmentation_longest_edge = 2048
|
| 14 |
depth_model_name = "depth-anything/Depth-Anything-V2-Metric-Indoor-Large-hf"
|
| 15 |
intrinsic_model_version = "v2"
|
| 16 |
|