batch_data_t = torch.FloatTensor(BATCH_SIZE, 1, 28, 28)
batch_targets_t = torch.LongTensor(BATCH_SIZE)
if cuda:
batch_data_t = batch_data_t.cuda()
batch_targets_t = batch_targets_t.cuda()
batch_data = Variable(batch_data_t, requires_grad=False)
batch_targets = Variable(batch_targets_t, requires_grad=False)
for i in range(0, training_data.size(0), BATCH_SIZE):
optimizer.zero_grad()
batch_data.data[:] = training_data[i:i+BATCH_SIZE]
After Change
batch_data, batch_targets = Variable(batch_data), Variable(batch_targets)
for i in range(0, training_data.size(0)-opt.batchSize+1, opt.batchSize):
start, end = i, i+opt.batchSize
optimizer.zero_grad()
batch_data.data[:] = training_data[start:end]
batch_targets.data[:] = training_labels[start:end]