(self, batch_inputs: dict,predict=False,**kwargs)
| 1403 | |
| 1404 | |
| 1405 | def forward(self, batch_inputs: dict,predict=False,**kwargs): |
| 1406 | if batch_inputs["target_positions"].ndim==3: |
| 1407 | assert batch_inputs["target_positions"].shape[-2]>=self.stage*self.num_frames_per_stage |
| 1408 | bs,Na, = batch_inputs["all_other_agents_future_positions"].shape[:2] |
| 1409 | Na = Na+1 |
| 1410 | agent_avail = batch_inputs["agent_raster_availability"] |
| 1411 | device = agent_avail.device |
| 1412 | |
| 1413 | ego_traj = torch.cat((batch_inputs["target_positions"], batch_inputs["target_yaws"]), dim=-1) |
| 1414 | agent_traj = torch.cat((batch_inputs["all_other_agents_future_positions"], batch_inputs["all_other_agents_future_yaws"]), dim=-1) |
| 1415 | trajectories = torch.cat((ego_traj.unsqueeze(1),agent_traj),1) |
| 1416 | agent_avail = torch.cat((torch.ones([bs,1]).to(device),agent_avail),1) |
| 1417 | |
| 1418 | curr_yaw = torch.cat((batch_inputs["history_yaws"][:,0].unsqueeze(1),batch_inputs["all_other_agents_history_yaws"][:,:,0]),1) |
| 1419 | agent_from_world = torch.cat((batch_inputs["agent_from_world"].unsqueeze(1),batch_inputs["other_agents_agent_from_world"]),1).float() |
| 1420 | ego_to_agent = agent_from_world@(batch_inputs["world_from_agent"].float().unsqueeze(1)) |
| 1421 | agent_to_ego,_ = torch.linalg.inv_ex(ego_to_agent) |
| 1422 | agent_to_ego = agent_to_ego.nan_to_num(nan=0.0, posinf=0.0, neginf=0.0) |
| 1423 | num_agent = [agent_idx[i].shape[0] for i in range(bs)] |
| 1424 | |
| 1425 | elif batch_inputs["target_positions"].ndim==4: |
| 1426 | |
| 1427 | bs,Na, = batch_inputs["target_positions"].shape[:2] |
| 1428 | agent_avail = batch_inputs["agent_type"]>0 |
| 1429 | device = agent_avail.device |
| 1430 | trajectories = torch.cat((batch_inputs["target_positions"], batch_inputs["target_yaws"]), dim=-1) |
| 1431 | curr_yaw = batch_inputs["history_yaws"][:,:,-1] |
| 1432 | |
| 1433 | agent_from_world = batch_inputs["agents_from_center"]@(batch_inputs["agent_from_world"].unsqueeze(1))*agent_avail[...,None,None] |
| 1434 | ego_to_agent = batch_inputs["agents_from_center"]*agent_avail[...,None,None] |
| 1435 | agent_to_ego = batch_inputs["center_from_agents"]*agent_avail[...,None,None] |
| 1436 | num_agent = batch_inputs["num_agents"].tolist() |
| 1437 | |
| 1438 | agent_idx = [torch.where(agent_avail[i])[0] for i in range(bs)] |
| 1439 | |
| 1440 | H = self.num_frames_per_stage |
| 1441 | if self.algo_config.goal_conditional: |
| 1442 | if "goal" in kwargs and kwargs["goal"] is not None: |
| 1443 | goal = kwargs["goal"] |
| 1444 | else: |
| 1445 | goal = self._get_goal_states(batch_inputs) |
| 1446 | goal_pos = GeoUtils.batch_nd_transform_points(goal[...,:2],ego_to_agent) |
| 1447 | goal_yaw = goal[...,2:]-curr_yaw |
| 1448 | goal = torch.cat((goal_pos,goal_yaw),-1) |
| 1449 | else: |
| 1450 | goal = None |
| 1451 | if batch_inputs["image"].ndim==4: |
| 1452 | images = torch.cat((batch_inputs["image"].unsqueeze(1),batch_inputs["other_agents_image"]),dim=1) |
| 1453 | else: |
| 1454 | images = batch_inputs["image"] |
| 1455 | map_feat=self.map_encoder(TensorUtils.join_dimensions(images,0,2)).reshape(bs,Na,-1) |
| 1456 | curr_map_feat = map_feat |
| 1457 | preds = list() |
| 1458 | decoder_kwargs = dict() |
| 1459 | |
| 1460 | if "cond_traj" not in kwargs: |
| 1461 | if self.shuffle: |
| 1462 | cond_idx = [random.choice(agent_idx[i]) if num_agent[i]>1 else -1 for i in range(bs)] |
nothing calls this directly
no test coverage detected