sleap.io.format.labels_json#

Adaptor for reading/writing old, JSON dataset format (kind of deprecated).

This supports reading and writing both json and json.zip. The zip allows you to include image files, in imgstore videos. A better option now is to save a single HDF5 file which include both the SLEAP dataset (i.e., Labels) and also the videos/frames as HDF5 datasets.

class sleap.io.format.labels_json.LabelsJsonAdaptor[source]#
property all_exts#

List of all file extensions supported by adaptor.

can_read_file(file: sleap.io.format.filehandle.FileHandle)[source]#

Returns whether this adaptor can read this file.

can_write_filename(filename: str)[source]#

Returns whether this adaptor can write format of this filename.

property default_ext#

The default file extension, e.g., ‘json’ (without ‘.’).

does_read() bool[source]#

Returns whether this adaptor supports reading.

does_write() bool[source]#

Returns whether this adaptor supports writing.

classmethod from_json_data(data: Union[str, dict], match_to: Optional[sleap.io.dataset.Labels] = None) sleap.io.dataset.Labels[source]#

Create instance of class from data in dictionary.

Method is used by other methods that load from JSON.

Parameters
  • data – Dictionary, deserialized from JSON.

  • match_to – If given, we’ll replace particular objects in the data dictionary with matching objects in the match_to Labels object. This ensures that the newly instantiated Labels can be merged without duplicate matching objects (e.g., Video objects ).

Returns

A new Labels object.

property handles#

Returns the type of object that can be read/written.

The Dispatch class calls this method on all registered adaptors to determine which to use for reading/writing.

property name#

Human-reading name of the file format

classmethod read(file: sleap.io.format.filehandle.FileHandle, video_search: Optional[Union[Callable, List[str]]] = None, match_to: Optional[sleap.io.dataset.Labels] = None, *args, **kwargs) sleap.io.dataset.Labels[source]#

Reads the file and returns the appropriate deserialized object.

classmethod write(filename: str, source_object: str, compress: Optional[bool] = None, save_frame_data: bool = False, frame_data_format: str = 'png', all_labeled: bool = False, suggested: bool = False, progress_callback: Optional[Callable[[int, int], None]] = None)[source]#

Save a Labels instance to a JSON format.

Parameters
  • filename – The filename to save the data to.

  • source_object – The labels dataset to save.

  • compress – Whether the data be zip compressed or not? If True, the JSON will be compressed using Python’s shutil.make_archive command into a PKZIP zip file. If compress is True then filename will have a .zip appended to it.

  • save_frame_data – Whether to save the image data for each frame. For each video in the dataset, all frames that have labels will be stored as an imgstore dataset. If save_frame_data is True then compress will be forced to True since the archive must contain both the JSON data and image data stored in ImgStores.

  • frame_data_format

    If save_frame_data is True, then this argument is used to set the data format to use when writing frame data to ImgStore objects. Supported formats should be:

    • ’pgm’,

    • ’bmp’,

    • ’ppm’,

    • ’tif’,

    • ’png’,

    • ’jpg’,

    • ’npy’,

    • ’mjpeg/avi’,

    • ’h264/mkv’,

    • ’avc1/mp4’

    Note: ‘h264/mkv’ and ‘avc1/mp4’ require separate installation of these codecs on your system. They are excluded from SLEAP because of their GPL license.

  • all_labeled – Whether to save all frames or just the labeled frames to use in training.

  • suggested – Whether to save the suggested labels along with the training labels.

  • progress_callback – A function that will be called with the current progress.

Returns

None