From c0c65f2f4e658e4514517b34f853b3efee386528 Mon Sep 17 00:00:00 2001 From: felixfu Date: Fri, 1 Nov 2024 23:17:34 +0800 Subject: [PATCH] fix register torchvision.transforms error, AttributeError: 'functools.partial' object has no attribute '__module__' when call mmengine.registry.count_registered_modules(./) --- mmpretrain/datasets/transforms/processing.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/mmpretrain/datasets/transforms/processing.py b/mmpretrain/datasets/transforms/processing.py index 4c640f6b1fa..cc182783640 100644 --- a/mmpretrain/datasets/transforms/processing.py +++ b/mmpretrain/datasets/transforms/processing.py @@ -82,10 +82,8 @@ def register_vision_transforms() -> List[str]: _transform = getattr(torchvision.transforms, module_name) if inspect.isclass(_transform) and callable( _transform) and not isinstance(_transform, (EnumMeta)): - from functools import partial TRANSFORMS.register_module( - module=partial( - TorchVisonTransformWrapper, transform=_transform), + module=lambda name=module_name: TorchVisonTransformWrapper(transform=torchvision.transforms[name], name=name), name=f'torchvision/{module_name}') vision_transforms.append(f'torchvision/{module_name}') return vision_transforms