This commit is contained in:
wassname
2020-02-15 07:22:14 +08:00
parent 4c10d0be7b
commit be30a40354
2 changed files with 11 additions and 8 deletions
+9 -7
View File
@@ -23,15 +23,19 @@ def collate_fns(max_num_context, max_num_extra_target, sample, sort=True):
x = torch.from_numpy(x).float()
y = torch.from_numpy(y).float()
x[:,:max_num_context, -1] = 0 # Feature to let the model know this is past data
x[:, :max_num_context, -1] = 0 # Feature to let the model know this is past data
n=x[:, max_num_context:, -1].shape[1]
x[:, max_num_context:, -1] = torch.arange(1, n+1)/1.0/n # Feature to let the model know this is past data
x_context = x[:, :max_num_context]
y_context = y[:, :max_num_context]
x_target_extra = x[:, max_num_context:]
y_target_extra = y[:, max_num_context:]
# x = x_target_extra # torch.cat([x_context, x_target_extra], 1)
# y = y_target_extra # torch.cat([y_context, y_target_extra], 1)
if sample:
x_target_extra = x[:, max_num_context:]
y_target_extra = y[:, max_num_context:]
# This is slightly differen't than normal, we are ensuring that our target point are in the future, to mimic deployment
x_context, y_context = npsample_batch(
@@ -42,14 +46,12 @@ def collate_fns(max_num_context, max_num_extra_target, sample, sort=True):
x_target_extra, y_target_extra, size=num_extra_target, sort=sort
)
x = torch.cat([x_context, x_target_extra], 1)
y = torch.cat([y_context, y_target_extra], 1)
assert (x_context[:, :, -1]==0).all()
assert (x[:, -1, -1] > 0).all()
assert (x[:, 0, -1] == 0).all()
# assert (x[:, 0, -1] == 0).all()
return x_context, y_context, x, y
return x_context, y_context, x_target_extra, y_target_extra
return collate_fn
+2 -1
View File
@@ -80,6 +80,7 @@ def plot_from_loader(
x_rows, y_rows = loader.dataset.get_rows(i)
max_num_context = context_x.shape[1]
y_context_rows = y_rows[:max_num_context]
y_target_rows = y_rows[max_num_context:]
dt = y_context_rows.index[0]
model.eval()
@@ -90,7 +91,7 @@ def plot_from_loader(
plt.figure()
plt.title(title + f" loss={loss_test: 2.2g} {dt}")
plot_rows(
y_rows,
y_target_rows,
y_context_rows,
y_pred.detach().cpu().numpy(),
y_std.detach().cpu().numpy(),