Hi,
I am trying to use pretrained Resnet50 for regression task
I changed the output of the fc to 1
model = torchvision.models.resnet50(pretrained=True)
model.fc.out_features = 1
and I am using the MSELoss as loss function and my batch_size = 15
criterion = nn.MSELoss()
preds = network(images)
loss = criterion(preds, labels)
I have another problem
when I have used the same notwork as classification for 8 classes and my batch_size = 15
but when I used it for regression output = 1 with even batch_size = 8
it tells
Maybe your training data is huge. I mean, each sample of your training data is huge. By the way, could you share the nature of the input (I am assuming images) and labels that you are feeding to the model? Is it the same for both classification and regression?
yes
they are the same, the same data I feed to the network input images (3,224,224)
the only difference is the labels
in the first case I replaced the regression 0-8 by classes 0-1, 1-2, …
and in the second case I used the true regression value
In the whole training process:
In the training phase, it works for 209 iterations it finished without any problem
the running was stopped in the validation evaluation (validation has 1100 samples)
after 4% the running was interrupted (in the validation process I used batch_size = 1)
thanks bro,
I have not used move model to gpu than cpu between training and validation
I solved the problem first by adding del images; del labels
and I added in the validation phase
model.eval()
with torch.no_grad():
preds = model(images)