0

I am training a network with batch optimization over my training set, and I would like to get a loss vector containing the loss of each of my training examples.

More specifically I am using images (of size 3x64x64) in a batch of size 64. Therefore my input is a tensor of size 64x3x64x64.

During training when I write

output = net:forward(input)
loss = criterion:forward(input, target)

loss is a number, but I would like to get a tensor (of size 64) with one entry per image in my batch, corresponding to the loss value of this precise image.

Is there a way to do that without looping on the first dimension of my input tensor?

fonfonx
  • 1,475
  • 21
  • 30

1 Answers1

0

The forward method calls another method, the updateOutput method which can be overwritten. For eg., in case of MSECriterion(), you can change the method by commenting the call to the THNN library and write on your own how you want the criterion to function, i.e., do a normal element wise subtraction and then square(again element wise) and divide by the total number of data points(again element wise); then return the output as a tensor.

You will also need to recompile the nn package once you have changed this using luarocks make rocks/[the scm file in the folder] after navigating to the nn folder.

vdai
  • 31
  • 5
  • yes sure it is always possible to write a new method, I am aware of that :) I just hoped it had been done previously, but it seems there is no option in the criterion functions to do that without rewriting them... – fonfonx Apr 17 '17 at 22:04