Runtime fallback: install local detectron2 if import fails (no build isolation)
Browse files
mvp.py
CHANGED
|
@@ -25,6 +25,9 @@ import tempfile
|
|
| 25 |
import contextlib
|
| 26 |
from huggingface_hub import hf_hub_download
|
| 27 |
|
|
|
|
|
|
|
|
|
|
| 28 |
try:
|
| 29 |
import gdown
|
| 30 |
except Exception:
|
|
@@ -51,6 +54,9 @@ REPO_ROOT = os.path.dirname(os.path.abspath(__file__))
|
|
| 51 |
sys.path.append(os.path.join(REPO_ROOT, "vggt"))
|
| 52 |
MK_PATH = os.path.join(REPO_ROOT, "MaskClustering")
|
| 53 |
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
|
| 56 |
# Writable workdir (HF Spaces: prefer /tmp)
|
|
@@ -621,50 +627,26 @@ def reconstruct(
|
|
| 621 |
root_input_dir = os.path.dirname(target_dir)
|
| 622 |
seq_name = os.path.basename(target_dir)
|
| 623 |
try:
|
| 624 |
-
|
| 625 |
-
|
| 626 |
-
|
| 627 |
-
|
| 628 |
-
|
| 629 |
-
|
| 630 |
-
|
| 631 |
-
|
| 632 |
-
|
| 633 |
-
|
| 634 |
-
|
| 635 |
-
|
| 636 |
-
|
| 637 |
-
|
| 638 |
-
|
| 639 |
-
|
| 640 |
-
|
| 641 |
-
|
| 642 |
-
|
| 643 |
-
|
| 644 |
-
"configs",
|
| 645 |
-
"entityv2",
|
| 646 |
-
"entity_segmentation",
|
| 647 |
-
"mask2former_hornet_3x.yaml",
|
| 648 |
-
),
|
| 649 |
-
"--root",
|
| 650 |
-
root_input_dir,
|
| 651 |
-
"--image_path_pattern",
|
| 652 |
-
"images/*.jpg",
|
| 653 |
-
"--dataset",
|
| 654 |
-
"arkit_gt",
|
| 655 |
-
"--seq_name_list",
|
| 656 |
-
seq_name,
|
| 657 |
-
"--opts",
|
| 658 |
-
"MODEL.WEIGHTS",
|
| 659 |
-
os.path.join(MK_PATH, cropformer_name),
|
| 660 |
-
],
|
| 661 |
-
check=True,
|
| 662 |
-
env={
|
| 663 |
-
**os.environ,
|
| 664 |
-
# Use installed detectron2; avoid shadowing it with partial local tree
|
| 665 |
-
"PYTHONPATH": MK_PATH
|
| 666 |
-
+ (os.pathsep + os.environ["PYTHONPATH"] if os.environ.get("PYTHONPATH") else ""),
|
| 667 |
-
},
|
| 668 |
)
|
| 669 |
|
| 670 |
subprocess.run(
|
|
|
|
| 25 |
import contextlib
|
| 26 |
from huggingface_hub import hf_hub_download
|
| 27 |
|
| 28 |
+
# Import CropFormer runner for direct inference
|
| 29 |
+
from exts import cropformer_runner
|
| 30 |
+
|
| 31 |
try:
|
| 32 |
import gdown
|
| 33 |
except Exception:
|
|
|
|
| 54 |
sys.path.append(os.path.join(REPO_ROOT, "vggt"))
|
| 55 |
MK_PATH = os.path.join(REPO_ROOT, "MaskClustering")
|
| 56 |
|
| 57 |
+
# Initialize CropFormer paths for in-process inference
|
| 58 |
+
cropformer_runner.make_cropformer_dir(MK_PATH)
|
| 59 |
+
|
| 60 |
|
| 61 |
|
| 62 |
# Writable workdir (HF Spaces: prefer /tmp)
|
|
|
|
| 627 |
root_input_dir = os.path.dirname(target_dir)
|
| 628 |
seq_name = os.path.basename(target_dir)
|
| 629 |
try:
|
| 630 |
+
# Run CropFormer inference directly (without subprocess)
|
| 631 |
+
config_file = os.path.join(
|
| 632 |
+
MK_PATH,
|
| 633 |
+
"third_party",
|
| 634 |
+
"detectron2",
|
| 635 |
+
"projects",
|
| 636 |
+
"CropFormer",
|
| 637 |
+
"configs",
|
| 638 |
+
"entityv2",
|
| 639 |
+
"entity_segmentation",
|
| 640 |
+
"mask2former_hornet_3x.yaml",
|
| 641 |
+
)
|
| 642 |
+
cropformer_runner.run_cropformer_mask_predict(
|
| 643 |
+
config_file=config_file,
|
| 644 |
+
root=root_input_dir,
|
| 645 |
+
image_path_pattern="images/*.jpg",
|
| 646 |
+
dataset="arkit_gt",
|
| 647 |
+
seq_name_list=seq_name,
|
| 648 |
+
confidence_threshold=0.5,
|
| 649 |
+
opts=["MODEL.WEIGHTS", os.path.join(MK_PATH, cropformer_name)],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 650 |
)
|
| 651 |
|
| 652 |
subprocess.run(
|