I am new to pytorch and are trying to implement a feed forward neural network to classify the mnist data set. I have some problems when trying to use cross-validation. My data has the following shapes:
x_train
:
torch.Size([45000, 784])
and
y_train
: torch.Size([45000])
I tried to use KFold from sklearn.
kfold =KFold(n_splits=10)
Here is the first part of my train method where I'm dividing the data into folds:
for train_index, test_index in kfold.split(x_train, y_train):
x_train_fold = x_train[train_index]
x_test_fold = x_test[test_index]
y_train_fold = y_train[train_index]
y_test_fold = y_test[test_index]
print(x_train_fold.shape)
for epoch in range(epochs):
...
The indices for the y_train_fold
variable is right, it's simply:
[ 0 1 2 ... 4497 4498 4499]
, but it's not for x_train_fold
, which is [ 4500 4501 4502 ... 44997 44998 44999]
. And the same goes for the test folds.
For the first iteration I want the varibale x_train_fold
to be the first 4500 pictures, in other words to have the shape torch.Size([4500, 784])
, but it has the shape torch.Size([40500, 784])
Any tips on how to get this right?