Issue
I thought that the process of training and inference in Deep Learning is separated, however I saw this snippet, and I actually executed the code, I found that my understanding it might be not correct.
network.train()
batch_losses = []
for step, (imgs, label_imgs) in enumerate(train_loader):
imgs = Variable(imgs).cuda()
label_imgs = Variable(label_imgs.type(torch.LongTensor)).cuda()
outputs = network(imgs)
loss = loss_fn(outputs, label_imgs)
loss_value = loss.data.cpu().numpy()
batch_losses.append(loss_value)
I point out outputs = network(imgs)
to figure out this procedure. this is typically used for estimating model? I know that estimating model is quite good to see our direction. but I don't understand that it's necessary. If I want to boost my training time, could I remove it?
Solution
The code snippet you shared is actually just the training code for a deep learning model. Here, the outputs = network(imgs)
actually takes in the imgs i.e; the training data and gives the predicted outputs after passing through the network (the model you want to train your data on).
And then based on that outputs, loss_fn is calculated here loss = loss_fn(outputs, label_imgs)
taking the predicted labels (outputs) and the actual labels (label_imgs)
Note: In the inference, you dont generally calculate the loss, you calculate the accuracy of the predicted labels. Loss is calculated only on the training data to measure if the training is happening properly and if the loss is decreasing. I suggest you once go through some basic deep learning tutorials to get a better insight in case you still have some doubts.
Answered By - furqan_ahmed
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.