Hello friends, I have a problem on my code . It gives an error below:
RuntimeError: size mismatch, m1: [1 x 1682], m2: [20 x 1682] at d:\downloads\pytorch-master-1\torch\lib\th\generic/THTensorMath.c:1238
I am putting the problematic code below . Could anyone help me ? I got crazy due to this error .
for epoch in range(1,nb_epoch +1):
train_loss = 0
s = 0.
for id_user in range(nb_users):
input = Variable(training_set[id_user]).unsqueeze(0)
target = input.clone()
if torch.sum(target.data > 0) > 0:
output = sae(input)
target.require_grad = False
output[target == 0] = 0
loss = criterion(output,target)
mean_corrector = nb_movies / float(torch.sum(target.data > 0 ) +1e-10)
train_loss += np.sqrt(loss.data*mean_corrector)
s += 1.
print('epoch: ’ + str(epoch) + ’ loss: ’ + str(train_loss/s))
This code is from tutorials of a friend on Udemy. I know it because I did all the codes presented by Hadelin (we did the Bachelor together, and he buys me the codes for a few euros).
I want to apologise, I am doing a PhD in Portugal, with a Portuguese salary. Selling codes for tutorials doubled my salary so I can regularly take the flight to see my family and friends in France and Switzerland.
But, as I did the code, I can tell you: Don’t trust it! I did it quickly (very quickly) on my free time. This one is from the autoencoder for movie rate prediction, and the results of prediction are very far from the state-of-the-art results presented in the paper http://users.cecs.anu.edu.au/~u5098633/papers/www15.pdf.
Also, I would not recommend non-free tutorials: most of the time, there is a ‘bad-spirit’ business hidden behind, they are not made for sharing knowledge but to make huge profits. This one, on Udemy, is a good example. My friend who is presenting the code is not understanding it at all. You have free tutorials with much better quality on the official websites and everywhere on Github.
However, your code is just the same with some changed names. So it should work. I am pretty sure your error is coming from another part (can you show your whole script? or at least the part with your modifications?)
As far as I know, the size mismatch always comes from the network architecture like the number of convolution which not have the required size. My suggestion you can go to your network code. From your code I see
output = sae(input) . You can see in class
sae and check the size for every layer.
check your network and forward function.