Hi. I just want to ask if it is possible to add **kwargs
to all existing classes? the current class __init__
makes it very inconvenient to perform multiple inheritance.
Could you provide an example of how this is a benefit? I’m not sure how multiple inheritance looks like in python.
thanks for the reply. my need for **kwargs
arises from the following kinda situation. i want to add some attributes and methods to, say, the nn.Conv2D class. it will be like
class Foo:
def __init__(self, foo1, foo2, **kwargs):
pass
class FooConv2D(nn.Conv2D, Foo):
def __init__(self, in_channels, ou_channels, ..., foo1, foo2, **kwargs):
....
as you can see, i cant initialize in one call with super
because of the different signatures of the parents. of course i dont have to use super()
, but well, isnt it uglier?
I second the request. for a different reason.
Im working on automl. Ensembling different model types. I have a master function that tests different models, often without changing the args, but I do pass **kwargs to all of them.
the model functions (e.g. resnet18()) contain **kwargs, but the base classes (eg ResNet() do not. adding **kwargs to the init() of the base model classes would allow me not to have to resort to either (cloning the models folder and changing it myself) or this horrendous hack
# I pass model_name, pretrained, num_classes and **kwargs to all
# e.g.
_model_check = models.__dict__[model_name](pretrained=pretrained, num_classes=num_classes)
_args = models.__dict__[_model_check.__class__.__name__].__init__.__code__.co_varnames
_kwargs = {k:kwargs[k] for k in kwargs if k in _args}
self.model = models.__dict__[model_name](pretrained=pretrained, num_classes=num_classes, **_kwargs).to(device=self.device)