nicetoolbox.detectors.data¶
Data module handling the data loading and processing of the give datasets.
Classes
A data class for loading and processing data. |
- class nicetoolbox.detectors.data.Data(config, io, data_formats, all_camera_names, all_dataset_names)[source]¶
A data class for loading and processing data.
- name¶
The name of the data.
- Type:
str
- data_folder¶
The folder path for the data.
- Type:
str
- tmp_folder¶
The folder path for temporary files.
- Type:
str
- code_folder¶
The folder path for code files.
- Type:
str
- data_input_folder¶
The folder path for input data.
- Type:
str
- session_ID¶
The session ID.
- Type:
str
- sequence_ID¶
The sequence ID.
- Type:
str
- video_length¶
The length of the video.
- Type:
int
- video_start¶
The starting frame of the video.
- Type:
int
- video_skip_frames¶
The number of frames to skip in the video.
- Type:
int or None
- annotation_interval¶
The time interval for segments.
- Type:
float
- subjects_descr¶
The description of the subjects.
- Type:
str
- camera_mapping¶
The mapping of camera names.
- Type:
dict
- data_formats¶
The list of data formats required.
- Type:
list
- all_camera_names¶
The list of all camera names.
- Type:
list
- segments_list¶
The list of data segments.
- Type:
None or list
- frames_list¶
The list of frames.
- Type:
None or list
- frame_indices_list¶
The list of frame indices.
- Type:
None or list
- snippets_list¶
The list of snippets.
- Type:
None or list
- calibration¶
The camera calibration.
- Type:
dict
- fps¶
The frames per second of the input video files.
- Type:
int
Initialize the Data class.
- Parameters:
config (dict) – The configuration dictionary.
io (IO) – The IO object for file and folder operations.
data_formats (list) – The list of data formats required.
all_camera_names (list) – The list of all camera names.
- Returns:
None
- create_inputs_from_frames(input_format)[source]¶
Processes frames and organizes them into specified data formats for further processing in the NICE pipeline.
This method iterates through all camera names, and for each camera, it performs the following operations based on the given data formats:
1. Frames: For each frame in the specified range, it checks if the frame exists in the input directory. If it does, the method creates a symbolic link in the output directory under a ‘frames’ subdirectory.
2. Segments: (Not Implemented) This part is intended to split the video into segments of a specified length based on the annotation interval.
3. Snippets: (Not Implemented) This part is intended to cut the video into snippets based on the specified start and length.
- Parameters:
input_format (str) – The file format of the input frames (e.g., ‘jpg’, ‘png’).
- Raises:
NotImplementedError – If the filename convention inferred from the first
frame's filename does not apply to any frame or if the 'segments' or –
'snippets' data formats are specified, as these are not implemented. –
- create_inputs_from_video()[source]¶
Create inputs from video files.
This method detects video input files, splits them into frames, and organizes the frames into different data formats which are frames, segments, and snippets.
- Raises:
AssertionError – If the length of the frame indices list does not match the specified video length.
AssertionError – If the frame indices of different cameras do not match.
- data_initialization()[source]¶
Initializes the data required for running NICE toolbox.
This method performs the following steps: 1. Determines the input format based on the available camera names. 2. Creates a list of all input files required to run NICE toolbox. 3. Checks whether all required data files exist. 4. Initializes data lists for frames, segments, and snippets. 5. If the data exists, extracts frame indices and organizes frames by camera
name.
If the data does not exist, creates the required data from video or frames.
Logs the completion of data creation.
- get_fps(config_fps)[source]¶
Get the frames per second (fps) of the input video files.
- Parameters:
config_fps (int) – The desired fps specified in the configuration.
- Returns:
- The fps of the input video files. If the input formats are not ‘mp4’
or ‘avi’, the config_fps value is returned.
- Return type:
int
- get_inference_path(component_name, detector_name)[source]¶
Get the file path for the inference script of a given detector.
- Parameters:
detector_name (str) – The name of the detector.
- Returns:
The file path for the inference script.
- Return type:
str
- Raises:
FileNotFoundError – If the inference script file does not exist.
- get_input_format(camera_names)[source]¶
Get the input format for the given camera names.
- Parameters:
camera_names (list) – A list of camera names.
- Returns:
The input format for the given camera names.
- Return type:
str
- Raises:
ValueError – If multiple or no valid input format is found in the data
input folder. –
- get_inputs_list(input_format, data_format, camera_names)[source]¶
Returns a list of input file paths based on the specified input format, data format, and camera names.
- Parameters:
input_format (str) – The format of the input files.
data_format (str) – The format/type of the video data. One of snippets, segments, or frames.
camera_names (list) – A list of camera names.
- Returns:
A list of input file paths.
- Return type:
list
- get_venv_path(detector_name, env_name)[source]¶
Get the file path of the virtual environment for the given detector and environment name.
- Parameters:
detector_name (str) – The name of the detector.
env_name (str) – The name of the environment.
- Returns:
The file path of the virtual environment.
- Return type:
str
- Raises:
FileNotFoundError – If the virtual environment does not exist.
- load_calibration(calibration_file, dataset_name, all_dataset_names)[source]¶
Load camera calibration from a file for a specific dataset.
Currently implemented for the datasets ‘dyadic_communication’ and ‘mpi_inf_3dhp’.
- Parameters:
calibration_file (str) – The path to the calibration file.
dataset_name (str) – The name of the dataset.
- Returns:
A dictionary containing the loaded camera calibration.
- Return type:
dict
- Raises:
NotImplementedError – If loading camera calibration for the specified
dataset is not implemented. –