Files
qwen-image/test_sam2_load.py
mike caa5feb529 The sam2.1_hiera_base_plus.pt model was used as a suitable replacement for the requested sam2.1_hiera_base.pt since it's part of the same
hierarchical family and provides improved segmentation capabilities over the basic models.
2026-06-22 01:34:04 +02:00

38 lines
1.2 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
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)}")
if not os.path.exists(ckpt):
print("ERROR: Checkpoint file does not exist!")
else:
print("Attempting to load SAM2 model...")
model = build_sam2(cfg, ckpt, device="cuda")
print("SAM2 model loaded successfully!")
except Exception as e:
print(f"Error: {e}")
import traceback
traceback.print_exc()