Esempio n. 1
0
    def get_models(input_channels=train_ds.input_channels, seq_len=train_ds.seq_len,
                   pred_out_size=pred_target_values.shape[0], disc_out_size=disc_target_values.shape[0],
                   phys_cols=phys_cols, act_cols=act_cols):
        predictor = M.PredictorConv(input_channels=input_channels, seq_len=seq_len, output_size=pred_out_size,
                                    physNodes=phys_cols)
        #M.load_classifier_state2(predictor, "Predictor")
        predictor.to(DEVICE)
        pred_optim = M.get_optimizer(predictor,)

        discriminator = M.DiscriminatorConv(input_channels=input_channels, seq_len=seq_len, output_size=disc_out_size,
                                            physNodes=phys_cols+act_cols)
        #M.load_classifier_state2(discriminator,"Discriminator")
        discriminator.to(DEVICE)
        disc_optim = M.get_optimizer(discriminator,)
        return predictor, pred_optim, discriminator, disc_optim
Esempio n. 2
0
            accAct += np.abs((y == yp).data.numpy()).sum()
        except TypeError:
            accAct += np.abs((y.cpu() == yp.cpu()).data.numpy()).sum()
    accAct = accAct / test_ds.length
    print("Accuracy: {}".format(accAct))

    PredicActAccu.append(accAct)

    # Defining model Predicting activities.
    activities = np.unique(train_ds.sensitive)
    phys_shape = train_ds.phy_data.shape[1]

    #Parameters

    model = M.DiscriminatorConv(input_channels=train_ds.input_channels,
                                seq_len=train_ds.seq_len,
                                output_size=activities.shape[0],
                                physNodes=phys_shape)
    # Send model on GPU or CPU
    model.to(device)
    # Loss
    # loss = torch.nn.NLLLoss()
    # loss = Cl.NLLLoss()
    loss = Cl.BalancedErrorRateLoss(targetBer=0, device=device)
    # loss = Cl.AccuracyLoss(device=device)
    # Training procedure
    max_epochs = 200
    losses = []
    #t_key = "act"
    t_key = "sens"
    print("Starting Training")
    for i in tqdm.tqdm(range(max_epochs)):