The story behind this error can be described as follows:
At first, I used the MSE-based loss function in the python file as
loss_function = nn.MSELoss().cuda()
the loss was input as
loss = loss_function(output, gtlabel)
in addition, thee line of  ‘labels_batch=…’ was input as
labels_batch = torch.FloatTensor(labels_batch.wiew(-1,self.num_classes).numpy())
These codes was run smoothly!

At this time, I want to use another loss function, i.e., 1-CCC,
and the codes are changed as
            pcc = scipy.stats.pearsonr(gtlabel, output.squeeze(-1))[0]
            loss = 1-2*pcc*np.std(gtlabel)*np.std(output)/((np.std(gtlabel))**2+(np.std(output))**2+(np.mean(output)-np.mean(gtlabel))**2)

When I use the line of " labels_batch = torch.FloatTensor(labels_batch.wiew(-1,self.num_classes).numpy())", there is the error listed in the previous posts,
So my colleague suggested me to add ‘requires_grad=True’ to this line, but there is the new error as listed in the previous post.
That’s all!