i am trying designing a neural network to classify signals by a pytorch model. after training the model i save the model and load it for inference phase.
i am trying designing a neural network to classify signals by a pytorch model. after training the model i save the model by the fllowing code:
torch.save(model.state_dict(), ".pth")
afterward i want to load the model for inference phase. i use the following code :
model_test = spectrogram_model(X_Test)
model_test.load_state_dict(torch.load(".pth"))
but i got an error as follows:
AttributeError: 'Tensor' object has no attribute 'load_state_dict'
the content of spectrogram_model is as follows:
class Spectrogram(nn.Module):
def __init__(self):
super().__init__()
self.dropout = nn.Dropout(0.04)
self.hidden1 = nn.Linear(16, 12)
self.act1 = nn.ReLU()
self.hidden2 = nn.Linear(12, 8)
self.act2 = nn.ReLU()
self.hidden3 = nn.Linear(8, 4)
def forward(self, x):
x = self.dropout(x)
x = self.act1(self.hidden1(x))
x = self.act2(self.hidden2(x))
x = self.hidden3(x)
return x
do you have any solution?