Debugging Validation and testing
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
from statistics import mean
|
||||
|
||||
from random import choice
|
||||
|
||||
import torch
|
||||
@@ -65,13 +67,12 @@ class CNNRouteGeneratorModel(LightningBaseModule):
|
||||
|
||||
def validation_epoch_end(self, outputs):
|
||||
evaluation = ROCEvaluation(plot_roc=True)
|
||||
predictions = torch.cat([x['prediction'] for x in outputs])
|
||||
pred_label = torch.cat([x['pred_label'] for x in outputs])
|
||||
labels = torch.cat([x['label'] for x in outputs]).unsqueeze(1)
|
||||
losses = torch.cat([x['discriminated_bce_loss'] for x in outputs]).unsqueeze(1)
|
||||
mean_losses = losses.mean()
|
||||
mean_losses = torch.stack([x['discriminated_bce_loss'] for x in outputs]).mean()
|
||||
|
||||
# Sci-py call ROC eval call is eval(true_label, prediction)
|
||||
roc_auc, tpr, fpr = evaluation(labels.cpu().numpy(), predictions.cpu().numpy(), )
|
||||
roc_auc, tpr, fpr = evaluation(labels.cpu().numpy(), pred_label.cpu().numpy(), )
|
||||
# self.logger.log_metrics(score_dict)
|
||||
self.logger.log_image(f'{self.name}_ROC-Curve_E{self.current_epoch}', plt.gcf())
|
||||
plt.clf()
|
||||
@@ -103,7 +104,7 @@ class CNNRouteGeneratorModel(LightningBaseModule):
|
||||
|
||||
# Dataset
|
||||
self.dataset = TrajData(self.hparams.data_param.map_root, mode='just_route',
|
||||
length=self.hparams.train_param.batch_size * 1000)
|
||||
length=self.hparams.data_param.dataset_length)
|
||||
|
||||
# Additional Attributes
|
||||
self.in_shape = self.dataset.map_shapes_max
|
||||
@@ -159,6 +160,10 @@ class CNNRouteGeneratorModel(LightningBaseModule):
|
||||
|
||||
self.traj_lin = nn.Linear(reduce(mul, self.traj_conv_3.shape), self.feature_dim)
|
||||
|
||||
#
|
||||
# Mixed Encoder
|
||||
self.mixed_lin = nn.Linear(self.lat_dim, self.lat_dim)
|
||||
|
||||
#
|
||||
# Variational Bottleneck
|
||||
self.mu = nn.Linear(self.lat_dim, self.hparams.model_param.lat_dim)
|
||||
@@ -242,7 +247,7 @@ class CNNRouteGeneratorModel(LightningBaseModule):
|
||||
return z, mu, logvar
|
||||
|
||||
def generate_random(self, n=6):
|
||||
maps = [self.map_storage[choice(self.map_storage.keys())] for _ in range(n)]
|
||||
maps = [self.map_storage[choice(self.map_storage.keys)] for _ in range(n)]
|
||||
trajectories = torch.stack([x.get_random_trajectory() for x in maps] * 2)
|
||||
maps = torch.stack([x.as_2d_array for x in maps] * 2)
|
||||
labels = torch.as_tensor([0] * n + [1] * n)
|
||||
|
||||
Reference in New Issue
Block a user