Hi, I want to use cross entropy function for my 5D inputs (Batch x channels x W x H x D). It seems that I have to use this one VolumetricCrossEntropyCriterion(), but I can’t find it in the documentation.

Any help is appreciated!

Hi, I want to use cross entropy function for my 5D inputs (Batch x channels x W x H x D). It seems that I have to use this one VolumetricCrossEntropyCriterion(), but I can’t find it in the documentation.

Any help is appreciated!

The documentation says: the input tensor has to be 2D. Does that mean if use 3D conv like in my case, the inputs have to be reshaped?

I usually just loop over the input by slice. Assuming your input is (batch, channels, depth, height, width) and target is (batch, depth, height, width):

```
loss = 0
for i in range(input.size()[2]):
loss += F.cross_entropy(input[:, :, i], target[:, i])
```

2 Likes

It works! Thank you so much!!

1 Like