MCPcopy Create free account
hub / github.com/NVlabs/CTG / sample

Method sample

tbsim/models/rasterized_models.py:1618–1631  ·  view source on GitHub ↗
(self, batch_inputs: dict, n: int)

Source from the content-addressed store, hash-verified

1616 return outs
1617
1618 def sample(self, batch_inputs: dict, n: int):
1619 pred_batch = self(batch_inputs,predict=True)
1620 dis_p = distributions.Categorical(probs=pred_batch["p"]) # [n_sample, batch] -> [batch, n_sample]
1621 z = dis_p.sample((n,)).permute(1, 2, 0)
1622 traj = pred_batch["x_recons"]["trajectories"]
1623 Na = traj.shape[-3]
1624 idx = z[:,:,:,None,None,None].repeat(1,1,1,*traj.shape[-3:])
1625 traj_selected = torch.gather(traj,2,idx)
1626 prob = torch.gather(pred_batch["p"],2,z)
1627
1628 outs = self._traj_to_preds(traj_selected)
1629 outs["p"] = prob
1630
1631 return outs
1632
1633 def predict(self, batch_inputs: dict):
1634 pred_batch = self(batch_inputs,predict=True,cond_traj=None)

Callers

nothing calls this directly

Calls 2

_traj_to_predsMethod · 0.95
sampleMethod · 0.45

Tested by

no test coverage detected