Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

raise KeyError( KeyError: 'Name resnet20 is already used, try another name!' #71

Closed
fzp16 opened this issue Jan 23, 2024 · 4 comments
Closed

Comments

@fzp16
Copy link

fzp16 commented Jan 23, 2024

run cifar.py always remind me this error:
raise KeyError( KeyError: 'Name resnet20 is already used, try another name!'
it seems like error in register.py

`
def register_from_dict(self,
name_to_func: Dict[str, Callable]):
for k, v in name_to_func.items():
self.register(v, name=k)

def register(self,
             func: Callable = None,
             *,
             name: Optional[str] = None):
    if func is None:
        return functools.partial(self.register, name=name)

    _type = self.type
    if _type is not None and not isinstance(_type, types.FunctionType):
        if not (isinstance(func, _type) or issubclass(func, _type)):
            raise TypeError(
                f'`func` is expected to be subclass of {_type}.')

    if name is None:
        name = func.__name__

    if self._registry.get(name) is not None:
        raise KeyError(
            f'Name {name} is already used, try another name!')

`

@moskomule
Copy link
Owner

Can you show more contexts, like where the error occurs?

@fzp16
Copy link
Author

fzp16 commented Jan 23, 2024

`Traceback (most recent call last):
File "", line 1027, in _find_and_load
File "", line 1006, in _find_and_load_unlocked
File "", line 688, in load_unlocked
File "", line 883, in exec_module
File "", line 241, in call_with_frames_removed
File "D:\Installation\ANACONDA\envs\senet\lib\site-packages\homura_init
.py", line 8, in
Registry.import_modules('homura.vision')
File "D:\Installation\ANACONDA\envs\senet\lib\site-packages\homura\register.py", line 105, in import_modules
Registry.import_modules(sub_package)
File "D:\Installation\ANACONDA\envs\senet\lib\site-packages\homura\register.py", line 105, in import_modules
Registry.import_modules(sub_package)
File "D:\Installation\ANACONDA\envs\senet\lib\site-packages\homura\register.py", line 97, in import_modules
module = importlib.import_module(package_name)
File "D:\Installation\ANACONDA\envs\senet\lib\importlib_init
.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "D:\Installation\ANACONDA\envs\senet\lib\site-packages\homura\vision\models\cifar_resnet.py", line 290, in
def resnet20(num_classes: int = 10,
File "D:\Installation\ANACONDA\envs\senet\lib\site-packages\homura\register.py", line 59, in register
raise KeyError(
KeyError: 'Name resnet20 is already used, try another name!'
python-BaseException

Process finished with exit code 1
`

@moskomule
Copy link
Owner

Just removing Registry.import_modules('homura.vision') in homura_init.py would work.

@fzp16
Copy link
Author

fzp16 commented Jan 23, 2024

it worked! thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants