Error in loss function

Now i understand, thank you. Now i want to save my output image, but the size of the input, doesn´t match with the output.

def to_img(x):
    x = x.view(x.size(0), 1, 28, 28)
    return x

File “C:/Users/user/.spyder-py3/normal_cnn.py”, line 21, in to_img
x = x.view(x.size(0), 1, 28, 28)

RuntimeError: shape ‘[11, 1, 28, 28]’ is invalid for input of size 110

This is the error, what view should i do?

What is your code for saving and what is the shape of the tensor you want to save?

code:

pic = to_img(output.cpu().data)
save_image(pic, './out/image_{}.png'.format(epoch))

shape of ouput: torch.Size([11, 10])

it cannot resize a tensor with size of [11, 10] into [11, 1, 28, 28]. your output is not an image. it is I think label for 11 images.

So, what i should do, to save my 11 images in each iteration? Should i use pic = to_img(label.cpu().data) ?

why do you want to save images? you already have them. Read them and feed them to your network. I don’t understand that. Anyway. you have to save img not lablel. you need a for loop on you 11 images.