evlib.dataloaders¶
Low level data loaders for event camera datasets.
- class evlib.dataloaders.DSECDataLoader(root, sequence, split='train', camera='left', load_images=False, load_flow_forward=False, load_flow_backward=False, load_disparity=False, load_imu=False, load_lidar=False, load_calibration=False, load_rectify_map=True, event_load_mode='lazy', prerectify_events=False)¶
Low level I/O for a single DSEC sequence.
The expected root contains DSEC sequence directories, either directly as produced by the multi-sequence ZIP archives, or grouped by split such as
train/<sequence>/events/left/events.h5andtest/<sequence>/images/left/rectified/*.png. Passing a split directory itself, such as/path/to/DSEC/train, is also supported. Passing the sequence directory itself is supported when its basename matchessequence.By default events are returned in raw sensor coordinates and
rectify_events()is an explicit per slice call. Passprerectify_events=Truewithevent_load_mode="cached"to rectify the cached event arrays once at init. Subsequentload_events()calls then return pre rectified data andrectify_events()is idempotent.All public timestamps are in seconds (float64).
load_frame_sampleuses forward flow intervals when forward flow is loaded, otherwise it spans consecutive image timestamps. Images are selected by nearest timestamp at the sample start/end, disparity by nearest timestamp at the sample end, and backward flow by matching the same anchor timestamp as the sample start.- Parameters:
root (str) – Root directory containing the DSEC dataset, a directory of sequence folders, a split directory such as
/path/to/DSEC/train, or the sequence directory itself.sequence (str) – Sequence name (e.g.
"zurich_city_01_a").split (DSECSplit) – Dataset split,
"train"or"test".camera (DSECCamera) – Event camera side,
"left"or"right".load_images (LoadMode) – LoadMode for rectified frame camera images.
load_flow_forward (LoadMode) – LoadMode for forward optical flow GT.
load_flow_backward (LoadMode) – LoadMode for backward optical flow GT.
load_disparity (LoadMode) – LoadMode for disparity maps.
load_imu (LoadMode) – LoadMode for IMU samples from
data/<drive_prefix>/lidar_imu.bag.load_lidar (LoadMode) – LoadMode for Velodyne point clouds from
data/<drive_prefix>/lidar_imu.bag.load_calibration (bool) – If True, load
cam_to_cam.yamlcalibration.load_rectify_map (bool) – If True, load event rectification map from HDF5.
event_load_mode (ResidentLoadMode) –
"lazy"to keep HDF5 open and read on demand (default), or"cached"to load all events into RAM.prerectify_events (bool) – If True (cached mode only), rectify + filter the cached event arrays at init so per call rectification is free. Requires
event_load_mode="cached"andload_rectify_map=True. With this flag,rectify_events()becomes idempotent so downstream code does not need to branch on mode.
- load_events(start_index, end_index)¶
Load events in
[start_index, end_index). Returns mutable copies.
- time_to_index(t)¶
Find the last event index strictly before time t (seconds).
- index_to_time(index)¶
Return the timestamp (absolute seconds) of event at index.
- times_to_indices(timestamps)¶
Vectorized
time_to_index().
- indices_to_times(indices)¶
Vectorized
index_to_time().
- get_events_by_time(t_start, t_end)¶
Load events whose timestamps fall in
[t_start, t_end).
- close()¶
Release open file handles and drop small lazy decode caches.
- Return type:
None
- property t_offset: int64¶
Temporal offset in microseconds added to raw event timestamps.
- property ms_to_idx: ndarray[Any, dtype[int64]]¶
Millisecond to event index lookup table.
ms_to_idx[ms]gives the first event index whose timestamp is >=ms * 1000microseconds (relative tot_offset).
- property event_load_mode: LoadingType¶
Configured event loading mode.
- property events_prerectified: bool¶
Whether cached events were prerectified at init.
When True,
load_eventsreturns rectified event coordinates andrectify_events()is idempotent.
- property rectify_map: ndarray[Any, dtype[float32]] | None¶
Event rectification map
(H, W, 2)or None.
- rectify_events(events)¶
Apply the DSEC event rectification map.
Returns a new
RawEventswith rectified coordinates. Events whose raw coordinates are outside the DSEC sensor bounds, or whose rectified pixel falls outside the sensor, are dropped.If the loader was constructed with
prerectify_events=Truethe input is returned unchanged.- Raises:
RuntimeError – If the rectification map is not loaded.
- Parameters:
events (RawEvents)
- Return type:
- property image_timestamps: ndarray[Any, dtype[float64]] | None¶
Image timestamps in seconds, or None.
- property image_exposure_timestamps: ndarray[Any, dtype[float64]] | None¶
Image exposure intervals
(N, 2)in seconds, or None.
- load_image(index)¶
Load a single image by index.
Returns an
(H, W)or(H, W, C)uint8 array. Cached mode returns a view into the preloaded stack. Lazy mode decodes from disk with a small LRU over recent indices.
- find_nearest_image_index(t)¶
Return the image index nearest to time t (in seconds).
- property flow_forward_timestamps: ndarray[Any, dtype[float64]] | None¶
Forward flow timestamps
(N, 2)in seconds, or None.
- property flow_backward_timestamps: ndarray[Any, dtype[float64]] | None¶
Backward flow timestamps
(N, 2)in seconds, or None.
- load_flow_forward(index)¶
Load a single forward optical flow field by index.
- load_flow_backward(index)¶
Load a single backward optical flow field by index.
- property disparity_timestamps: ndarray[Any, dtype[float64]] | None¶
Disparity timestamps in seconds, or None.
- load_disparity(index)¶
Load a single disparity map by index.
- Returns:
(H, W)float32. valid:(H, W)bool validity mask.- Return type:
disparity
- Parameters:
index (int)
- property imu_timestamps: ndarray[Any, dtype[float64]] | None¶
IMU sample timestamps in seconds, or None.
- load_imu(t_start, t_end)¶
Load IMU samples whose timestamps fall in
[t_start, t_end).
- property lidar_timestamps: ndarray[Any, dtype[float64]] | None¶
Return LiDAR scan timestamps in seconds, or None.
- iter_events(num_events=None, time_window=None)¶
Yield class RawEvents chunks.
Exactly one of num_events or time_window must be given.
- Parameters:
- Raises:
ValueError – If neither or both arguments are given, or if the given value is not positive.
- Return type:
- load_lidar(index)¶
Load one Velodyne scan by index.
The returned
pointsarray is a compact structured NumPy array using the PointCloud2 field names and dtypes, commonlyx,y,z,intensity,ring, andtimefor DSEC.- Parameters:
index (int)
- Return type:
DSECLidarScan
- load_lidar_by_time(t_start, t_end)¶
Load LiDAR scans whose timestamps fall in
[t_start, t_end).
- property calibration: dict[str, Any] | None¶
Parsed calibration YAML dict, or None.
A deep copy is returned so callers cannot mutate process global calibration cache entries shared by later loader instances.
- property cam_to_lidar_calibration: dict[str, Any] | None¶
Parsed
data/<drive_prefix>/cam_to_lidar.yamldict, or None.
- property cam_to_imu_calibration: dict[str, Any] | None¶
Parsed
imu_calibration/cam0_to_imu0.yamldict, or None.
- property imu_calibration: dict[str, Any] | None¶
Parsed
imu_calibration/imu0_params.yamldict, or None.
- property num_samples: int¶
Number of iterable samples.
Returns
num_flow_forwardif flow is loaded, elsenum_images - 1if images are loaded (each sample spans two consecutive images), else 0.
- load_frame_sample(index)¶
Load a synchronized sample dict for the given index.
The sample time interval is taken from the forward flow timestamps file (if loaded) or from consecutive image timestamps. Per the DSEC documentation,
forward[k] = (t_k, t_{k+1})andbackward[k] = (t_k, t_{k-1})are both anchored att_k. Backward flow is associated with the sample by matching its anchor (t_start) to the sample’st_startrather than by reusingindex.flow_backwardisNonewhen no backward entry shares the anchor. Backward coverage can be a strict subset of forward coverage.- Parameters:
index (int)
- Return type:
DSECSample
- class evlib.dataloaders.DataLoaderBase¶
ABC for low level event data I/O
Subclasses implement the abstract methods for a specific file format or data source. The concrete convenience methods are built on top of the abstract primitives.
- abstractmethod load_events(start_index, end_index)¶
Load events in [start_index, end_index).
- abstractmethod time_to_index(t)¶
Find the index of the last event strictly before time t.
May return -1 if no event precedes t.
- abstractmethod index_to_time(index)¶
Return the timestamp of the event at index.
- times_to_indices(timestamps)¶
Vectorized form of
time_to_index().Subclasses may override this for a more efficient implementation.
- indices_to_times(indices)¶
Vectorized form of
index_to_time().Subclasses may override this for a more efficient implementation.
- abstractmethod close()¶
Release resources (e.g. file handles, etc.).
- Return type:
None
- get_events_by_time(t_start, t_end)¶
Load events whose timestamps fall in [t_start, t_end).
- iter_events(num_events=None, time_window=None)¶
Yield class RawEvents chunks.
Exactly one of num_events or time_window must be given.
- Parameters:
- Raises:
ValueError – If neither or both arguments are given, or if the given value is not positive.
- Return type:
- class evlib.dataloaders.LoadingType(value)¶
internal loading state for dataset modalities.
- OFF = 'off'¶
- LAZY = 'lazy'¶
- CACHED = 'cached'¶
- classmethod from_value(value, *, name='loading type')¶
- Parameters:
- Return type:
- classmethod from_resident_value(value, *, name)¶
- Parameters:
- Return type:
- encode(encoding='utf-8', errors='strict')¶
Encode the string using the codec registered for encoding.
- encoding
The encoding in which to encode the string.
- errors
The error handling scheme to use for encoding errors. The default is ‘strict’ meaning that encoding errors raise a UnicodeEncodeError. Other possible values are ‘ignore’, ‘replace’ and ‘xmlcharrefreplace’ as well as any other name registered with codecs.register_error that can handle UnicodeEncodeErrors.
- replace(old, new, count=-1, /)¶
Return a copy with all occurrences of substring old replaced by new.
- count
Maximum number of occurrences to replace. -1 (the default value) means replace all occurrences.
If the optional argument count is given, only the first count occurrences are replaced.
- split(sep=None, maxsplit=-1)¶
Return a list of the substrings in the string, using sep as the separator string.
- sep
The separator used to split the string.
When set to None (the default value), will split on any whitespace character (including n r t f and spaces) and will discard empty strings from the result.
- maxsplit
Maximum number of splits. -1 (the default value) means no limit.
Splitting starts at the front of the string and works to the end.
Note, str.split() is mainly useful for data that has been intentionally delimited. With natural text that includes punctuation, consider using the regular expression module.
- rsplit(sep=None, maxsplit=-1)¶
Return a list of the substrings in the string, using sep as the separator string.
- sep
The separator used to split the string.
When set to None (the default value), will split on any whitespace character (including n r t f and spaces) and will discard empty strings from the result.
- maxsplit
Maximum number of splits. -1 (the default value) means no limit.
Splitting starts at the end of the string and works to the front.
- join(iterable, /)¶
Concatenate any number of strings.
The string whose method is called is inserted in between each given string. The result is returned as a new string.
Example: ‘.’.join([‘ab’, ‘pq’, ‘rs’]) -> ‘ab.pq.rs’
- capitalize()¶
Return a capitalized version of the string.
More specifically, make the first character have upper case and the rest lower case.
- casefold()¶
Return a version of the string suitable for caseless comparisons.
- title()¶
Return a version of the string where each word is titlecased.
More specifically, words start with uppercased characters and all remaining cased characters have lower case.
- center(width, fillchar=' ', /)¶
Return a centered string of length width.
Padding is done using the specified fill character (default is a space).
- count(sub[, start[, end]]) int¶
Return the number of non-overlapping occurrences of substring sub in string S[start:end]. Optional arguments start and end are interpreted as in slice notation.
- expandtabs(tabsize=8)¶
Return a copy where all tab characters are expanded using spaces.
If tabsize is not given, a tab size of 8 characters is assumed.
- find(sub[, start[, end]]) int¶
Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end]. Optional arguments start and end are interpreted as in slice notation.
Return -1 on failure.
- partition(sep, /)¶
Partition the string into three parts using the given separator.
This will search for the separator in the string. If the separator is found, returns a 3-tuple containing the part before the separator, the separator itself, and the part after it.
If the separator is not found, returns a 3-tuple containing the original string and two empty strings.
- index(sub[, start[, end]]) int¶
Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end]. Optional arguments start and end are interpreted as in slice notation.
Raises ValueError when the substring is not found.
- ljust(width, fillchar=' ', /)¶
Return a left-justified string of length width.
Padding is done using the specified fill character (default is a space).
- lower()¶
Return a copy of the string converted to lowercase.
- lstrip(chars=None, /)¶
Return a copy of the string with leading whitespace removed.
If chars is given and not None, remove characters in chars instead.
- rfind(sub[, start[, end]]) int¶
Return the highest index in S where substring sub is found, such that sub is contained within S[start:end]. Optional arguments start and end are interpreted as in slice notation.
Return -1 on failure.
- rindex(sub[, start[, end]]) int¶
Return the highest index in S where substring sub is found, such that sub is contained within S[start:end]. Optional arguments start and end are interpreted as in slice notation.
Raises ValueError when the substring is not found.
- rjust(width, fillchar=' ', /)¶
Return a right-justified string of length width.
Padding is done using the specified fill character (default is a space).
- rstrip(chars=None, /)¶
Return a copy of the string with trailing whitespace removed.
If chars is given and not None, remove characters in chars instead.
- rpartition(sep, /)¶
Partition the string into three parts using the given separator.
This will search for the separator in the string, starting at the end. If the separator is found, returns a 3-tuple containing the part before the separator, the separator itself, and the part after it.
If the separator is not found, returns a 3-tuple containing two empty strings and the original string.
- splitlines(keepends=False)¶
Return a list of the lines in the string, breaking at line boundaries.
Line breaks are not included in the resulting list unless keepends is given and true.
- strip(chars=None, /)¶
Return a copy of the string with leading and trailing whitespace removed.
If chars is given and not None, remove characters in chars instead.
- swapcase()¶
Convert uppercase characters to lowercase and lowercase characters to uppercase.
- translate(table, /)¶
Replace each character in the string using the given translation table.
- table
Translation table, which must be a mapping of Unicode ordinals to Unicode ordinals, strings, or None.
The table must implement lookup/indexing via __getitem__, for instance a dictionary or list. If this operation raises LookupError, the character is left untouched. Characters mapped to None are deleted.
- upper()¶
Return a copy of the string converted to uppercase.
- startswith(prefix[, start[, end]]) bool¶
Return True if S starts with the specified prefix, False otherwise. With optional start, test S beginning at that position. With optional end, stop comparing S at that position. prefix can also be a tuple of strings to try.
- endswith(suffix[, start[, end]]) bool¶
Return True if S ends with the specified suffix, False otherwise. With optional start, test S beginning at that position. With optional end, stop comparing S at that position. suffix can also be a tuple of strings to try.
- removeprefix(prefix, /)¶
Return a str with the given prefix string removed if present.
If the string starts with the prefix string, return string[len(prefix):]. Otherwise, return a copy of the original string.
- removesuffix(suffix, /)¶
Return a str with the given suffix string removed if present.
If the string ends with the suffix string and that suffix is not empty, return string[:-len(suffix)]. Otherwise, return a copy of the original string.
- isascii()¶
Return True if all characters in the string are ASCII, False otherwise.
ASCII characters have code points in the range U+0000-U+007F. Empty string is ASCII too.
- islower()¶
Return True if the string is a lowercase string, False otherwise.
A string is lowercase if all cased characters in the string are lowercase and there is at least one cased character in the string.
- isupper()¶
Return True if the string is an uppercase string, False otherwise.
A string is uppercase if all cased characters in the string are uppercase and there is at least one cased character in the string.
- istitle()¶
Return True if the string is a title-cased string, False otherwise.
In a title-cased string, upper- and title-case characters may only follow uncased characters and lowercase characters only cased ones.
- isspace()¶
Return True if the string is a whitespace string, False otherwise.
A string is whitespace if all characters in the string are whitespace and there is at least one character in the string.
- isdecimal()¶
Return True if the string is a decimal string, False otherwise.
A string is a decimal string if all characters in the string are decimal and there is at least one character in the string.
- isdigit()¶
Return True if the string is a digit string, False otherwise.
A string is a digit string if all characters in the string are digits and there is at least one character in the string.
- isnumeric()¶
Return True if the string is a numeric string, False otherwise.
A string is numeric if all characters in the string are numeric and there is at least one character in the string.
- isalpha()¶
Return True if the string is an alphabetic string, False otherwise.
A string is alphabetic if all characters in the string are alphabetic and there is at least one character in the string.
- isalnum()¶
Return True if the string is an alpha-numeric string, False otherwise.
A string is alpha-numeric if all characters in the string are alpha-numeric and there is at least one character in the string.
- isidentifier()¶
Return True if the string is a valid Python identifier, False otherwise.
Call keyword.iskeyword(s) to test whether string s is a reserved identifier, such as “def” or “class”.
- isprintable()¶
Return True if the string is printable, False otherwise.
A string is printable if all of its characters are considered printable in repr() or if it is empty.
- zfill(width, /)¶
Pad a numeric string with zeros on the left, to fill a field of the given width.
The string is never truncated.
- format(*args, **kwargs) str¶
Return a formatted version of S, using substitutions from args and kwargs. The substitutions are identified by braces (‘{’ and ‘}’).
- format_map(mapping) str¶
Return a formatted version of S, using substitutions from mapping. The substitutions are identified by braces (‘{’ and ‘}’).
- static maketrans()¶
Return a translation table usable for str.translate().
If there is only one argument, it must be a dictionary mapping Unicode ordinals (integers) or characters to Unicode ordinals, strings or None. Character keys will be then converted to ordinals. If there are two arguments, they must be strings of equal length, and in the resulting dictionary, each character in x will be mapped to the character at the same position in y. If there is a third argument, it must be a string, whose characters will be mapped to None in the result.
- class evlib.dataloaders.MVSECDataLoader(root, sequence, camera='left', load_gt_flow=False, load_calibration=False, load_imu=False, load_odometry_npz=False, load_gt_odometry=False, load_gt_poses=False, load_gt_depth_raw=False, load_gt_depth_rect=False, load_gt_flow_hdf5=False, load_gt_blended=False, load_velodyne=False, event_load_mode='cached', image_load_mode='cached', cache_dir=None)¶
Low level I/O for a single MVSEC sequence.
Handles HDF5 reading, NPZ decompression, calibration loading, and typed column caching. Use directly for custom access patterns (overlapping windows, multiscale, etc.) or let MVSECDataset wrap it for PyTorch style frame indexed sampling.
Large HDF5 backed modalities (depth, blended images, HDF5 flow, and velodyne) support a per modality loading strategy via the
LoadModetristate:False– do not load this modality.Trueor"lazy"– lazy load on demand (HDF5 handle stays open)."cached"– read entirely into memory during__init__.
Small modalities (IMU, odometry NPZ, GT odometry, GT poses) are always cached in memory when enabled because they are tiny.
The default profile is intentionally lean:
events are cached in RAM
grayscale images are cached in RAM
optional GT and calibration modalities stay disabled until requested
- Parameters:
root (str) – Directory containing the MVSEC dataset files.
sequence (str) – Sequence name (e.g.
"indoor_flying1").camera (str) –
"left"or"right".load_gt_flow (LoadMode) – LoadMode for GT optical flow from NPZ.
load_calibration (bool) – If True, load calibration rectification maps.
load_imu (bool) – If True, cache IMU data from data HDF5.
load_odometry_npz (bool) – If True, cache odometry from
*_odom.npz.load_gt_odometry (bool) – If True, cache LOAM odometry SE(3) from gt HDF5.
load_gt_poses (bool) – If True, cache Cartographer poses SE(3) from gt HDF5.
load_gt_depth_raw (LoadMode) – LoadMode for raw depth maps from gt HDF5.
load_gt_depth_rect (LoadMode) – LoadMode for rectified depth maps from gt HDF5.
load_gt_flow_hdf5 (LoadMode) – LoadMode for optical flow from gt HDF5.
load_gt_blended (LoadMode) – LoadMode for blended images from gt HDF5.
load_velodyne (LoadMode) – LoadMode for velodyne lidar from data HDF5.
event_load_mode (ResidentLoadMode) –
"cached"to keep all events in RAM or"lazy"to build and use a typed read only sidecar cache.image_load_mode (ResidentLoadMode) –
"cached"to keep all images in RAM or"lazy"to read frames from HDF5 on demand.cache_dir (Optional[str]) – Optional root directory for MVSEC sidecar caches.
- VALID_FRAMES: Dict[str, Tuple[int, int | None]] = {'indoor_flying1': (60, 1340), 'indoor_flying2': (140, 1500), 'indoor_flying3': (100, 1711), 'indoor_flying4': (104, 380), 'outdoor_day1': (0, 5020), 'outdoor_day2': (30, None)}¶
- load_events(start_index, end_index)¶
Load events in [start_index, end_index). Returns mutable copies.
- time_to_index(t)¶
Find the index of the last event strictly before time t.
May return -1 if no event precedes t.
- index_to_time(index)¶
Return the timestamp of the event at index.
- times_to_indices(timestamps)¶
Vectorized form of
time_to_index().Subclasses may override this for a more efficient implementation.
- indices_to_times(indices)¶
Vectorized form of
index_to_time().Subclasses may override this for a more efficient implementation.
- close()¶
Release resources (e.g. file handles, etc.).
- Return type:
None
- load_optical_flow(t1, t2)¶
Load GT optical flow between two timestamps.
Returns (H, W, 2) float32 where channels are [flow_x, flow_y]. Estimates displacement over [t1, t2) by propagating through GT frames.
- get_gt_timestamps(event_index)¶
Return (t_before, t_after) GT timestamps bracketing event_index.
- gt_time_list()¶
Return all GT timestamps. Raises if GT flow not loaded.
- property event_load_mode: LoadingType¶
- property image_load_mode: LoadingType¶
- normalize_frame_index(frame_index)¶
Normalize negative index and validate bounds.
- load_frame_sample(frame_index)¶
Load a synchronized single camera MVSEC sample for one frame.
- load_image(frame_index)¶
Load a single grayscale frame by index.
- undistort_events(events)¶
Apply calibration rectification maps to events.
Returns new RawEvents with rectified coordinates. Raises RuntimeError if calibration maps are not loaded.
- property imu_data: ndarray[Any, dtype[float64]] | None¶
Full IMU array (N, 6) [ax, ay, az, gx, gy, gz], or None.
- load_imu(t_start, t_end)¶
Return IMU readings and timestamps in [t_start, t_end), or None.
- property odometry_npz: MVSECOdometryData | None¶
- property gt_odometry: ndarray[Any, dtype[float64]] | None¶
LOAM odometry SE(3) poses (N, 4, 4), or None.
- load_nearest_pose(t, source='pose')¶
Return the nearest SE(3) pose (4, 4) to time t.
- get_events_by_time(t_start, t_end)¶
Load events whose timestamps fall in [t_start, t_end).
- iter_events(num_events=None, time_window=None)¶
Yield class RawEvents chunks.
Exactly one of num_events or time_window must be given.
- Parameters:
- Raises:
ValueError – If neither or both arguments are given, or if the given value is not positive.
- Return type:
- load_depth_raw(frame_index)¶
- load_depth_rect(frame_index)¶
- load_depth(frame_index, rectified=False)¶
- load_blended_image(frame_index)¶
- load_flow_hdf5(frame_index)¶
Load a single flow field (2, H, W) float64 from gt HDF5.
- class evlib.dataloaders.MVSECOdometryData(timestamps, linear_velocity, position, quaternion, angular_velocity)¶
Container for MVSEC odometry samples loaded from
*_odom.npz.- Parameters:
Modules
Shared helpers for dataloader indexing, caching, and optional decoding. |