I’m a bit confused.
I have trained my network to output float values for a given input (regression problem).
How do I use this network now to output float values for a given input?
I followed this thread: How to run trained model? - #2 by ptrblck
and did:
# Train your model
...
# After training
model.eval()
data = torch.randn(1, 3, 24, 24) # Load your data here, this is just dummy data
output = model(data)
prediction = torch.argmax(output)
For the data variable, I put the same tensor i used as input for training but without the target value, but it is complaining about the following:
RuntimeError: Expected 4-dimensional input for 4-dimensional weight [12, 7, 5, 5], but got 3-dimensional input of size [7, 111, 111] instead
This is my network:
class Net(nn.Module):
def __init__(self, bounds):
super().__init__()
self.bounds = bounds
# input channels, output no. of features, kernel size
self.conv1 = nn.Conv2d(7, 12, 5)
# self.pool = nn.MaxPool2d(2, 2)
self.conv2 = nn.Conv2d(12, 16, 5)
self.fc1 = nn.Linear(16 * 103 * 103, 120)
self.fc2 = nn.Linear(120, 84)
self.fc3 = nn.Linear(84, 1)
# self.double()
def forward(self, x):
# x = self.pool(F.relu(self.conv1(x)))
# x = self.pool(F.relu(self.conv1(x)))
# x = self.pool(F.relu(self.conv2(x)))
x = F.relu(self.conv1(x))
x = F.relu(self.conv2(x))
# x = self.pool(F.relu(self.conv2(x)))
x = torch.flatten(x, 1) # flatten all dimensions except batch
x = F.relu(self.fc1(x))
x = F.relu(self.fc2(x))
x = self.fc3(x)
return x