Based on the error message it seems that PIL doesn’t recognize the used “image” format with 5 channels as seen here:
x = torch.empty(1, 1, 5).uniform_().byte()
PIL.Image.fromarray(x.numpy())
> TypeError: Cannot handle this data type: (1, 1, 5), |u1

so you would have to make sure the model output is using an expected shape (e.g. 3  or 1 channel(s)).