When creating MNIST object, we can set the “transform” parameter to be “torchvision.transforms.ToTensor()”, as following:

mnist = torchvision.datasets.MNIST(
root=’./mnist/’,
train=True,
transform=torchvision.transforms.ToTensor()
)

When loaded by DataLoader, the training data can be transformed into FloatTensor.
However, if I use a torchvision.transforms.ToTensor() object to directly transform the training data, as following:

torchvision.transforms.ToTensor()(mnist.train_data)

error will appear:

AttributeError: ‘torch.ByteTensor’ object has no attribute ‘tobytes’