The type error, make code doesn't work

when I use a pytorch-template for my dataset, some errors just like monster on the way. When I solve one, another one is coming and say hello to me. But this error make me feel wondering.
I just write my dataset dataloader in dataloader/;
make a new loss in model/


Trainable parameters: 31042369
Train Epoch: 1 [0/27 (0%)] Loss: 0.669998
Traceback (most recent call last):
  File "", line 68, in <module>
  File "", line 49, in main
  File "E:\kaggle\pytorch-template\base\", line 66, in train
    result = self._train_epoch(epoch)
  File "E:\kaggle\pytorch-template\trainer\", line 60, in _train_epoch
    self.writer.add_image('input', make_grid(data.cpu(), nrow=8, normalize=True))
  File "D:\Anaconda3\lib\site-packages\torchvision\", line 67, in make_grid
    norm_range(tensor, range)
  File "D:\Anaconda3\lib\site-packages\torchvision\", line 61, in norm_range
    norm_ip(t, float(t.min()), float(t.max()))
  File "D:\Anaconda3\lib\site-packages\torchvision\", line 55, in norm_ip
    img.add_(-min).div_(max - min + 1e-5)
RuntimeError: result type Float can't be cast to the desired output type Byte

And I upload code to

It seems that img is a ByteTensor, which you are trying to normalize with floating point values.
This simple code snippet will raise the same issue:

img = torch.randint(0, 255, (3, 24, 24)).byte()

Try to transform img to a FloatTensor via img = img.float() before normalizing it.

1 Like

THANK YOU. :yum: Finally it works.AWESOME.