To much time for loading data using data loader and Invalid for Input size error

I am loading custom data set from google drive and using google colab.

first of all it is taking so much time to exectue the code and secondly it throws an error in training loop.

code is below
data_dir = ‘…/content/gdrive/My Drive/digits_train_set’

train_transforms = transforms.Compose([
std=[0.5,] )

data = datasets.ImageFolder(root=data_dir, transform= train_transforms)

from import DataLoader

batch_size = 100

data_loader = DataLoader(data, batch_size, shuffle=True)

for img_batch, label_batch in data_loader:
print(‘first batch’)
plt.imshow(img_batch[0][0], cmap=‘gray’)

to display it is taking too much time.


in the training loop it is taking so much time and then throws the error

the code of the training loop


num_epochs = 10
total_step = len(data_loader)
d_losses, g_losses, real_scores, fake_scores = [], [], [], []

for epoch in range(num_epochs):
for i, (images, _) in enumerate(data_loader):
# Load a batch & transform to vectors
images = images.reshape(batch_size,-1).to(device)

    # Train the discriminator and generator
    d_loss, real_score, fake_score = train_discriminator(images)
    g_loss, fake_images = train_generator()
    # Inspect the losses
    if (i+1) % 200 == 0:
        print('Epoch [{}/{}], Step [{}/{}], d_loss: {:.4f}, g_loss: {:.4f}, D(x): {:.2f}, D(G(z)): {:.2f}' 
              .format(epoch, num_epochs, i+1, total_step, d_loss.item(), g_loss.item(), 
                      real_score.mean().item(), fake_score.mean().item()))
# Sample and save images


The error is shape ‘[100, -1]’ is invalid for input of size 14112

is that I am doing wrong with the data loader
The first batch size is torch.Size([100, 3, 28, 28])
and my input is according to that, where I am missing?

I change the following code and now it works fine

#images = images.reshape(batch_size,-1).to(device)
images = images.view(images.size(0), -1).to(device)