Ejemplo n.º 1
0
    def exc_train(self):
        # only import train staff in training env
        from train_util.data_set import generate_data_set, SiameseNetworkTrainDataSet
        from train_util.common_train import train
        from torch.utils.data import dataloader as DataLoader
        print("verify model start training")
        print(str(self))

        optimizer = torch.optim.Adam(self.parameters(), lr=LEARNING_RATE)
        lr_scheduler = torch.optim.lr_scheduler.ExponentialLR(
            optimizer=optimizer, gamma=0.1)

        batch_k = 48
        data_set = generate_data_set(0.06, SiameseNetworkTrainDataSet, batch_k)

        loss_func = ContrastiveLoss()

        data_loader = {
            'train':
            DataLoader.DataLoader(
                data_set['train'],
                shuffle=True,
                batch_size=BATCH_SIZE,
            ),
            'test':
            DataLoader.DataLoader(
                data_set['test'],
                shuffle=True,
            )
        }
        train(model=self,
              model_name='verify_68',
              EPOCH=EPOCH,
              optimizer=optimizer,
              exp_lr_scheduler=lr_scheduler,
              loss_func=loss_func,
              save_dir='./params',
              data_set=data_set,
              data_loader=data_loader,
              test_result_output_func=test_result_output,
              cuda_mode=1,
              print_inter=2,
              val_inter=25,
              scheduler_step_inter=50)
    def exc_train(self):
        # only import train staff in training env
        from train_util.data_set import generate_data_set, MyDataset
        from train_util.common_train import train
        print("CNN classify model start training")
        print(str(self))

        optimizer = torch.optim.Adam(self.parameters(),
                                     lr=LEARNING_RATE,
                                     weight_decay=WEIGHT_DECAY)
        loss_func = nn.CrossEntropyLoss()
        lr_scheduler = torch.optim.lr_scheduler.ExponentialLR(optimizer,
                                                              gamma=0.1)
        data_set = generate_data_set(0.06, MyDataset)
        data_loader = {
            'train':
            DataLoader.DataLoader(data_set['train'],
                                  shuffle=True,
                                  batch_size=BATCH_SIZE,
                                  num_workers=1),
            'test':
            DataLoader.DataLoader(data_set['test'],
                                  shuffle=True,
                                  batch_size=1,
                                  num_workers=1)
        }
        train(model=self,
              model_name='cnn_68',
              EPOCH=EPOCH,
              optimizer=optimizer,
              exp_lr_scheduler=lr_scheduler,
              loss_func=loss_func,
              save_dir='./params',
              data_set=data_set,
              data_loader=data_loader,
              test_result_output_func=test_result_output,
              cuda_mode=1,
              print_inter=2,
              val_inter=30,
              scheduler_step_inter=50)