TypeError although same shape: if not (target.size() == input.size()): 'int' object is not callable
This is the error message I get. In the first line, I output the shapes of predicted and  target. From my understanding, the error arises from those shapes not being the same but here they clearly are.

torch.Size([6890, 3]) torch.Size([6890, 3])

Traceback (most recent call last):
  File "train.py", line 251, in &lt;module&gt;
    main()
  File "train.py", line 230, in main
    train(net, training_dataset, targets, device, criterion, optimizer, epoch, args.epochs)
  File "train.py", line 101, in train
    loss = criterion(predicted, target.detach().cpu().numpy())
  File "/home/hb119056/.local/lib/python3.6/site-packages/torch/nn/modules/module.py", line 493, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/hb119056/.local/lib/python3.6/site-packages/torch/nn/modules/loss.py", line 443, in forward
    return F.mse_loss(input, target, reduction=self.reduction)
  File "/home/hb119056/.local/lib/python3.6/site-packages/torch/nn/functional.py", line 2244, in mse_loss
    if not (target.size() == input.size()):
TypeError: 'int' object is not callable



I hope all the relevant context information is provided and if not, please let me know. Thanks for any suggestions!

EDIT: This is the part of the code where this error occurs:

        target = torch.from_numpy(np.load(file_dir + '/points/points{:03}.npy'.format(i))).to(device)
        rv = torch.zeros(12 * outputs.shape[0])

        for j in [x for x in range(10) if x != i]:
            source = torch.from_numpy(np.load(file_dir + '/points/points{:03}.npy'.format(j))).to(device)
            rv = factor.ransac(source, target, prob, n_iter, tol, device) # some self-written RANSAC-like method

        predicted = factor.predict(source, rv, outputs)
        print(target.shape, predicted.shape)
        loss = criterion(predicted, target.detach().cpu().numpy()) ## error occurs here


criterion is nn.MSELoss().

A little bit late but maybe it will help someone else. Just solved the same problem for myself.

As Alpha said in his answer we cannot call .size() for a numpy array.
But we can call .size() for a tensor.
Therefore, we need to make our target a tensor. You can do it like this:

target = torch.from_numpy(target)


I'm using GPU, so I also needed to send my target to GPU. You can do it like this:

device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
target = target.to(device)


And then the loss function must work perfectly.
