Undocumented difference between torchvision 0.2.1 and 0.3.0

I am currently taking a deep learning class from IBM on EDx, and IBM’s Cognitive labs is using torchvision 0.2.1. In attempting to run under Anaconda using Windows 10 on my own machine (which uses torchvision 0.3.0), I noticed a difference which I cannot find documented anywhere. (Both environments are using python 3.6 versions.)

The output of a transformed MNIST character’s 2nd dimension has changed from a tensor to an int between torchvision 0.2.1 and 0.3.0.

here is the code i used to test:

import torch
import torchvision
import torchvision.transforms as transforms
import torchvision.datasets as dsets

print(“torch: \t”, torch.version)
print(“torchvisiion:\t”, torchvision.version)
print()

# create a transform to resize the image and convert it to a tensor
IMAGE_SIZE = 16

composed = transforms.Compose([transforms.Resize((IMAGE_SIZE, IMAGE_SIZE)), transforms.ToTensor()])

# Load the training dataset
train_dataset = dsets.MNIST(root=‘./data’, train=True, download=True, transform=composed)

# Show the data type for each element in dataset
for i in range(len(train_dataset[0])):
print(“train_dataset[0][{}]:\t{}\n{}\n”.format(I, type(train_dataset[0][i]), train_dataset[0][i]))

===============================================
this is the output produced byt the program on Cognitive Labs:

torch: 0.4.1
torchvisiion: 0.2.1

train_dataset[0][0]: <class ‘torch.Tensor’>
tensor([[[0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000],
[0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000],
[0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0078,
0.0196, 0.0824, 0.1059, 0.0980, 0.1843, 0.0902, 0.0000, 0.0000],
[0.0000, 0.0000, 0.0000, 0.0039, 0.0824, 0.2157, 0.3765, 0.5333,
0.6118, 0.7373, 0.6627, 0.6196, 0.7647, 0.3020, 0.0000, 0.0000],
[0.0000, 0.0000, 0.0000, 0.0118, 0.3804, 0.8549, 0.9294, 0.9569,
0.8784, 0.9294, 0.4588, 0.2510, 0.2000, 0.0510, 0.0000, 0.0000],
[0.0000, 0.0000, 0.0000, 0.0000, 0.1569, 0.4588, 0.7765, 0.7608,
0.2353, 0.3137, 0.1412, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000],
[0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0078, 0.4275, 0.6941,
0.1137, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000],
[0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0980, 0.6235,
0.5647, 0.2627, 0.0235, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000],
[0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0039, 0.2039,
0.6549, 0.8039, 0.3490, 0.0392, 0.0000, 0.0000, 0.0000, 0.0000],
[0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0039,
0.0980, 0.5137, 0.8863, 0.3255, 0.0078, 0.0000, 0.0000, 0.0000],
[0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0078, 0.0980,
0.3373, 0.6667, 0.9608, 0.3882, 0.0078, 0.0000, 0.0000, 0.0000],
[0.0000, 0.0000, 0.0000, 0.0000, 0.0039, 0.0627, 0.3294, 0.7098,
0.9137, 0.8706, 0.5647, 0.1373, 0.0000, 0.0000, 0.0000, 0.0000],
[0.0000, 0.0000, 0.0118, 0.0784, 0.3137, 0.5843, 0.8980, 0.8824,
0.6235, 0.2667, 0.0510, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000],
[0.0000, 0.0000, 0.2627, 0.7059, 0.9020, 0.8745, 0.7059, 0.2941,
0.0510, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000],
[0.0000, 0.0000, 0.1333, 0.2706, 0.2549, 0.1647, 0.0510, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000],
[0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000]]])

train_dataset[0][1]: <class ‘torch.Tensor’>
5
===============================================
this is the output produced on my machine:
torch: 1.1.0
torchvisiion: 0.3.0

train_dataset[0][0]: <class ‘torch.Tensor’>
tensor([[[0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000],
[0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000],
[0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0078,
0.0196, 0.0824, 0.1059, 0.0980, 0.1843, 0.0902, 0.0000, 0.0000],
[0.0000, 0.0000, 0.0000, 0.0039, 0.0824, 0.2157, 0.3765, 0.5333,
0.6118, 0.7373, 0.6627, 0.6196, 0.7647, 0.3020, 0.0000, 0.0000],
[0.0000, 0.0000, 0.0000, 0.0118, 0.3804, 0.8549, 0.9294, 0.9569,
0.8784, 0.9294, 0.4588, 0.2510, 0.2000, 0.0510, 0.0000, 0.0000],
[0.0000, 0.0000, 0.0000, 0.0000, 0.1569, 0.4588, 0.7765, 0.7608,
0.2353, 0.3137, 0.1412, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000],
[0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0078, 0.4275, 0.6941,
0.1137, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000],
[0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0980, 0.6235,
0.5647, 0.2627, 0.0235, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000],
[0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0039, 0.2039,
0.6549, 0.8039, 0.3490, 0.0392, 0.0000, 0.0000, 0.0000, 0.0000],
[0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0039,
0.0980, 0.5137, 0.8863, 0.3255, 0.0078, 0.0000, 0.0000, 0.0000],
[0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0078, 0.0980,
0.3373, 0.6667, 0.9608, 0.3882, 0.0078, 0.0000, 0.0000, 0.0000],
[0.0000, 0.0000, 0.0000, 0.0000, 0.0039, 0.0627, 0.3294, 0.7098,
0.9137, 0.8706, 0.5647, 0.1373, 0.0000, 0.0000, 0.0000, 0.0000],
[0.0000, 0.0000, 0.0118, 0.0784, 0.3137, 0.5843, 0.8980, 0.8824,
0.6235, 0.2667, 0.0510, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000],
[0.0000, 0.0000, 0.2627, 0.7059, 0.9020, 0.8745, 0.7059, 0.2941,
0.0510, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000],
[0.0000, 0.0000, 0.1333, 0.2706, 0.2549, 0.1647, 0.0510, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000],
[0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000]]])

train_dataset[0][1]: <class ‘int’>
5

===============================================
I have also verified that conda also reflects this difference when tested with the same environment using torchvision 0.2.1 and 0.3.0.

Please advise if this is an intentional change or a “bug”.

Regards,
Jim

I posted this here hoping to get some sort of explanation or verification that it is a bug. Can anyone verify or explain if the behavior is different intentionally?

It’s a change but considered neither particularly noteworthy nor a bug. Most people are ultimately interested in the Dataloader output, that did not change. If you write custom collate functions or rely on the tensor properties, it would ness you up, though.

Best regards

Thomas

Thank you, Thomas. That is what I was looking for.

Regards,

Jim