tator.get_api(host=‘https://cloud.tator.io’, token=None)
Retrieves a tator.api
instance using the given host and token.
Parameters
Returns
tator.api
object.
tator.get_parser(parser=None, description=None)
Returns an argument parser that includes host and token.
Returns
argparse.ArgumentParser
object that includes host and token arguments.
tator.download_media(api, media, out_path, quality=None, media_type=None, codec_or_mime=None)
Download a media file from Tator to an off-line location.
Example:
api = tator.get_api(host, token)
media = api.get_media(media_id)
out_path = f'/tmp/{media.name}'
for progress in tator.util.download_media(api, media, out_path):
print(f"Download progress: {progress}%")
#download 720p version streaming
for progress in tator.util.download_media(api,
media,
out_path,
720,
'streaming'):
print(f"Download progress: {progress}%")
Parameters
tator.TatorApi
object.tator.Media
object.Returns
Generator the yields progress (0-100).
Utility functions for interacting with the Tator platform
class tator.util.MediaUtil(temp_dir)
Top-level class to construct to handle per-media manipulations
Return an animation of frames at a given FPS.
Given a list of frame ranges generate a temporary mp4
Generate a tile jpeg of the given frame/rois
Initialize the MediaUtil with a tator media object (loaded with presigned URLs)
Setup the MediaUtil instance with primitive types
tator.util.chunked_create(func: Callable, project: int, chunk_size: int = 500, **kwargs)
Breaks a create_*_list operation into chunks. Example:
created_ids = [
new_id
for response in tator.util.chunked_create(
api.create_localization_list, chunk_size=100, body=my_long_list
)
for new_id in response.id
]
Parameters
Returns
Generator that yields a response.
tator.util.chunked_file_list(paths, chunk_size=100)
Breaks file list into chunks for upload via media archive.
Example:
api = tator.get_api(host, token)
batch_num = 0
for batch in tator.util.chunked_file_list(paths):
print(f"Uploading file {batch_num*100} / {len(paths)}")
for progress, response in tator.util.upload_media_archive(api, project_id, batch):
print(f"Upload progress: {progress}%")
print(response.message)
batch_num += 1
Parameters
Returns
Generator that yields batches of file paths.
tator.util.clone_leaf_list(src_api, query_params, dest_project, parent_mapping, leaf_type_mapping, dest_api=None)
Clone leaf list.
This can be used to clone leaves from one project to another or from one host to another.
Example for different host:
src_api = tator.get_api(host, token)
dest_api = tator.get_api(other_host, other_token)
query_params = {'project': 1, 'depth': 1}
dest_project = 1
created_ids = []
parent_mapping = {1: 10} # Mapping of parent leaf IDs
leaf_type_mapping = {1: 10} # Source leaf type ID -> Dest leaf type ID
generator = clone_leaf_list(src_api, query_params, dest_project, parent_mapping,
leaf_type_mapping, dest_api)
for num_created, num_total, response, id_map in generator:
print(f"Created {num_created} of {num_total} leafs...")
created_ids.append(response.id)
print(f"Finished creating {num_created} leafs!")
Example for same host:
api = tator.get_api(host, token)
query_params = {'project': 1, 'depth': 1}
dest_project = 1
parent_mapping = {1: 10}
leaf_type_mapping = {1: 10} # Source leaf type ID -> Dest leaf type ID
created_ids = []
generator = clone_leaf_list(api, query_params, dest_project, parent_mapping)
for num_created, num_total, response, id_map in generator:
print(f"Created {num_created} of {num_total} leafs...")
created_ids += response.id
print(f"Finished creating {num_created} leafs!")
Parameters
tator.TatorApi
object corresponding to source host or only
host if this is a clone on same host.tator.TatorApi
object corresponding to destination host.Returns
Generator containing number of leafs created, number of leafs total, most recent response from leaf creation operation, and mapping between original IDs and created IDs.
tator.util.clone_leaf_type(src_api, src_type_id, dest_project, dest_api=None)
Clone leaf type.
This can be used to clone leaf types from one project to another or from one host to another.
Example for different host:
src_api = tator.get_api(host, token)
dest_api = tator.get_api(other_host, other_token)
src_type_id = 1
dest_project = 1
response = tator.util.clone_leaf_type(src_api, src_type_id, dest_project, dest_api)
print(response.message)
Example for same host:
api = tator.get_api(host, token)
src_type_id = 1
dest_project = 1
response = tator.util.clone_leaf_type(src_api, src_type_id, dest_project)
print(response.message)
Parameters
tator.TatorApi
object corresponding to source host or only
host if this is a clone on same host.tator.TatorApi
object corresponding to destination host.Returns
Response from leaf type creation request.
tator.util.clone_localization_list(src_api, query_params, dest_project, version_mapping, media_mapping, localization_type_mapping, dest_api=None)
Clone localization list.
This can be used to clone localizations from one project to another or from one host to another.
Example for different host:
src_api = tator.get_api(host, token)
dest_api = tator.get_api(other_host, other_token)
query_params = {'project': 1, 'media_id': [1]}
version_mapping = {1: 10} # Source version ID -> Dest version ID
media_mapping = {1: 10} # Source media ID -> Dest media ID
localization_type_mapping = {1: 10} # Source localization type ID -> Dest type ID
dest_project = 1
created_ids = []
generator = clone_localization_list(src_api, query_params, dest_project, version_mapping,
media_mapping, localization_type_mapping, dest_api)
for num_created, num_total, response, id_map in generator:
print(f"Created {num_created} of {num_total} localizations...")
created_ids.append(response.id)
print(f"Finished creating {num_created} localizations!")
Example for same host:
api = tator.get_api(host, token)
query_params = {'media_id': [1]}
dest_project = 1
version_mapping = {1: 10}
media_mapping = {1: 10}
localization_type_mapping = {1: 10} # Source localization type ID -> Dest type ID
created_ids = []
generator = clone_localization_list(src_api, query_params, dest_project, version_mapping,
media_mapping, localization_type_mapping)
for num_created, num_total, response, id_map in generator:
print(f"Created {num_created} of {num_total} localizations...")
created_ids += response.id
print(f"Finished creating {num_created} localizations!")
Parameters
tator.TatorApi
object corresponding to source host or only
host if this is a clone on same host.tator.TatorApi
object corresponding to destination host.Returns
Generator containing number of localizations created, number of localizations total, most recent response from localization creation operation, and mapping between original IDs and created IDs.
tator.util.clone_localization_type(src_api, src_type_id, dest_project, media_type_mapping, dest_api=None)
Clone localization type.
This can be used to clone localization types from one project to another or from one host to another.
Example for different host:
src_api = tator.get_api(host, token)
dest_api = tator.get_api(other_host, other_token)
src_type_id = 1
dest_project = 1
media_type_mapping = {1: 10}
response = tator.util.clone_localization_type(src_api, src_type_id, dest_project,
media_type_mapping, dest_api)
print(response.message)
Example for same host:
api = tator.get_api(host, token)
src_type_id = 1
dest_project = 1
response = tator.util.clone_localization_type(src_api, src_type_id, dest_project,
media_type_mapping)
print(response.message)
Parameters
tator.TatorApi
object corresponding to source host or only
host if this is a clone on same host.tator.TatorApi
object corresponding to destination host.Returns
Response from localization type creation request.
tator.util.clone_media_list(src_api, query_params, dest_project, media_mapping={}, dest_type=-1, dest_section=”, dest_api=None, ignore_transfer=False)
Clone media list.
This can be used to clone media from one project to another or from one
host to another. In the case of the same host, the media files are not
copied. If the destination host is different (dest_api is a tator.TatorApi
object), the transcoded files for each media object is downloaded and then
uploaded to the other host, and a new tator.Media
object is created.
Example for different host:
src_api = tator.get_api(host, token)
dest_api = tator.get_api(other_host, other_token)
query_params = {'project': 1, 'media_id': [1]}
media_mapping = {} # Only required if query contains multi media types
dest_project = 1
dest_type = -1
dest_section = 'My cloned media'
created_ids = []
generator = clone_media_list(src_api, query_params, dest_project, media_mapping,
dest_type, dest_section, dest_api)
for num_created, num_total, response, id_map in generator:
print(f"Created {num_created} of {num_total} files...")
created_ids.append(response.id[0])
print(f"Finished creating {num_created} files!")
Example for same host:
api = tator.get_api(host, token)
query_params = {'media_id': [1]}
dest_project = 1
created_ids = []
generator = clone_media_list(src_api, query_params, dest_project)
for num_created, num_total, response, id_map in generator:
print(f"Created {num_created} of {num_total} files...")
created_ids += response.id[0] # This response is from the CloneMedia endpoint.
print(f"Finished creating {num_created} files!")
Parameters
tator.TatorApi
object corresponding to source host or only
host if this is a clone on same host.tator.TatorApi
object corresponding to destination host.Returns
Generator containing number of files created, number of files total, most recent response from media creation operation, and mapping between original IDs and created IDs.
tator.util.clone_media_type(src_api, src_type_id, dest_project, dest_api=None)
Clone media type.
This can be used to clone media types from one project to another or from one host to another.
Example for different host:
src_api = tator.get_api(host, token)
dest_api = tator.get_api(other_host, other_token)
src_type_id = 1
dest_project = 1
response = tator.util.clone_media_type(src_api, src_type_id, dest_project, dest_api)
print(response.message)
Example for same host:
api = tator.get_api(host, token)
src_type_id = 1
dest_project = 1
response = tator.util.clone_media_type(src_api, src_type_id, dest_project)
print(response.message)
Parameters
tator.TatorApi
object corresponding to source host or only
host if this is a clone on same host.tator.TatorApi
object corresponding to destination host.Returns
Response from media type creation request.
tator.util.clone_membership(src_api, src_membership_id, dest_project, user_mapping=None, dest_api=None)
Clone membership.
This can be used to clone memberships from one project to another or from one host to another.
Example for different host:
src_api = tator.get_api(host, token)
dest_api = tator.get_api(other_host, other_token)
src_membership_id = 1
dest_project = 1
user_mapping = {1: 10} # Mapping between user ID on source host and destination host.
response = tator.util.clone_membership(src_api, src_membership_id, dest_project,
user_mapping, dest_api)
print(response.message)
Example for same host:
api = tator.get_api(host, token)
src_membership_id = 1
dest_project = 1
response = tator.util.clone_membership(src_api, src_membership_id, dest_project)
print(response.message)
Parameters
tator.TatorApi
object corresponding to source host or only
host if this is a clone on same host.tator.TatorApi
object corresponding to destination host.Returns
Response from membership creation request.
tator.util.clone_section(src_api, src_section_id, dest_project, dest_api=None)
Clone section.
This can be used to clone sections from one project to another or from one host to another.
Example for different host:
src_api = tator.get_api(host, token)
dest_api = tator.get_api(other_host, other_token)
src_section_id = 1
dest_project = 1
response = tator.util.clone_section(src_api, src_section_id, dest_project, dest_api)
print(response.message)
Example for same host:
api = tator.get_api(host, token)
src_section_id = 1
dest_project = 1
response = tator.util.clone_section(src_api, src_section_id, dest_project)
print(response.message)
Parameters
tator.TatorApi
object corresponding to source host or only
host if this is a clone on same host.tator.TatorApi
object corresponding to destination host.Returns
Response from section creation request.
tator.util.clone_state_list(src_api, query_params, dest_project, version_mapping, media_mapping, localization_mapping, state_type_mapping, dest_api=None)
Clone state list.
This can be used to clone states from one project to another or from one host to another.
Example for different host:
src_api = tator.get_api(host, token)
dest_api = tator.get_api(other_host, other_token)
query_params = {'project': 1, 'media_id': [1]}
version_mapping = {1: 10} # Source version ID -> Dest version ID
media_mapping = {1: 10} # Source media ID -> dest media ID
localization_mapping = {} # For tracks, source localization ID -> dest localization ID
state_type_mapping = {1: 10} # Source state type ID -> Dest state type ID
dest_project = 1
dest_version = -1
created_ids = []
generator = clone_state_list(src_api, query_params, dest_project, version_mapping,
media_mapping, localization_mapping, state_type_mapping,
dest_api)
for num_created, num_total, response, id_map in generator:
print(f"Created {num_created} of {num_total} states...")
created_ids.append(response.id)
print(f"Finished creating {num_created} states!")
Example for same host:
api = tator.get_api(host, token)
query_params = {'media_id': [1]}
dest_project = 1
version_mapping = {1: 10} # Source version ID -> Dest version ID
media_mapping = {1: 10}
localization_mapping = {}
state_type_mapping = {1: 10} # Source state type ID -> Dest state type ID
created_ids = []
generator = clone_state_list(src_api, query_params, dest_project, version_mapping,
media_mapping, localization_mapping, state_type_mapping)
for num_created, num_total, response, id_map in generator:
print(f"Created {num_created} of {num_total} states...")
created_ids += response.id
print(f"Finished creating {num_created} states!")
Parameters
tator.TatorApi
object corresponding to source host or only
host if this is a clone on same host.tator.TatorApi
object corresponding to destination host.Returns
Generator containing number of states created, number of states total, most recent response from state creation operation, and mapping between original IDs and created IDs.
tator.util.clone_state_type(src_api, src_type_id, dest_project, media_type_mapping, dest_api=None)
Clone state type.
This can be used to clone state types from one project to another or from one host to another.
Example for different host:
src_api = tator.get_api(host, token)
dest_api = tator.get_api(other_host, other_token)
src_type_id = 1
dest_project = 1
media_type_mapping = {1: 10}
response = tator.util.clone_state_type(src_api, src_type_id, dest_project,
media_type_mapping, dest_api)
print(response.message)
Example for same host:
api = tator.get_api(host, token)
src_type_id = 1
dest_project = 1
response = tator.util.clone_state_type(src_api, src_type_id, dest_project,
media_type_mapping)
print(response.message)
Parameters
tator.TatorApi
object corresponding to source host or only
host if this is a clone on same host.tator.TatorApi
object corresponding to destination host.Returns
Response from state type creation request.
tator.util.clone_version(src_api, src_version_id, dest_project, version_mapping={}, dest_api=None)
Clone version.
This can be used to clone versions from one project to another or from one host to another.
Example for different host:
src_api = tator.get_api(host, token)
dest_api = tator.get_api(other_host, other_token)
src_version_id = 1
dest_project = 1
version_mapping = {} # Necessary if source version has base versions.
response = tator.util.clone_version(src_api, src_version_id, dest_project,
version_mapping, dest_api)
print(response.message)
Example for same host:
api = tator.get_api(host, token)
src_version_id = 1
dest_project = 1
response = tator.util.clone_version(src_api, src_version_id, dest_project)
print(response.message)
Parameters
tator.TatorApi
object corresponding to source host or only
host if this is a clone on same host.tator.TatorApi
object corresponding to destination host.Returns
Response from version creation request.
tator.util.download_attachment(api, media, out_path, index=0)
Download an attachment from Tator to an off-line location.
Example:
api = tator.get_api(host, token)
media = api.get_media(media_id)
out_path = f'/tmp/{media.name}'
for progress in tator.util.download_attachment(api, media, out_path):
print(f"Download progress: {progress}%")
#download second attachment
for progress in tator.util.download_attachment(api, media, out_path, index=1):
print(f"Download progress: {progress}%")
Parameters
tator.TatorApi
object.tator.Media
object.Returns
Generator that yields progress (0-100).
tator.util.download_media(api, media, out_path, quality=None, media_type=None, codec_or_mime=None)
Download a media file from Tator to an off-line location.
Example:
api = tator.get_api(host, token)
media = api.get_media(media_id)
out_path = f'/tmp/{media.name}'
for progress in tator.util.download_media(api, media, out_path):
print(f"Download progress: {progress}%")
#download 720p version streaming
for progress in tator.util.download_media(api,
media,
out_path,
720,
'streaming'):
print(f"Download progress: {progress}%")
Parameters
tator.TatorApi
object.tator.Media
object.Returns
Generator the yields progress (0-100).
tator.util.download_temporary_file(api, temporary_file, out_path)
Download a temporary file from Tator to an off-line location.
Example:
api = tator.get_api(host, token)
temporary_file = api.get_temporary_file(temporary_file_id)
out_path = f'/tmp/{temporary_file.name}'
for progress in tator.util.download_temporary_file(api, temporary_file,
out_path):
print(f"Download progress: {progress}%")
Parameters
tator.TatorApi
object.tator.models.TemporaryFile
object.Returns
Generator that yields progress (0-100).
tator.util.find_single_change(api: tator.TatorApi, project_id: int, entity_id: int, field_name: str, old_value: Any | None = None, new_value: Any | None = None, find_last_change: bool = False)
Finds the ChangeLog containing the desired field/value combination.
Example:
api = tator.get_api(host, token)
change_log = tator.util.find_change(api, media_id, "_deleted", new_value=True)
print(change_log)
At least one of old_value and new_value must be specified; if both are specified, then the matching changelog must match both, not just one.
The field_name must be prefixed with an underscore if it is not a user-defined attribute, note how “_deleted” corresponds to the Media.deleted field.
Parameters
tator.TatorApi
object.Returns
The changelog corresponding to the desired value(s) to find or None if no matches are found.
Return type
Optional[ChangeLog]
tator.util.full_state_graphic(api, state_id, force_scale=None)
Retrieves all detection images for a state.
Example:
state_graphic = full_state_graphic(api, state_id)
Parameters
tator.TatorApi
object.Returns
List containing all detection images in this state.
tator.util.get_api(host=‘https://cloud.tator.io’, token=None)
Retrieves a tator.api
instance using the given host and token.
Parameters
Returns
tator.api
object.
tator.util.get_images(file_path, media_or_state, num_images=None, width=None, height=None)
Loads image saved by tator.api.get_frame()
Can also be used with tator.api.get_state_graphic()
.
Returns
A list of PIL.Image.Image
Parameters
tator.Media
or tator.State
object.tator.TatorApi.get_frame()
, or if the offset
or length parameters were used in tator.TatorApi.get_state_graphic()
.tator.TatorApi.get_frame()
.tator.TatorApi.get_frame()
.tator.util.get_paginator(api, func_name: str, batch_size: int | None = 1000)
Returns a Paginator object that returns pages of results from the given func_name. Example:
import tator
api = tator.get_api(host, token)
media_paginator = tator.util.get_paginator(api, "get_media_list")
page_iterator = media_paginator.paginate(project=project_id)
all_media = []
for page in page_iterator:
for media in page:
all_media.append(media)
Parameters
tator.TatorApi
object.Raises ValueError if the func_name does not match the expected pattern or if it does not exist.
Returns
Paginator object
tator.util.import_media(api, type_id, url, md5=None, section=None, fname=None, upload_gid=None, upload_uid=None, chunk_size=2097152, attributes=None, media_id=None, size=None, _request_timeout=10)
Imports a hosted media file.
Example:
api = tator.get_api(host, token)
response = tator.util.import_media(api, type_id, url)
print(response.message)
tator.TatorApi
object.tator.util.make_concat(api, name, media_ids, section, offsets=None)
Uploads a single media file.
Parameters
tator.TatorApi
object.Returns
Response from media object creation.
tator.util.make_live_stream(api, type_id, layout, name, section, feedInfo)
Make a live stream tator media object.
Parameters
tator.TatorApi
object.tator.models.LiveDefinition
object or dictionary.Returns
Response from media object creation.
tator.util.make_multi_stream(api, type_id, layout, name, media_ids, section, quality=None, frame_offset=None)
Creates a multiview from the given arguments
Parameters
Returns
Response from media object creation.
tator.util.md5sum(fname, size=None)
Computes md5sum-based fingerprint of a file contents. The return
is the md5sum of the file contents (up to 100Mb) hashed along with
the file size.
Parameters
Returns
md5 sum of the file.
tator.util.register_algorithm(host: str, token: str, project: int, manifest: str, algorithm_name: str, files_per_job: int, categories: list = [], description: str = ”, cluster_id: int | None = None) layout: ../../../../layouts/DocLayout.astro
Registers an algorithm argo workflow using the provided parameters
This will upload the given manifest file, save it to tator, and the new server side URL will be used when registering the workflow. This may change the filename of the manifest file.
Args:
host: Host URL
token: User token used for connecting to the host
project: Unique identifier of project associated with algorithm
manifest: Local path to argo workflow manifest file to upload, save,
> and register the algorithm with
algorithm_name: Unique name of the workflow
files_per_job: Number of media to process per workflow created
description: Optional description of workflow
layout: ../../../../layouts/DocLayout.astro cluster_id: Optional unique integer identifying the job cluster
tator.util.register_applet(host: str, token: str, project: int, html_file: str, applet_name: str, categories: list = [], description: str = ”) layout: ../../../../layouts/DocLayout.astro
Registers a applet using the provided parameters
This will upload the given html file, save it to tator, and the new server side URL will be used when registering the applet. This may change the filename of the uploaded file
tator.util.supplement_video_to_media(api, media_id, role, configuration, filepath: str, force=False)
This routine will transcode filepath based on configuration to media_object
See tator.api.delete_video_file()
for information on deleting resolutions from a media object
tator.util.to_dataframe(objects)
Converts list of objects to pandas.DataFrame
.
Parameters object – List of objects.
Returns
Pandas dataframe.
tator.util.update_applet(host: str, token: str, applet_id: int, html_file: str | None = None, applet_name: str | None = None, categories: list | None = None, description: str | None = None) layout: ../../../../layouts/DocLayout.astro
Updates an existing applet using the provided parameters
tator.util.upload_attachment(api, media, path, name=None, chunk_size=104857600)
Upload a file as an attachment to a media object. Example:
api = tator.get_api(host, token)
for progress, response in tator.util.upload_attachment(api, media_id, path):
print(f"Upload progress: {progress}%")
print(response.message)
Parameters
tator.TatorApi
object.Returns
Generator that yields tuple containing progress (0-100) and a
response. The response is None until the last yield, when the response
is the response object from tator.util.TatorApi.create_auxiliary_file()
.
tator.util.upload_generic_file(api, file_type, path, description, name=None, attributes=None, timeout=None)
Upload a file to the File storage location.
Example:
api = tator.get_api(host, token)
for progress, response in tator.util.upload_generic_file(api, project_id, path):
print(f"Upload progress: {progress}%")
print(response)
Parameters
tator.TatorApi
object.tator.util._upload_file._upload_file()
operation.Returns
Generator that yields tuple containing progress (0-100) and a response. The response
is None until the last yield, when the response is the updated response object from
tator.util.TatorApi.get_file()
.
tator.util.upload_media(api, type_id, path, md5=None, section=None, fname=None, upload_gid=None, upload_uid=None, chunk_size=10485760, attributes=None, email_spec=None, media_id=None, timeout=30, max_workers=10)
Uploads a single media file.
Example:
api = tator.get_api(host, token)
for progress, response in tator.util.upload_media(api, type_id, path):
print(f"Upload progress: {progress}%")
print(response.message)
Parameters
tator.TatorApi
object.Returns
Generator that yields tuple containing progress (0-100) and a
response. The response is None until the last yield, when the response
is the response object from tator.TatorApi.create_media_list()
or
tator.TatorApi.transcode()
.
tator.util.upload_temporary_file(api, project, path, lookup=None, hours=24, name=None, chunk_size=104857600)
Upload a file to the temporary file storage location.
Example:
api = tator.get_api(host, token)
for progress, response in tator.util.upload_temporary_file(api, project_id, path):
print(f"Upload progress: {progress}%")
print(response.message)
Parameters
tator.TatorApi
object.Returns
Generator that yields tuple containing progress (0-100) and a
response. The response is None until the last yield, when the response
is the response object from tator.util.TatorApi.create_temporary_file()
.