I am trying to append a tensor list with the pixel values of MNIST dataset. However, I am unable to concatenate all the values of the pixels by a single loop. Is there a workaround this problem?
for i in range(10):
stacked_training = torch.stack([tensor(Image.open(o)) for o in (path_digit[i])]).float()/255
train_x = torch.cat([stacked_training]).view(-1, 28*28)
train_y_temp = tensor([i]*len(stacked_training))
train_y = torch.cat([train_y_temp])
print(f"Shape of training dataset for {i} is :", len(stacked_training))
Shape of training dataset for 0 is : 5923
Shape of training dataset for 1 is : 6742
Shape of training dataset for 2 is : 5958
Shape of training dataset for 3 is : 6131
Shape of training dataset for 4 is : 5842
Shape of training dataset for 5 is : 5421
Shape of training dataset for 6 is : 5918
Shape of training dataset for 7 is : 6265
Shape of training dataset for 8 is : 5851
Shape of training dataset for 9 is : 5949
As you can see in my code only the last loop values will be contained in the train_x and train_y. Is there a way to append the values of each loop or any other workaround this problem?