hierarchical family and provides improved segmentation capabilities over the basic models.
45 lines
1.5 KiB
Python
45 lines
1.5 KiB
Python
#!/usr/bin/env python3
|
|
|
|
import os
|
|
import json
|
|
from sam2.build_sam import build_sam2
|
|
from sam2.automatic_mask_generator import SAM2AutomaticMaskGenerator
|
|
|
|
# Simulate the _load_sam2 function logic but with proper path handling
|
|
CONFIG_PATH = "/home/mike/dev/qwen-image-edit-rapid-aio-nsfw-v23/tour-comfy/config.json"
|
|
|
|
print(f"CONFIG_PATH: {CONFIG_PATH}")
|
|
|
|
try:
|
|
with open(CONFIG_PATH) as f:
|
|
conf = json.load(f)
|
|
|
|
print("Current config contents:")
|
|
for key, value in conf.items():
|
|
print(f" {key}: {value}")
|
|
|
|
ckpt = os.path.expanduser(conf.get("sam2_checkpoint", "~/.sam/sam2.1_hiera_base_plus.pt"))
|
|
cfg = conf.get("sam2_config", "configs/sam2.1/sam2.1_hiera_t.yaml")
|
|
|
|
print(f"Checkpoint path from config: {ckpt}")
|
|
print(f"Config path from config: {cfg}")
|
|
print(f"Checkpoint exists: {os.path.exists(ckpt)}")
|
|
|
|
# Try to resolve the config path properly relative to venv
|
|
venv_path = "/home/mike/comfyui/venv"
|
|
full_cfg_path = os.path.join(venv_path, cfg)
|
|
print(f"Full config path (venv): {full_cfg_path}")
|
|
print(f"Full config path exists: {os.path.exists(full_cfg_path)}")
|
|
|
|
if not os.path.exists(ckpt):
|
|
print("ERROR: Checkpoint file does not exist!")
|
|
else:
|
|
print("Attempting to load SAM2 model...")
|
|
# Try loading with the resolved path
|
|
model = build_sam2(full_cfg_path, ckpt, device="cuda")
|
|
print("SAM2 model loaded successfully!")
|
|
|
|
except Exception as e:
|
|
print(f"Error: {e}")
|
|
import traceback
|
|
traceback.print_exc() |