diff --git a/test_sam2_direct.py b/test_sam2_direct.py new file mode 100644 index 0000000..c6ba266 --- /dev/null +++ b/test_sam2_direct.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python3 + +import os +import json +import sys + +# Add the venv to path so we can import sam2 properly +sys.path.insert(0, '/home/mike/comfyui/venv/lib/python3.13/site-packages') + +# This mimics exactly what happens in edit_api.py _load_sam2 function +CONFIG_PATH = "/home/mike/dev/qwen-image-edit-rapid-aio-nsfw-v23/tour-comfy/config.json" + +print(f"Testing SAM2 loading with exact code from edit_api.py") +print(f"CONFIG_PATH: {CONFIG_PATH}") + +try: + # This is the exact code from _load_sam2 function + with open(CONFIG_PATH) as f: + conf = json.load(f) + + print("Config loaded successfully") + print("sam2_checkpoint:", conf.get("sam2_checkpoint")) + print("sam2_config:", conf.get("sam2_config")) + + # This is the exact code from _load_sam2 function + 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: {ckpt}") + print(f"Config path: {cfg}") + print(f"Checkpoint exists: {os.path.exists(ckpt)}") + + # Now try to import and load SAM2 exactly as edit_api.py does + from sam2.build_sam import build_sam2 + from sam2.automatic_mask_generator import SAM2AutomaticMaskGenerator + + if not os.path.exists(ckpt): + raise FileNotFoundError(f"SAM2 checkpoint not found: {ckpt}") + + print("Loading SAM2 model...") + model = build_sam2(cfg, ckpt, device="cuda") + print("SUCCESS: SAM2 model loaded successfully!") + +except Exception as e: + print(f"ERROR: {e}") + import traceback + traceback.print_exc() \ No newline at end of file diff --git a/test_sam2_fixed.py b/test_sam2_fixed.py new file mode 100644 index 0000000..a483023 --- /dev/null +++ b/test_sam2_fixed.py @@ -0,0 +1,42 @@ +#!/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 for SAM2 + print(f"Attempting to load SAM2 model with config: {cfg}") + + if not os.path.exists(ckpt): + print("ERROR: Checkpoint file does not exist!") + else: + print("Attempting to load SAM2 model...") + # This should work now with the correct pkg:// protocol path + 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() \ No newline at end of file diff --git a/test_sam2_load.py b/test_sam2_load.py new file mode 100644 index 0000000..f7e4a47 --- /dev/null +++ b/test_sam2_load.py @@ -0,0 +1,38 @@ +#!/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() \ No newline at end of file diff --git a/test_sam2_load_fixed.py b/test_sam2_load_fixed.py new file mode 100644 index 0000000..dbb27e9 --- /dev/null +++ b/test_sam2_load_fixed.py @@ -0,0 +1,45 @@ +#!/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() \ No newline at end of file diff --git a/tour-comfy/car.html b/tour-comfy/car.html index d4fe42d..24d4a85 100644 --- a/tour-comfy/car.html +++ b/tour-comfy/car.html @@ -1586,6 +1586,73 @@