0

I have a UNet model. I'm trying for a regression model since, in my output, I have different floating values for each pixel. In order to check the r2score, I tried to put the below code in the model class, training_step, validation_step, and test_step.

from pytorch_lightning.metrics.functional import r2score

r2 = r2score(pred, y)

self.log('r2:',r2)

But it's giving the following error

ValueError: Expected both prediction and target to be 1D or 2D tensors, but recevied tensors with dimension torch.Size([50, 1, 32, 32])

How can I check my model fit?

4

1 回答 1

2

问题是该函数接受 1D 或 2D 张量,但您的张量是 4D (B x C x H x W)。因此,要使用该功能,您应该重塑它:

r2 = r2score(pred.view(pred.shape[1], -1), y.view(y.shape[1], -1))
于 2021-02-22T15:03:24.363 回答