Finetunning model to downstream task. Attribute does not exist!

Hello, I have a pretrained model that I am trying to fine tune to a downstream task. However, when I create this new class and pass my model through the constructor. See below:

class MyModel(nn.Module):

 def __init__(self, pretrained_model, model_settings):

        super(MyModel, self).__init__()
   
        self.orig_d_a, self.orig_d_v = model_settings.orig_d_a, model_settings.orig_d_v
        self.d_a, self.d_v = 130, 130
        self.output_dim = model_settings.output_dim
        self.pre_trained = pretrained_model
        self.proj_a = nn.Conv1d(self.orig_d_a, self.d_a, kernel_size=1, padding=0, bias=False)
        self.proj_v = nn.Conv1d(self.orig_d_v, self.d_v, kernel_size=1, padding=0, bias=False)

    def forward(self, a, v):

        x_a = a.transpose(1, 2)
        x_v = v.transpose(1, 2)
        proj_x_a = x_a if self.orig_d_a == self.d_a else self.proj_a(x_a)
        proj_x_v = x_v if self.orig_d_v == self.d_v else self.proj_v(x_v)
        output = self.pre_trained(proj_x_a, proj_x_v)
        
        return output

I keep getting the following error:

  File "/localdisk//finetunning/src/models.py", line 31, in forward
    output = self.pre_trained(proj_x_a, proj_x_v)
  File "/localdisk/conda/miniconda3/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1130, in __getattr__

    raise AttributeError("'{}' object has no attribute '{}'".format(
AttributeError: 'MyModel' object has no attribute 'pre_trained'

Any ideas why this is happening? thanks

I cannot reproduce the issue using your code snippet and models.resnet18() as the pretrained model after removing undefined code parts. Could you update your code and make it executable to that we could reproduce the error?