Convenience class used to save features to an HDF5 file.

class metavision_ml.utils.h5_writer.HDF5Writer(filename, dataset_name, shape, dtype=<class 'numpy.uint8'>, attrs={}, mode='w', store_as_uint8=False)

Convenience class used to save features to an HDF5 file.

  • filename (string) – Path to the destination file

  • dataset_name (string) – name of the dataset to write.

  • shape (int List) – shape of the features written to disks, the actual shape of the dataset is [-1,] + shape (since the total number of features written to disk is not known at initialisation time.)

  • dtype (np.dtype) – dtype specifying the features precision.

  • {dictionary} (attrs) – dictionary of attributes for the dataset. It consists in metadata that needs to be contained in the result file.

  • mode (string) – mode for opening the file. Defaults to write “w”.

  • store_as_uint8 (boolean) – if True, casts to byte before storing to save space. Only supports 0-1 normalized data.


correspond to the number of feature already written to HDF5.




>>> f = HDF5Writer("example.h5", "data", [2, 480, 320], dtype=np.uint8)
>>> f.write(np.empty((15, 2, 480, 320), dtype=np.uint8))
>>> f.write(np.zeros((12, 2, 480, 320), dtype=np.uint8))
>>> f.close()

Sets the cursor of where to write the next features. Use with caution !

Can be used to overwrite or drop some already written data.


index (int) – new cursor position.


>>> # ... some feature were written
>>> hdf5_writer.set_cursor(hdf5_writer.index - 1)  # drop the last frame
>>> hdf5_writer.set_cursor(0)  #  ! drop all previously written features !

Appends an array of features to the dataset.

The underlying hdf5 dataset gets extended when necessary.


array (np.ndarray) – feature array, its shape must be [*,] + self.shape and its dtype must be convertible to the dtype of the dataset.

Tools common to training main functions.

metavision_ml.utils.main_tools.check_input_power_2(event_input_height, event_input_width, height=None, width=None)

Checks that the provided height and width are indeed a negative power of two of the input.

  • event_input_height (int) – height of the sensor in pixels.

  • event_input_width (int) – width of the sensor in pixels.

  • height (int) – desired height of features after rescaling

  • width (int) – desired width of features after rescaling


Returns the couple (height, width) of a file.


path (string) – File path, either a DAT file of an hdf5 file path.

metavision_ml.utils.main_tools.infer_preprocessing(params, h5path=None)

Infer the preprocessing parameters via reading attributes of first found HDF5 file.

  • params – struct containing training parameters.

  • h5path (string) – optional path of an HDF5 file from the dataset, its attributes are used to override the preprocessing parameters.


tensor shape of a single item of a batch (num time bins, num channels, height, width) preprocess (string): name of the preprocessing used. delta_t (int): duration of a temporal bin in us. max_incr_per_pixel (float): Maximum number of increments per pixel (normalize the contribution of each event)

Return type

array_dim (int List)