Any way to get model name

I am asking if I have a resnet34 model. I can do something like model.__name__ and it returns a string as resnet34.

1 Like

Try model.__class__.__name__ to get the name.


It returns only the base class name which is resnet not resnet34

Could you post the model definition?
This seems to work or did I misunderstand your question?

class MyModel(nn.Module):
    def __init__(self):
        super(MyModel, self).__init__()
    def forward(self, x):
        return x + 1

model = MyModel()            
>> MyModel
1 Like

I am using torchvision.models.resnet34.
What I want is

model = torchvision.models.resnet34(pretrained=True)

to print


but currently it prints

Ah ok, I see.
resnet34() is just a function for constructing the appropriate model. The model itself is just the ResNet.

However, you could simply add a new parameter to your model:

model = MyModel() = 'ResNet34'

Will this meet your needs?

1 Like

Yeah! I also came up with a workaround for myself similar to this.

Thank you for the help!