24from coverage_control 
import IOUtils
 
   26__all__ = [
"DataLoaderUtils"]
 
   32    Class to provide utility functions to load tensors and configuration files 
   36    def load_maps(path: str, use_comm_map: bool = 
False) -> torch.tensor:
 
   38        Function to load maps stored as tensors 
   40        The maps are stored as tensors in the following format: 
   41        - {path}/local_maps.pt: Local maps 
   42        - {path}/obstacle_maps.pt: Obstacle maps 
   43        - {path}/comm_maps.pt: Communication maps (if use_comm_map is True) 
   46            path (str): Path to the directory containing the maps 
   47            use_comm_map (bool): Whether to load the communication map 
   53        local_maps = IOUtils.load_tensor(f
"{path}/local_maps.pt")
 
   54        local_maps = local_maps.to_dense().unsqueeze(2)
 
   55        obstacle_maps = IOUtils.load_tensor(f
"{path}/obstacle_maps.pt")
 
   56        obstacle_maps = obstacle_maps.to_dense().unsqueeze(2)
 
   59            comm_maps = IOUtils.load_tensor(f
"{path}/comm_maps.pt")
 
   60            comm_maps = comm_maps.to_dense()
 
   62            maps = torch.cat([local_maps, comm_maps, obstacle_maps], 2)
 
   64            maps = torch.cat([local_maps, obstacle_maps], 2)
 
 
   70        path: str, output_dim: int = 
None 
   71    ) -> tuple[torch.tensor, torch.tensor, torch.tensor]:
 
   73        Function to load normalized features 
   75        The features are stored as tensors in the following format: 
   76        - {path}/normalized_coverage_features.pt: Normalized coverage features 
   77        - {path}/../coverage_features_mean.pt: Mean of the coverage features 
   78        - {path}/../coverage_features_std.pt: Standard deviation of the coverage features 
   81            path (str): Path to the directory containing the features 
   82            output_dim (int): Output dimension of the features 
   85            features: The loaded features 
   86            features_mean: Mean of the features 
   87            features_std: Standard deviation of the features 
   89        normalized_coverage_features = IOUtils.load_tensor(
 
   90            f
"{path}/normalized_coverage_features.pt" 
   92        coverage_features_mean = IOUtils.load_tensor(
 
   93            f
"{path}/../coverage_features_mean.pt" 
   95        coverage_features_std = IOUtils.load_tensor(
 
   96            f
"{path}/../coverage_features_std.pt" 
   99        if output_dim 
is not None:
 
  100            normalized_coverage_features = normalized_coverage_features[
 
  105            normalized_coverage_features,
 
  106            coverage_features_mean,
 
  107            coverage_features_std,
 
 
  111    def load_actions(path: str) -> tuple[torch.tensor, torch.tensor, torch.tensor]:
 
  113        Function to load normalized actions 
  115        The actions are stored as tensors in the following format: 
  116        - {path}/normalized_actions.pt: Normalized actions 
  117        - {path}/../actions_mean.pt: Mean of the actions 
  118        - {path}/../actions_std.pt: Standard deviation of the actions 
  121            path (str): Path to the directory containing the actions 
  124            actions: The loaded actions 
  125            actions_mean: Mean of the actions 
  126            actions_std: Standard deviation of the actions 
  129        actions = IOUtils.load_tensor(f
"{path}/normalized_actions.pt")
 
  130        actions_mean = IOUtils.load_tensor(f
"{path}/../actions_mean.pt")
 
  131        actions_std = IOUtils.load_tensor(f
"{path}/../actions_std.pt")
 
  133        return actions, actions_mean, actions_std
 
 
  138        Function to load robot positions 
  140        The robot positions are stored as tensors in the following format: 
  141        - {path}/robot_positions.pt: Robot positions 
  144            path (str): Path to the directory containing the robot positions 
  147            robot_positions: The loaded robot positions 
  150        robot_positions = IOUtils.load_tensor(f
"{path}/robot_positions.pt")
 
  152        return robot_positions
 
 
  157        Function to load edge weights 
  159        The edge weights are stored as tensors in the following format: 
  160        - {path}/edge_weights.pt: Edge weights 
  163            path (str): Path to the directory containing the edge weights 
  166            edge_weights: The loaded edge weights 
  169        edge_weights = IOUtils.load_tensor(f
"{path}/edge_weights.pt")
 
  170        edge_weights.to_dense()
 
 
  176        feature: torch.tensor, edge_weights: torch.tensor, pos: torch.tensor = 
None 
  177    ) -> torch_geometric.data.Data:
 
  179        The function converts the feature, edge_weights and pos to a torch_geometric.data.Data object 
  180        This is essential for using the data with the PyTorch Geometric library 
  183            feature (torch.tensor): The feature tensor 
  184            edge_weights (torch.tensor): The edge weights tensor 
  185            pos (torch.tensor): The position tensor 
  188            data: The torch_geometric.data.Data object 
  189            data.x: The feature tensor 
  190            data.edge_index: The edge index tensor 
  191            data.edge_weight: The edge weight tensor 
  192            data.pos: The position tensor (if pos is not None) 
  198        edge_weights = edge_weights.to_sparse()
 
  199        edge_weights = edge_weights.coalesce()
 
  200        edge_index = edge_weights.indices().long()
 
  201        weights = edge_weights.values().float()
 
  205            data = torch_geometric.data.Data(
 
  207                edge_index=edge_index.clone(),
 
  208                edge_weight=weights.clone(),
 
  211            data = torch_geometric.data.Data(
 
  213                edge_index=edge_index.clone(),
 
  214                edge_weight=weights.clone(),
 
 
 
Class to provide utility functions to load tensors and configuration files.
 
torch.tensor load_edge_weights(str path)
Function to load edge weights.
 
torch.tensor load_robot_positions(str path)
Function to load robot positions.
 
tuple[torch.tensor, torch.tensor, torch.tensor] load_actions(str path)
Function to load normalized actions.
 
torch_geometric.data.Data to_torch_geometric_data(torch.tensor feature, torch.tensor edge_weights, torch.tensor pos=None)
The function converts the feature, edge_weights and pos to a torch_geometric.data....
 
torch.tensor load_maps(str path, bool use_comm_map=False)
Function to load maps stored as tensors.
 
tuple[torch.tensor, torch.tensor, torch.tensor] load_features(str path, int output_dim=None)
Function to load normalized features.