Esempio n. 1
0
    def _build_models(self):
        gpu_flag = torch.cuda.is_available()

        extractor = Extractor()
        classifier = Classifier()
        discriminator = Discrimimator()

        if gpu_flag:
            self.device = torch.device('cuda:0')
        else:
            self.device = torch.device('cpu')

        self.extractor = extractor.to(self.device)
        self.classifier = classifier.to(self.device)
        self.discriminator = discriminator.to(self.device)
Esempio n. 2
0
                                  batch_size=Batch_size_t,
                                  shuffle=True,
                                  num_workers=2)

source_training_loader_e = Data.DataLoader(dataset=source_training_dataset,
                                           batch_size=Batch_size_s,
                                           shuffle=True,
                                           num_workers=2)
target_loader_e = Data.DataLoader(dataset=target_dataset,
                                  batch_size=Batch_size_t,
                                  shuffle=True,
                                  num_workers=2)

#Training
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
E.to(device)
D.to(device)
R.to(device)
for epoch in range(num_epochs):
    print('Epoch:', epoch + 1, 'Training')
    # Evaluate Step
    if epoch % 3 == 0:
        # 1. Source_validation
        source_validation_loss, source_validation_error = evaluate(
            E, R, source_validation_loader, length_source_validation)
        # 2. Source_training
        source_training_loss, source_training_error = evaluate(
            E, R, source_training_loader_d, length_source_training)
        # 3. Target
        target_loss, target_error = evaluate(E, R, target_loader_d,
                                             length_target)