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/dataloaders.py;
make a new loss in model/loss.py

THE ERROR HINTS IS

Trainable parameters: 31042369
Train Epoch: 1 [0/27 (0%)] Loss: 0.669998
Traceback (most recent call last):
  File "train.py", line 68, in <module>
    main(config)
  File "train.py", line 49, in main
    trainer.train()
  File "E:\kaggle\pytorch-template\base\base_trainer.py", line 66, in train
    result = self._train_epoch(epoch)
  File "E:\kaggle\pytorch-template\trainer\trainer.py", 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\utils.py", line 67, in make_grid
    norm_range(tensor, range)
  File "D:\Anaconda3\lib\site-packages\torchvision\utils.py", line 61, in norm_range
    norm_ip(t, float(t.min()), float(t.max()))
  File "D:\Anaconda3\lib\site-packages\torchvision\utils.py", 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 git@github.com:ActonMartin/Unet_pytorch.git

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()
img.add_(torch.tensor(1.))

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

1 Like

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