Undocumented difference between torchvision 0.2.1 and 0.3.0

username: jtlareau
cooked: <p>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.)</p>
<h1><a name="the-output-of-a-transformed-mnist-characters-2nd-dimension-has-changed-from-a-tensor-to-an-int-between-torchvision-021-and-030-1" class="anchor" href="#the-output-of-a-transformed-mnist-characters-2nd-dimension-has-changed-from-a-tensor-to-an-int-between-torchvision-021-and-030-1"></a>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.</h1>
<p>here is the code i used to test:</p>
<blockquote>
<p>import torch<br>
import torchvision<br>
import torchvision.transforms as transforms<br>
import torchvision.datasets as dsets</p>
<p>print(“torch:       \t”, torch.<strong>version</strong>)<br>
print(“torchvisiion:\t”, torchvision.<strong>version</strong>)<br>
print()</p>
<p># create a transform to resize the image and convert it to a tensor<br>
IMAGE_SIZE = 16</p>
<p>composed = transforms.Compose([transforms.Resize((IMAGE_SIZE, IMAGE_SIZE)), transforms.ToTensor()])</p>
<p># Load the training dataset<br>
train_dataset = dsets.MNIST(root=‘./data’, train=True, download=True, transform=composed)</p>
<p># Show the data type for each element in dataset<br>
for i in range(len(train_dataset[0])):<br>
print(“train_dataset[0][{}]:\t{}\n{}\n”.format(I, type(train_dataset[0][i]), train_dataset[0][i]))</p>
</blockquote>
<p>===============================================<br>
this is the output produced byt the program on Cognitive Labs:</p>
<blockquote>
<p>torch:       	 0.4.1<br>
torchvisiion:	 0.2.1</p>
<p>train_dataset[0][0]:	&lt;class ‘torch.Tensor’&gt;<br>
tensor([[[0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000,<br>
0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000],<br>
[0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000,<br>
0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000],<br>
[0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0078,<br>
0.0196, 0.0824, 0.1059, 0.0980, 0.1843, 0.0902, 0.0000, 0.0000],<br>
[0.0000, 0.0000, 0.0000, 0.0039, 0.0824, 0.2157, 0.3765, 0.5333,<br>
0.6118, 0.7373, 0.6627, 0.6196, 0.7647, 0.3020, 0.0000, 0.0000],<br>
[0.0000, 0.0000, 0.0000, 0.0118, 0.3804, 0.8549, 0.9294, 0.9569,<br>
0.8784, 0.9294, 0.4588, 0.2510, 0.2000, 0.0510, 0.0000, 0.0000],<br>
[0.0000, 0.0000, 0.0000, 0.0000, 0.1569, 0.4588, 0.7765, 0.7608,<br>
0.2353, 0.3137, 0.1412, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000],<br>
[0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0078, 0.4275, 0.6941,<br>
0.1137, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000],<br>
[0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0980, 0.6235,<br>
0.5647, 0.2627, 0.0235, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000],<br>
[0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0039, 0.2039,<br>
0.6549, 0.8039, 0.3490, 0.0392, 0.0000, 0.0000, 0.0000, 0.0000],<br>
[0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0039,<br>
0.0980, 0.5137, 0.8863, 0.3255, 0.0078, 0.0000, 0.0000, 0.0000],<br>
[0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0078, 0.0980,<br>
0.3373, 0.6667, 0.9608, 0.3882, 0.0078, 0.0000, 0.0000, 0.0000],<br>
[0.0000, 0.0000, 0.0000, 0.0000, 0.0039, 0.0627, 0.3294, 0.7098,<br>
0.9137, 0.8706, 0.5647, 0.1373, 0.0000, 0.0000, 0.0000, 0.0000],<br>
[0.0000, 0.0000, 0.0118, 0.0784, 0.3137, 0.5843, 0.8980, 0.8824,<br>
0.6235, 0.2667, 0.0510, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000],<br>
[0.0000, 0.0000, 0.2627, 0.7059, 0.9020, 0.8745, 0.7059, 0.2941,<br>
0.0510, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000],<br>
[0.0000, 0.0000, 0.1333, 0.2706, 0.2549, 0.1647, 0.0510, 0.0000,<br>
0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000],<br>
[0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000,<br>
0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000]]])</p>
<p>train_dataset[0][1]:	&lt;class ‘torch.Tensor’&gt;<br>
5<br>
===============================================<br>
this is the output produced on my machine:<br>
torch:           1.1.0<br>
torchvisiion:    0.3.0</p>
<p>train_dataset[0][0]:    &lt;class ‘torch.Tensor’&gt;<br>
tensor([[[0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000,<br>
0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000],<br>
[0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000,<br>
0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000],<br>
[0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0078,<br>
0.0196, 0.0824, 0.1059, 0.0980, 0.1843, 0.0902, 0.0000, 0.0000],<br>
[0.0000, 0.0000, 0.0000, 0.0039, 0.0824, 0.2157, 0.3765, 0.5333,<br>
0.6118, 0.7373, 0.6627, 0.6196, 0.7647, 0.3020, 0.0000, 0.0000],<br>
[0.0000, 0.0000, 0.0000, 0.0118, 0.3804, 0.8549, 0.9294, 0.9569,<br>
0.8784, 0.9294, 0.4588, 0.2510, 0.2000, 0.0510, 0.0000, 0.0000],<br>
[0.0000, 0.0000, 0.0000, 0.0000, 0.1569, 0.4588, 0.7765, 0.7608,<br>
0.2353, 0.3137, 0.1412, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000],<br>
[0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0078, 0.4275, 0.6941,<br>
0.1137, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000],<br>
[0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0980, 0.6235,<br>
0.5647, 0.2627, 0.0235, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000],<br>
[0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0039, 0.2039,<br>
0.6549, 0.8039, 0.3490, 0.0392, 0.0000, 0.0000, 0.0000, 0.0000],<br>
[0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0039,<br>
0.0980, 0.5137, 0.8863, 0.3255, 0.0078, 0.0000, 0.0000, 0.0000],<br>
[0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0078, 0.0980,<br>
0.3373, 0.6667, 0.9608, 0.3882, 0.0078, 0.0000, 0.0000, 0.0000],<br>
[0.0000, 0.0000, 0.0000, 0.0000, 0.0039, 0.0627, 0.3294, 0.7098,<br>
0.9137, 0.8706, 0.5647, 0.1373, 0.0000, 0.0000, 0.0000, 0.0000],<br>
[0.0000, 0.0000, 0.0118, 0.0784, 0.3137, 0.5843, 0.8980, 0.8824,<br>
0.6235, 0.2667, 0.0510, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000],<br>
[0.0000, 0.0000, 0.2627, 0.7059, 0.9020, 0.8745, 0.7059, 0.2941,<br>
0.0510, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000],<br>
[0.0000, 0.0000, 0.1333, 0.2706, 0.2549, 0.1647, 0.0510, 0.0000,<br>
0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000],<br>
[0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000,<br>
0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000]]])</p>
<p>train_dataset[0][1]:    &lt;class ‘int’&gt;<br>
5</p>
</blockquote>
<p>===============================================<br>
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.</p>
<p>Please advise if this is an intentional change or a “bug”.</p>
<p>Regards,<br>
Jim</p>

username: jtlareau
cooked: <p>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?</p>

username: tom
cooked: <p>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.</p>
<p>Best regards</p>
<p>Thomas</p>

username: jtlareau
cooked: <p>Thank you, Thomas. That is what I was looking for.</p>
<p>Regards,</p>
<p>Jim</p>