sleap.io.format.alphatracker#
Adaptor for reading AlphaTracker datasets.
This can read a JSON file with labeled frames for a single video, or multiple videos.
The adaptor was created by manually inspecting AlphaTracker files and there’s no guarantee that it will perfectly import all data (especially metadata).
If the adaptor can find full video files for the annotated frames, then the full videos will be used in the resulting SLEAP dataset. Otherwise, we’ll create a video object which wraps the individual frame images.
- class sleap.io.format.alphatracker.AlphaTrackerAdaptor[source]#
Reads AlphaTracker JSON file with annotations for both single and multiple animals.
- property all_exts: List[str]#
List of all file extensions supported by adaptor.
- can_read_file(file: FileHandle) bool [source]#
Returns whether this adaptor can read this file.
Checks the format of the file at three different levels: - First, the upper-level format of file.json must be a list of dictionaries. - Second, the dictionaries that represent frames must contain the specific keys
that the adaptor reads.
Third, the “annotations” key in must contain a list of dictionaries.
- Fourth, the dictionaries used to define bounding boxes for instances must
contain the specific key that the adaptor reads.
- Fifth, the dictionaries used to define the points of instance node must
contain the specific keys that the adaptor reads.
- can_write_filename(filename: str) bool [source]#
Returns whether this adaptor can write format of this filename.
- property default_ext: str#
The default file extension, e.g., ‘json’ (without ‘.’).
- does_match_ext(filename: str) bool [source]#
Returns whether this adaptor can write format of this filename.
- property formatted_ext_options#
String for Qt file dialog extension options.
- get_alpha_tracker_frame_dict(filename: str = '')[source]#
Returns a deep copy of the dictionary used for frames.
- Parameters:
annotations – List of AlphaTracker annotations for current frame.
filename – The filename of the image to use for the current frame.
- Returns:
A dictionary containing the annotations in the frame, the AlphaTracker class of the dictionary (“image”), and the filename.
- get_alpha_tracker_instance_dict(width: int = 200, x: float = 200.0, y: float = 200.0) dict [source]#
Returns a deep copy of the dictionary used for instances.
- Parameters:
height – The height of the bounding box.
width – The width of the bounding box.
x – The x-coor of lower left hand corner of the bounding box.
y – The y-coor of lower left hand corner of the bounding box.
- Returns:
A dictionary containing the AlphaTracker class of the dictionary (“Face”) along with the height, width, and x,y-coordinates of the bounding box around the instance.
- get_alpha_tracker_point_dict(y: float = 200.0) dict [source]#
Returns a deep copy of the dictionary used for nodes.
- Parameters:
x – The x-coordinate of the node location.
y – The y-coordinate of the node location.
- Returns:
A dictionary containing the AlphaTracker class of the dictionary (“point”) and the x,y-coordinates of the node location.
- property handles: SleapObjectType#
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.
- make_video_for_image_list(image_dir: str, filenames: List[str]) Video [source]#
Creates a Video object from frame images.
- Parameters:
image_dir – The directory that contains the AlphaTracker file.
filenames – A list of filenames for the frame images.
- Returns:
A
Video
object.
- property name: str#
Human-reading name of the file format
- read(file: FileHandle, skeleton: Skeleton | None = None, full_video: Video | None = None) Labels [source]#
Reads the file and returns the appropriate deserialized object.
- Parameters:
file – The file to read.
skeleton – The skeleton to use for
Instance
objects. If no skeleton is provided, the skeleton will created with numerical node names.full_video – The video to use for the
Labels
object.
- Returns:
A
Labels
object containing all the AlphaTracker annotations.
- write(filename: str, source_object: Labels) List[dict] [source]#
Writes the object to an AlphaTracker JSON file.
- Parameters:
filename – The name of the file being written to.
souce_object – The
Labels
object which contains the relevant information to write to an AlphaTracker JSON file.
- Raises:
NotImplementedError – The code for the write functionality is not complete, see TODOs.
- Returns:
A list of annotated frames in the same format seen in the AlphaTracker JSON.