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
    train_dl = data.DataLoader(train_ds,
                               batch_size=batch_size,
                               shuffle=True,
                               num_workers=4)
    test_dl = data.DataLoader(test_ds,
                              batch_size=batch_size,
                              shuffle=True,
                              num_workers=4)

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

    model = M.PredictorConv(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"

    for i in tqdm.tqdm(range(max_epochs)):