lbl package

Submodules

lbl.file_io module

class lbl.file_io.FileIO(cfg: dict, calib_reader: callable)[source]

Bases: object

Class for handling file input/output operations.

Args:

cfg (dict): Configuration dictionary. calib_reader (callable): Callable object for reading calibration data.

Attributes:

cfg (dict): Configuration dictionary. lbl_dir (str): Directory path for label files. lbl_type (str): Type of label files. lbl_count (int): Number of label files to process. lbl_ext (str): Extension of label files. reader (class): Handler class for reading label files. clb_reader (callable): Callable object for reading calibration data. files_basenames (list): List of file basenames. data_lock (threading.Lock): Lock for thread safety. data (list): List of tuples containing label file paths and annotations. stop (threading.Event): Event for stopping the async read thread.

Methods:

get_abs_path(idx: int) -> str: Returns the absolute path of the label file at the given index. __async_read_fn__(): Asynchronously reads label files and annotations. __len__() -> int: Returns the number of label files. __getitem__(idx) -> tuple: Returns the label file path and annotation at the given index. close(): Stops the async read thread.

close()[source]

Stops the async read thread.

get_abs_path(idx: int) str[source]

Returns the absolute path of the label file at the given index.

Args:

idx (int): Index of the label file.

Returns:

str: Absolute path of the label file.

lbl.handler_kitti module

lbl.handler_openpcdet module

lbl.handler_sustechpoints module

Module contents

The lbl package comprises handlers for reading label files. The file_io.py module should not be modified except for contributions to the framework application logic.

### Creating a New Label File Handler:

To create a new label file handler:

  1. Create a new Python file named handler_<lbl_type>.py in the calib directory.

  2. Replace <lbl_type> with the specific type of label file (e.g., kitti, coco, etc.).

  3. The lbl_type is passed from config.yml under data:label:lbl_type and is used to select the appropriate handler.

### Handler File Structure:

The handler_<lbl_type>.py file should contain the following elements:

  • colors: A dictionary mapping object categories to colors.

  • label_file_extension: A string specifying the file extension to look for.

  • Handler function: Reads the label file and returns a list of dictionaries representing the labels.

```python # hander_<lbl_type>.py

colors = {‘Car’: [1, 0, 0], ‘Pedestrian’: [0, 1, 0]} label_file_extension = ‘.txt’

def Handler(label_path: str, calib_data: dict):

‘’’ Args:

label_path (str): The path to the label file. calib_data (dict): Calibration data.

Returns:

list: A list of dictionaries representing the labels.

‘’’ import os

output = []

# Check if the label file exists if not os.path.exists(label_path):

return output

# Read the label file labels = [] with open(label_path, ‘r’) as f:

# read labels

for label in labels:

# extract label information

# Example extraction: # lidar_xyz_center = … # lidar_xyz_extent = … # lidar_xyz_euler_angles = np.array([x, y, z], dtype=np.float32) # lidar_bbox_color = np.array(colors[obj_class], dtype=np.float32) # this is in 0-1 range # rgb_bbox_color = np.array(colors[obj_class], dtype=np.float32) * 255.0 # Convert to 0-255 range

# Create a dictionary to store the lidar bounding box information label[‘lidar_bbox’] = {

# ‘lidar_xyz_center’: lidar_xyz_center, # ‘lidar_xyz_extent’: lidar_xyz_extent, # ‘lidar_xyz_euler_angles’: lidar_xyz_euler_angles, # ‘rgb_bbox_color’: lidar_bbox_color, ‘predicted’: False # as the label is ground truth and is read from file

}

# Append the label to the output list output.append(label)

return output # return the list of dictionaries representing the labels

```

Ensure that the Handler function reads the label file specified by label_path and returns the label data as a list of dictionaries. Each dictionary should contain information about the label, including the bounding box coordinates and object class.