There was a similar question in How to assign a name for a pytorch layer?, and the answer gives two ways by using Sequential or OrderedDict. But what I hope is to add a name
paramter to my custom module, namely
class MyModule(nn.Module):
def __init__(self, name=None):
...
and later I can use
class AnotherModule(nn.Module):
def __init__(self):
self.mymodules = ModuleList(MyModule(name=f'my{_}') for _ in range(2))
Is there a way to achieve this or this is just impossible?