Ejemplo n.º 1
0
    return initial_epoch


def train_log(*args, **kwargs):
    print(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S:"), *args,
          **kwargs)


if __name__ == '__main__':

    print("Dataset folder: ", args.train_data)

    # The only reason why I do this workaround (not necessary now) is because
    # I am thinking to the situation where one MPI process has multiple gpus available
    # In that case, the argument passed to get_gpu may be a numberID > 0
    available_device = get_gpu(0)

    # model selection
    print('===> Building model')
    model_classic = DnCNN()
    model_anderson = deepcopy(model_classic)

    # initial_epoch = findLastCheckpoint(save_dir=save_dir)  # load the last model in matconvnet style
    # criterion = nn.MSELoss(reduction = 'sum')  # PyTorch 0.4.1
    criterion = sum_squared_error()
    if cuda:
        print("Available device: ", available_device)
        model_classic.to(available_device)
        model_anderson.to(available_device)

    optimizer_classic = optim.Adam(model_classic.parameters(), lr=args.lr)
Ejemplo n.º 2
0
        for epoch in range(0, self.num_epochs):
            self.train_epoch(epoch)
            self.validation_epoch(epoch)
            
        return self.training_loss_history, self.training_accuracy_history, self.validation_loss_history, self.validation_accuracy_history

parser = argparse.ArgumentParser(description='PyTorch CIFAR10 Training')
parser.add_argument('--lr', default=0.1, type=float, help='learning rate')
parser.add_argument('--resume', '-r', action='store_true',
                    help='resume from checkpoint')
args = parser.parse_args()

# The only reason why I do this workaround (not necessary now) is because
# I am thinking to the situation where one MPI process has multiple gpus available
# In that case, the argument passed to get_gpu may be a numberID > 0
device = get_gpu(0)

best_acc = 0  # best test accuracy
start_epoch = 0  # start from epoch 0 or last checkpoint epoch

# Data
print('==> Preparing data..')
transform_train = transforms.Compose([
    transforms.RandomCrop(32, padding=4),
    transforms.RandomHorizontalFlip(),
    transforms.ToTensor(),
    transforms.Normalize((0.4914, 0.4822, 0.4465), (0.2023, 0.1994, 0.2010)),
])

transform_test = transforms.Compose([
    transforms.ToTensor(),