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.
List of all file extensions supported by adaptor.
Returns whether this adaptor can read this file.
Returns whether this adaptor can write format of this filename.
The default file extension, e.g., ‘json’ (without ‘.’).
does_read() → bool¶
Returns whether this adaptor supports reading.
does_write() → bool¶
Returns whether this adaptor supports writing.
from_json_data(data: Union[str, dict], match_to: Optional[Labels] = None) → sleap.io.dataset.Labels¶
Create instance of class from data in dictionary.
Method is used by other methods that load from JSON.
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
Labelsobject. This ensures that the newly instantiated
Labelscan be merged without duplicate matching objects (e.g.,
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.
Human-reading name of the file format
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¶
Reads the file and returns the appropriate deserialized object.
write(filename: str, source_object: str, compress: Optional[bool] = None, save_frame_data: bool = False, frame_data_format: str = 'png')¶
Save a Labels instance to a JSON format.
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.
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:
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.