Ejemplo n.º 1
0
        model_dir = logDir + model_name_B + '.pt'
        print("Saving model at {} epoch to {}".format(epoch, model_dir))
        max_val_acc_B = val_accuracy_B
        torch.save(model_B.state_dict(), model_dir)

    if max_val_acc_I <= val_accuracy_I:
        model_dir = logDir + model_name_I + '.pt'
        print("Saving model at {} epoch to {}".format(epoch, model_dir))
        max_val_acc_I = val_accuracy_I
        torch.save(model_I.state_dict(), model_dir)

training_end = datetime.now()
training_time = training_end - training_start
print("RAE training takes time {}".format(training_time))

model_B.is_fitted = True
model_I.is_fitted = True

model_B.eval()
model_I.eval()

# TEST
correct_B = 0
correct_I = 0
test_num = 0

for i, (XI, XB, y) in enumerate(test_loader):
    XI, XB, y = XI.to(device), XB.to(device), y.long().to(device)

    if XI.size()[0] != batch_size:
        break
Ejemplo n.º 2
0
    # choose model
    if max_val_acc <= val_accuracy:
        model_dir = logDir + model_name + '.pt'
        print('Saving model at {} epoch to{}'.format(epoch, model_dir))
        max_val_acc = val_accuracy
        torch.save(model.state_dict(), model_dir)
        
training_end =  datetime.now()
training_time = training_end -training_start 
print("training takes time {}".format(training_time))


# In[9]:


model.is_fitted = True
model.eval()


# In[10]:


# testing set check
net_trained = VRAEC(num_class=num_class,
            sequence_length=sequence_length,
            number_of_features = number_of_features,
            hidden_size = hidden_size, 
            hidden_layer_depth = hidden_layer_depth,
            latent_length = latent_length,
            batch_size = batch_size,
            learning_rate = learning_rate,
        max_val_acc_B = val_accuracy_B
        torch.save(model_B.state_dict(), model_dir)

    if max_val_acc_I <= val_accuracy_I:
        model_dir = logDir + model_name_I + '.pt'
        print("Saving model at {} epoch to {}".format(epoch, model_dir))
        max_val_acc_I = val_accuracy_I
        torch.save(model_I.state_dict(), model_dir)

training_end = datetime.now()
training_time = training_end - training_start
print("RAE training takes time {}".format(training_time))

# In[ ]:

model_B.is_fitted = True
model_I.is_fitted = True

model_B.eval()
model_I.eval()

# model_B_trained = 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,
Ejemplo n.º 4
0
    #         max_val_acc_B = val_accuracy_B
    #         torch.save(model_B.state_dict(), model_dir)

    if max_val_acc_I <= val_accuracy_I:
        model_dir = logDir + model_name_I + '.pt'
        print("Saving model at {} epoch to {}".format(epoch, model_dir))
        max_val_acc_I = val_accuracy_I
        torch.save(model_I.state_dict(), model_dir)

training_end = datetime.now()
training_time = training_end - training_start
print("RAE training takes time {}".format(training_time))

# In[8]:

model_B_pretrained.is_fitted = True
model_I.is_fitted = True

model_B_pretrained.eval()
model_I.eval()

# In[9]:

# TEST
correct_B = 0
correct_I = 0
test_num = 0

for i, (XI, XB, y) in enumerate(test_loader):
    XI, XB, y = XI.to(device), XB.to(device), y.long().to(device)
    # TODO: not save at the same time, may have bad common representation
    if max_val_acc_B <= val_accuracy_B:
        model_dir = logDir + model_name_B + '.pt'
        print("Saving model at {} epoch to {}".format(epoch, model_dir))
        max_val_acc_B = val_accuracy_B
        torch.save(model_B.state_dict(), model_dir)

    if max_val_acc_I <= val_accuracy_I:
        model_dir = logDir + model_name_I + '.pt'
        print("Saving model at {} epoch to {}".format(epoch, model_dir))
        max_val_acc_I = val_accuracy_I
        torch.save(model_I.state_dict(), model_dir)

# In[10]:

model_B.is_fitted = True
model_I.is_fitted = True

model_B.eval()
model_I.eval()

# model_B_trained = 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,