diff --git a/modules/impact/config.py b/modules/impact/config.py index 509650b..8f4b1ab 100644 --- a/modules/impact/config.py +++ b/modules/impact/config.py @@ -1,7 +1,7 @@ import configparser import os -version_code = [8, 18] +version_code = [8, 18, 1] version = f"V{version_code[0]}.{version_code[1]}" + (f'.{version_code[2]}' if len(version_code) > 2 else '') dependency_version = 24 diff --git a/modules/impact/core.py b/modules/impact/core.py index 0f6e17a..800ab69 100644 --- a/modules/impact/core.py +++ b/modules/impact/core.py @@ -2,7 +2,6 @@ import os import warnings import torch -from sam2.sam2_image_predictor import SAM2ImagePredictor from segment_anything import SamPredictor from comfy_extras.nodes_custom_sampler import Noise_RandomNoise @@ -25,9 +24,18 @@ from impact import impact_sampling from concurrent.futures import ThreadPoolExecutor import inspect from collections import OrderedDict -from sam2.build_sam import build_sam2, build_sam2_video_predictor import torch.nn.functional as F +import logging +import sys +import importlib +is_sam2_available = importlib.util.find_spec("sam2") +sam2_unavailable_message = f"\n----------------------------------------------------------------------------\n[Impact Pack] The SAM2 functionality is unavailable because the `facebook/sam2` dependency is not installed.\n\nInstallation command:\n{sys.executable} -m pip install git+https://github.com/facebookresearch/sam2\n----------------------------------------------------------------------------\n" +if is_sam2_available: + from sam2.sam2_image_predictor import SAM2ImagePredictor + from sam2.build_sam import build_sam2, build_sam2_video_predictor +else: + logging.warning(sam2_unavailable_message) try: from comfy_extras import nodes_differential_diffusion @@ -653,6 +661,9 @@ class SAM2Wrapper: self.video_predictor.to(device="cpu") def predict(self, image, points, plabs, bbox, threshold): + if not is_sam2_available: + raise Exception(sam2_unavailable_message) + if self.image_predictor is None: self.image_predictor = SAM2ImagePredictor(build_sam2(self.config, self.modelname)) @@ -663,6 +674,9 @@ class SAM2Wrapper: return sam_predict(self.image_predictor, points, plabs, bbox, threshold) def predict_video_segs(self, image_frames, segs): + if not is_sam2_available: + raise Exception(sam2_unavailable_message) + if self.video_predictor is None: self.video_predictor = build_sam2_video_predictor(self.config, self.modelname) @@ -713,8 +727,6 @@ class SAM2Wrapper: padding ) - print(f"bbox={bbox} / adjusted_bbox={adjusted_bbox}") - points = [utils.center_of_bbox(adjusted_bbox)] plabs = [1] self.video_predictor.add_new_points_or_box(inference_state=inference_state, frame_idx=0, obj_id=i, points=points, labels=plabs, box=adjusted_bbox) diff --git a/pyproject.toml b/pyproject.toml index 0cc5aee..022f5b2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "comfyui-impact-pack" description = "This node pack offers various detector nodes and detailer nodes that allow you to configure a workflow that automatically enhances facial details. And provide iterative upscaler." -version = "8.18" +version = "8.18.1" license = { file = "LICENSE.txt" } dependencies = ["segment-anything", "scikit-image", "piexif", "transformers", "opencv-python-headless", "GitPython", "scipy>=1.11.4"]