Example #1
0
# Initialize models
model_B = VRAEC(num_class=num_class,
                sequence_length=sequence_length_B,
                number_of_features=number_of_features_B,
                hidden_size=hidden_size,
                hidden_layer_depth=hidden_layer_depth,
                latent_length=latent_length,
                batch_size=batch_size,
                learning_rate=learning_rate,
                n_epochs=n_epochs,
                dropout_rate=dropout_rate,
                cuda=cuda,
                model_name=model_name_B,
                header=header_B,
                device=device)
model_B.to(device)

model_I = VRAEC(num_class=num_class,
                sequence_length=sequence_length_I,
                number_of_features=number_of_features_I,
                hidden_size=hidden_size,
                hidden_layer_depth=hidden_layer_depth,
                latent_length=latent_length,
                batch_size=batch_size,
                learning_rate=learning_rate,
                n_epochs=n_epochs,
                dropout_rate=dropout_rate,
                cuda=cuda,
                model_name=model_name_I,
                header=header_I,
                device=device)
Example #2
0
            hidden_layer_depth = hidden_layer_depth,
            latent_length = latent_length,
            batch_size = batch_size,
            learning_rate = learning_rate,
            n_epochs = n_epochs,
            dropout_rate = dropout_rate,
            cuda = cuda,
            print_every=print_every, 
            clip=clip, 
            max_grad_norm=max_grad_norm,
            dload = logDir,
            model_name=model_name,
            header=header,
            device = device)

model.to(device)


# In[7]:


criterion = nn.CrossEntropyLoss()
optimizer = optim.Adam(model.parameters(), lr=learning_rate)
cl_loss_fn = nn.NLLLoss()
recon_loss_fn = nn.MSELoss()


# In[8]:


# 1st stage training: with recon_loss
Example #3
0
                           cuda=cuda,
                           print_every=print_every,
                           clip=clip,
                           max_grad_norm=max_grad_norm,
                           dload=logDir,
                           model_name=model_name_B,
                           header=header_B,
                           device=device)
model_B_pretrained_dir = logDir + model_name_B + '.pt'
if device == torch.device('cpu'):
    model_B_pretrained.load_state_dict(
        torch.load(model_B_pretrained_dir, map_location=torch.device('cpu')))
else:
    model_B_pretrained.load_state_dict(torch.load(model_B_pretrained_dir))

model_B_pretrained.to(device)
model_B_pretrained.eval()

print("load model from")
print(model_name_B)

model_I = VRAEC(num_class=num_class,
                sequence_length=sequence_length_I,
                number_of_features=number_of_features_I,
                hidden_size=hidden_size,
                hidden_layer_depth=hidden_layer_depth,
                latent_length=latent_length,
                batch_size=batch_size,
                learning_rate=learning_rate,
                n_epochs=n_epochs,
                dropout_rate=dropout_rate,
                hidden_size=hidden_size,
                hidden_layer_depth=hidden_layer_depth,
                latent_length=latent_length,
                batch_size=batch_size,
                learning_rate=learning_rate,
                n_epochs=n_epochs,
                dropout_rate=dropout_rate,
                cuda=cuda,
                print_every=print_every,
                clip=clip,
                max_grad_norm=max_grad_norm,
                dload=logDir,
                model_name=model_name_B,
                header=header_B,
                device=device)
model_B.to(device)

model_I = VRAEC(num_class=num_class,
                sequence_length=sequence_length_I,
                number_of_features=number_of_features_I,
                hidden_size=hidden_size,
                hidden_layer_depth=hidden_layer_depth,
                latent_length=latent_length,
                batch_size=batch_size,
                learning_rate=learning_rate,
                n_epochs=n_epochs,
                dropout_rate=dropout_rate,
                cuda=cuda,
                print_every=print_every,
                clip=clip,
                max_grad_norm=max_grad_norm,
                batch_size=batch_size,
                learning_rate=learning_rate,
                n_epochs=n_epochs,
                dropout_rate=dropout_rate,
                cuda=cuda,
                print_every=print_every,
                clip=clip,
                max_grad_norm=max_grad_norm,
                dload=logDir,
                model_name=model_name_B,
                header=header_B,
                w_r=w_r,
                w_k=w_k,
                w_c=w_c,
                device=device)
model_B.to(device)

model_I = VRAEC(num_class=num_class,
                sequence_length=sequence_length_I,
                number_of_features=number_of_features_I,
                hidden_size=hidden_size,
                hidden_layer_depth=hidden_layer_depth,
                latent_length=latent_length,
                batch_size=batch_size,
                learning_rate=learning_rate,
                n_epochs=n_epochs,
                dropout_rate=dropout_rate,
                cuda=cuda,
                print_every=print_every,
                clip=clip,
                max_grad_norm=max_grad_norm,
model_B = VRAEC(num_class=num_class,
                sequence_length=sequence_length_B,
                number_of_features=number_of_features_B,
                hidden_size=hidden_size,
                hidden_layer_depth=hidden_layer_depth,
                latent_length=latent_length,
                batch_size=batch_size,
                learning_rate=learning_rate,
                n_epochs=n_epochs,
                dropout_rate=dropout_rate,
                cuda=cuda,
                model_name=model_name_B,
                header=header_B,
                device=device)
model_B.to(device)

model_I_pretrained = VRAEC(num_class=num_class,
                           sequence_length=sequence_length_I,
                           number_of_features=number_of_features_I,
                           hidden_size=hidden_size,
                           hidden_layer_depth=hidden_layer_depth,
                           latent_length=latent_length,
                           batch_size=batch_size,
                           learning_rate=learning_rate,
                           n_epochs=n_epochs,
                           dropout_rate=dropout_rate,
                           cuda=cuda,
                           model_name=model_name_I,
                           header=header_I,
                           device=device)