transfrom.Normalize | RuntimeError: expected device cpu but got device cuda:0

Hi,

when I try to normalize an image with transforms.Normalize I get this error:

“RuntimeError: expected device cpu but got device cuda:0”

I know that my model is on the GPU and I want that, how to I change the device for the normalization within my dataset class?

            norm = Normalize([0.5, 0.5, 0.5], [1, 1, 1])
            transform_list_signal += [transforms.ToTensor()]
            transform_list_signal.append(norm)
            transform_list += [transforms.ToTensor()]
            apply_transformation_signal = Compose(transform_list_signal)
            apply_transformation = Compose(transform_list)
            signal_im_transformed = apply_transformation_signal(signal_im)
            target_im_transformed = apply_transformation(target_im)

Did you solved that error?

Yes. For me it was just a updating problem. I was was using an old torchvision version. I can’t recall which, but updating torchvision to the newest version solved the problem.