Skip to content

Commit 50c7b71

Browse files
committed
fixed: removed the torch_whitelist related logic and updated the ultralytics dependency to version 8.3.162 or higher
#69
1 parent 5b4e550 commit 50c7b71

File tree

4 files changed

+7
-79
lines changed

4 files changed

+7
-79
lines changed

__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import importlib
99
import logging
1010

11-
version_code = [1, 3, 4]
11+
version_code = [1, 3, 5]
1212
version_str = f"V{version_code[0]}.{version_code[1]}" + (f'.{version_code[2]}' if len(version_code) > 2 else '')
1313
logging.info(f"### Loading: ComfyUI-Impact-Subpack ({version_str})")
1414

modules/subcore.py

Lines changed: 4 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -162,70 +162,12 @@ def restricted_getattr(obj, name, *args):
162162
from numpy import dtype
163163
from numpy.dtypes import Float64DType
164164
except:
165-
logging.error("[Impact Subpack] installed 'numpy' is outdated. Please update 'numpy' to 1.26.4")
166-
raise Exception("[Impact Subpack] installed 'numpy' is outdated. Please update 'numpy' to 1.26.4")
165+
logging.error("[Impact Subpack] installed 'numpy' is outdated. Please update 'numpy>=1.26.4'")
166+
raise Exception("[Impact Subpack] installed 'numpy' is outdated. Please update 'numpy>=1.26.4'")
167167

168168

169169
torch_whitelist = []
170170

171-
# https://github.com/comfyanonymous/ComfyUI/issues/5516#issuecomment-2466152838
172-
def build_torch_whitelist():
173-
"""
174-
For security, only a limited set of namespaces is allowed during loading.
175-
176-
Since the same module may be identified by different namespaces depending on the model,
177-
some modules are additionally registered with aliases to ensure backward compatibility.
178-
"""
179-
global torch_whitelist
180-
181-
for name, obj in inspect.getmembers(modules):
182-
if inspect.isclass(obj) and obj.__module__.startswith("ultralytics.nn.modules"):
183-
aliasObj = type(name, (obj,), {})
184-
aliasObj.__module__ = "ultralytics.nn.modules"
185-
186-
torch_whitelist.append(obj)
187-
torch_whitelist.append(aliasObj)
188-
189-
for name, obj in inspect.getmembers(block_modules):
190-
if inspect.isclass(obj) and obj.__module__.startswith("ultralytics.nn.modules"):
191-
aliasObj = type(name, (obj,), {})
192-
aliasObj.__module__ = "ultralytics.nn.modules.block"
193-
194-
torch_whitelist.append(obj)
195-
torch_whitelist.append(aliasObj)
196-
197-
for name, obj in inspect.getmembers(loss_modules):
198-
if inspect.isclass(obj) and obj.__module__.startswith("ultralytics.utils.loss"):
199-
aliasObj = type(name, (obj,), {})
200-
aliasObj.__module__ = "ultralytics.yolo.utils.loss"
201-
202-
torch_whitelist.append(obj)
203-
torch_whitelist.append(aliasObj)
204-
205-
for name, obj in inspect.getmembers(torch_modules):
206-
if inspect.isclass(obj) and obj.__module__.startswith("torch.nn.modules"):
207-
torch_whitelist.append(obj)
208-
209-
aliasIterableSimpleNamespace = type("IterableSimpleNamespace", (IterableSimpleNamespace,), {})
210-
aliasIterableSimpleNamespace.__module__ = "ultralytics.yolo.utils"
211-
212-
aliasTaskAlignedAssigner = type("TaskAlignedAssigner", (TaskAlignedAssigner,), {})
213-
aliasTaskAlignedAssigner.__module__ = "ultralytics.yolo.utils.tal"
214-
215-
aliasYOLOv10DetectionModel = type("YOLOv10DetectionModel", (DetectionModel,), {})
216-
aliasYOLOv10DetectionModel.__module__ = "ultralytics.nn.tasks"
217-
aliasYOLOv10DetectionModel.__name__ = "YOLOv10DetectionModel"
218-
219-
aliasv10DetectLoss = type("v10DetectLoss", (loss_modules.E2EDetectLoss,), {})
220-
aliasv10DetectLoss.__name__ = "v10DetectLoss"
221-
aliasv10DetectLoss.__module__ = "ultralytics.utils.loss"
222-
223-
torch_whitelist += [DetectionModel, aliasYOLOv10DetectionModel, SegmentationModel, IterableSimpleNamespace,
224-
aliasIterableSimpleNamespace, TaskAlignedAssigner, aliasTaskAlignedAssigner, aliasv10DetectLoss,
225-
restricted_getattr, dill._dill._load_type, scalar, dtype, Float64DType]
226-
227-
build_torch_whitelist()
228-
229171
except Exception as e:
230172
logging.error(e)
231173
logging.error("\n!!!!!\n\n[ComfyUI-Impact-Subpack] If this error occurs, please check the following link:\n\thttps://github.com/ltdrdata/ComfyUI-Impact-Pack/blob/Main/troubleshooting/TROUBLESHOOTING.md\n\n!!!!!\n")
@@ -372,22 +314,8 @@ def torch_wrapper(*args, **kwargs):
372314

373315

374316
def load_yolo(model_path: str):
375-
# https://github.com/comfyanonymous/ComfyUI/issues/5516#issuecomment-2466152838
376-
if hasattr(torch.serialization, 'safe_globals'):
377-
with torch.serialization.safe_globals(torch_whitelist):
378-
try:
379-
return YOLO(model_path)
380-
except ModuleNotFoundError:
381-
# https://github.com/ultralytics/ultralytics/issues/3856
382-
YOLO("yolov8n.pt")
383-
return YOLO(model_path)
384-
else:
385-
try:
386-
return YOLO(model_path)
387-
except ModuleNotFoundError:
388-
YOLO("yolov8n.pt")
389-
return YOLO(model_path)
390-
317+
return YOLO(model_path)
318+
391319

392320
def inference_bbox(
393321
model,

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[project]
22
name = "comfyui-impact-subpack"
33
description = "This node pack provides nodes that complement the Impact Pack, such as the UltralyticsDetectorProvider."
4-
version = "1.3.4"
4+
version = "1.3.5"
55
license = { file = "LICENSE.txt" }
66
dependencies = ["matplotlib", "ultralytics"]
77

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
matplotlib
2-
ultralytics
2+
ultralytics>=8.3.162
33
numpy
44
opencv-python-headless
55
dill

0 commit comments

Comments
 (0)