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([
transforms.ToTensor(),
transforms.Normalize(mean=[0.5,],
std=[0.5,] )
])
data = datasets.ImageFolder(root=data_dir, transform= train_transforms)
from torch.utils.data import DataLoader
batch_size = 100
data_loader = DataLoader(data, batch_size, shuffle=True)
for img_batch, label_batch in data_loader:
print(‘first batch’)
print(img_batch.shape)
plt.imshow(img_batch[0][0], cmap=‘gray’)
print(label_batch)
break
‘’’
to display it is taking too much time.
secondly
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:
d_losses.append(d_loss.item())
g_losses.append(g_loss.item())
real_scores.append(real_score.mean().item())
fake_scores.append(fake_score.mean().item())
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
save_fake_images(epoch+1)
‘’’
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?