# Part 1, Chapt 4 newbie question

I am trying to do Chapter 4 with the full MNIST set.

I did this to make my train_y and valid_y tensors:

train_y = tensor(*len(zeroes) +

``````            *len(ones) +

*len(twos) +

*len(threes) +

*len(fours) +

*len(fives) +

*len(sixes) +

*len(sevens) +

*len(eights) +

*len(nines)).unsqueeze(1)
``````

train_x.shape,train_y.shape

(torch.Size([60414, 784]), torch.Size([60000, 1]))

valid_x = torch.cat([valid_0_tens,

``````                 valid_1_tens,

valid_2_tens,

valid_4_tens,

valid_5_tens,

valid_6_tens,

valid_7_tens,

valid_8_tens,

valid_9_tens,

]).view(-1, 28*28)
``````

valid_y = tensor(*len(valid_0_tens) +

``````             *len(valid_1_tens) +

*len(valid_2_tens) +

*len(valid_3_tens) +

*len(valid_4_tens) +

*len(valid_5_tens) +

*len(valid_6_tens) +

*len(valid_7_tens) +

*len(valid_8_tens) +

*len(valid_9_tens)).unsqueeze(1)
``````

valid_dset = list(zip(valid_x,valid_y))

(torch.Size([8990, 784]), torch.Size([10000, 1]))

As you can see, the operation seemed to have “removed entries” (for lack of a better word) from train_x in making train_y, and likewise “added entries” to valid_x when making valid_y

Why is it either returning more or less entries in train_y then in train_x? As I understand it, it’s the exact same operation as in the tutorial proper with the same tensor shape so it shouldn’t change anything. I suspect there’s some kind of default limitations since the cutoff is so clean, but the pytorch documentation is not too illuminating. Any suggestions? I feel rather dumb for asking but I am stuck.

Hi and welcome! All I can say is the sizes of your target tensors are correct. MNIST has 60.000 training items and 10.000 validation items, that’s where the clean numbers come from, it’s not a PyTorch limitation.

Can you maybe share your notebook? It’s hard to tell where the error comes from.

2 Likes

Hi Johannes,
Yes absolutly:

Thank you for the assist

Found the errors When converting the images to tensors, you’re using the “seven” images for the “eight” tensors.

In the validation set, you missed the “threes”.

That should fix it. Maybe you can figure out a way to load the images in a loop instead of writing all the code by hand, which is just asking for trouble 2 Likes

It works ! and yeah ,loop does make a lot more sense

Thanks again ^_^.