When I worked with Keras sometime back, it used to increase the training data. I don’t know if things have changed.



 my3bikaht:

but also what kind of augmentation


I don’t know if this will help me increase the training data. It would only return the transformed image and not multiple images. I have written a code and I was wondering if you can tell me if this is what you meant by running in loop here:



 my3bikaht:

run multiple training loops


    for epoch in range(num_epochs):
        running_loss_train = 0.0
        running_corrects_train, running_corrects_test = 0, 0
        for _ in tqdm(range(10)):
            # print('Epoch {}/{}'.format(epoch, num_epochs - 1))
            # print('-' * 10)
            # Each epoch has a training and validation phase
            model.train()  # Set model to training mode
            # Iterate over data.
            running_loss_aug = 0.0
            running_corrects_train_aug, running_corrects_test_aug = 0, 0
            for inputs, labels in (trainloader):
                inputs = inputs.cuda(0)
                labels = labels.cuda(1)
                # print(inputs, labels)
                # zero the parameter gradients
                optimizer.zero_grad()
                # forward
                # track history if only in train
                with torch.set_grad_enabled(True):
                    outputs = model(inputs)
                    # print(outputs)
                    
                    loss = criterion(outputs, labels)
                    # backward + optimize only if in training phase
                    loss.backward()
                    optimizer.step()
                # statistics
                running_loss_train += loss.item() * inputs.size(0)
                running_loss_aug += loss.item() * inputs.size(0)
                count=0
                for i in range(inputs.size(0)):
                    if(torch.argmax(outputs[i]) == torch.argmax(labels.data[i])):
                        count+=1
                running_corrects_train += count
                running_corrects_train_aug += count
            running_loss_aug = running_loss_aug / len(trainloader.dataset)
            running_corrects_train_aug = running_corrects_train_aug / len(trainloader.dataset)
            with torch.no_grad():
                model.eval()
                for inputs, labels in (testloader):

                    # Generate outputs
                    outputs = model(inputs)
                    count = 0
                    for i in range(inputs.size(0)):
                        if(torch.argmax(outputs[i]) == torch.argmax(labels.data[i])):
                            count+=1
                    running_corrects_test_aug += count
                    running_corrects_test += count
                epoch_acc_test = running_corrects_test_aug / len(testloader.dataset)
                acc_data_test.append(epoch_acc_test)
            # print('After each train: Train_Loss: {:.4f} Train_Acc: {:.4f} Test_Acc: {:.4f}'.format(
            #     running_loss_aug, running_corrects_train_aug, epoch_acc_test))
        scheduler.step()
        epoch_loss = running_loss_train / 20100.
        epoch_acc_train = running_corrects_train / 20100.
        epoch_acc_test = running_corrects_test / 20100
        loss_data_train.append(epoch_loss)
        acc_data_train.append(epoch_acc_train)