Skip to content

Commit

Permalink
Fix a bug with the velocity loss
Browse files Browse the repository at this point in the history
It mixed up dimensions: since the first dimension was index in a batch but
not time, the loss was actually calculating the distance between two
sequences in a batch
  • Loading branch information
Svito-zar committed Oct 5, 2020
1 parent 391466b commit 1164222
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions gesticulator/model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

warnings.filterwarnings("ignore")
torch.set_default_tensor_type('torch.FloatTensor')
torch.autograd.set_detect_anomaly(True)

def weights_init_he(m):
"""Initialize the given linear layer using He initialization."""
Expand Down Expand Up @@ -387,16 +388,16 @@ def tr_loss(self, y_hat, y):
"""

# calculate corresponding speed
pred_speed = y_hat[1:] - y_hat[:-1]
actual_speed = y[1:] - y[:-1]
pred_speed = y_hat[:,1:] - y_hat[:,:-1]
actual_speed = y[:,1:] - y[:,:-1]
vel_loss = self.loss(pred_speed, actual_speed)

return [self.loss(y_hat, y), vel_loss * self.hparams.vel_coef]

def val_loss(self, y_hat, y):
# calculate corresponding speed
pred_speed = y_hat[1:] - y_hat[:-1]
actual_speed = y[1:] - y[:-1]
pred_speed = y_hat[:,1:] - y_hat[:,:-1]
actual_speed = y[:,1:] - y[:,:-1]

return self.loss(pred_speed, actual_speed)

Expand Down

1 comment on commit 1164222

@Svito-zar
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quite an important bug. Issue #10 is devoted to it.

Please sign in to comment.