Beispiel #1
0
def parse_args() -> argparse.Namespace:
    """ Parse the provided script arguments

    Returns:
        Parsed arguments in a namespace object
    """

    parser = argparse.ArgumentParser(
        description=
        "Launches the registered algorithm workflow (via name) on the given set of media"
    )
    parser = tator.get_parser(parser=parser)
    parser.add_argument('--project',
                        type=int,
                        required=True,
                        help='Unique project id')
    parser.add_argument('--algorithm',
                        type=str,
                        required=True,
                        help='Name of registered algorithm to launch')
    parser.add_argument('--media',
                        type=int,
                        required=True,
                        nargs='+',
                        help='Media IDs to process')

    args = parser.parse_args()
    logger.info(args)

    return args
Beispiel #2
0
def parse_args() -> argparse.Namespace:
    """ Process arguments
    """
    parser = tator.get_parser()
    parser.add_argument("--name", type=str, required=True, help="New project's name")
    parser.add_argument("--create-state-latest-type", action="store_true", help="Create a state type with latest interpolation/frame association attributes")
    parser.add_argument("--create-state-range-type", action="store_true", help="Create state types with attr_style_range interpolation/frame association")
    parser.add_argument("--create-track-type", action="store_true", help="Create a state type with localization association")
    args = parser.parse_args()

    return args
Beispiel #3
0
def main():
    """ Main routine of this script
    """

    # Create the argument list and extract them
    parser = tator.get_parser()
    parser.add_argument('--project',
                        type=int,
                        required=True,
                        help='Unique project id')
    parser.add_argument('--section',
                        type=str,
                        required=False,
                        help='Optional section name to process')
    parser.add_argument(
        '--output',
        type=str,
        required=False,
        help='Filename of section csv report. Only use if section was provided.'
    )
    parser.add_argument(
        '--disable-thumbnails',
        action='store_true',
        help='Ignore thumbnail creation, no thumbnails reported.')
    parser.add_argument(
        '--thumbnail-filename-pattern',
        type=str,
        required=False,
        help=
        'Default thumbnail filename is just the localization id. Use this string to specify otherwise.\n'
        +
        'Use all string to use media-id_frame-num_localization-id_all-attributes\n'
        +
        'Specify a specific set with: "media_id:frame_number:localization_id:Attribute Name 1:Attribute Name 2"\n'
        +
        'media_id, frame_number, localization_id are parameters that can be used\n'
        + 'split up the set with the colon\n' +
        'Entire string needs to be encapsulated in double quotes\n' +
        'This argument is ignored if disable-thumbnails is true')
    args = parser.parse_args()

    logger.info(args)

    # Create the report(s) and thumbnail(s)
    processProject(host=args.host,
                   token=args.token,
                   project_id=args.project,
                   section_name=args.section,
                   summary_filename=args.output,
                   disable_thumbnails=args.disable_thumbnails,
                   thumbnail_filename_pattern=args.thumbnail_filename_pattern)
def parse_args() -> argparse.Namespace:
    """ Parse script arguments
    """
    parser = tator.get_parser()
    parser.add_argument("--project", type=int, required=True, help="Associated unique project ID.")
    parser.add_argument("--media", type=int, nargs="+", required=True, help="List of media IDs to display.")
    parser.add_argument("--multi-media-name", type=str, required=True, help="Name of multi-media file. Note *.multi extension is applied automatically.")
    parser.add_argument("--layout-rows", type=int, required=True, help="Number of rows to use in the multi-gridview.")
    parser.add_argument("--layout-cols", type=int, required=True, help="Number of columns to use in the multi-gridview.")
    parser.add_argument("--quality", type=int, required=True, help="Video quality. 360 for 360p, 720 for 720p, etc.")
    parser.add_argument("--section-name", type=str, help="If provided, the new multi media will be applied to the given section. If section with the name does not exist, one will be created.")
    args = parser.parse_args()

    return args
Beispiel #5
0
def parse_args() -> argparse.Namespace:
    """ Parse the provided arguments

    Returns parsed arguments in a namespace object.

    """
    parser = argparse.ArgumentParser(
        description="Query localization based on media location")
    parser = tator.get_parser(parser=parser)
    parser.add_argument('--project',
                        type=int,
                        required=True,
                        help='Unique project id')
    parser.add_argument('--section',
                        type=str,
                        required=True,
                        help='Section name of media to process')
    parser.add_argument(
        '--media_type_id',
        type=int,
        required=True,
        help=
        'ID of media type to process (required for numerical attribute filtering)'
    )
    parser.add_argument('--radius',
                        type=float,
                        required=True,
                        help='Radius (km) of location query')
    parser.add_argument('--latitude',
                        type=float,
                        required=True,
                        help='Latitude of location query center point')
    parser.add_argument('--longitude',
                        type=float,
                        required=True,
                        help='Longitude of location query center point')
    parser.add_argument('--location_field',
                        type=str,
                        required=True,
                        help='Name of lat/lon field of media')

    args = parser.parse_args()
    logger.info(args)

    return args
def parse_args() -> argparse.Namespace:
    """Parse the provided arguments

    Returns parsed arguments in a namespace object.

    """
    parser = argparse.ArgumentParser(description="Add attribute to existing type")
    parser = tator.get_parser(parser=parser)
    parser.add_argument("project", type=int, help="Unique project id")
    parser.add_argument(
        "localization_type_id", type=int, help="ID of localization type to add attribute to"
    )
    parser.add_argument("new_attribute", type=str, help="Attribute to add (JSON string)")

    args = parser.parse_args()
    logger.info(args)

    return args
Beispiel #7
0
def parse_args() -> argparse.Namespace:
    """Parse the provided arguments

    Returns parsed arguments in a namespace object.

    """
    parser = argparse.ArgumentParser(description="Add attribute to existing type")
    parser = tator.get_parser(parser=parser)
    parser.add_argument("--project", type=int, required=True, help="Unique project id")
    parser.add_argument(
        "--state-type", type=int, required=True, help="The type of state to consider"
    )
    parser.add_argument(
        "--state-file",
        type=str,
        help="The text file where the intermediate list of states will be stored or read from",
        default="state_list.txt",
    )
    parser.add_argument(
        "--version", nargs="*", type=int, help="The list of layers to retrieve states from"
    )
    parser.add_argument(
        "--tracks-file",
        type=str,
        help="The text file where the intermediate list of filtered states will be stored or read from",
        default="track_list.txt",
    )
    parser.add_argument(
        "--roi",
        type=int,
        help="The id of the localization that defines the region of interest",
        default=94684778,
    )

    group = parser.add_mutually_exclusive_group(required=False)
    group.add_argument(
        "--get-states", help="Stop processing after all states are retrieved", action="store_true"
    )
    group.add_argument(
        "--filter-states", help="Stop processing after states are filtered", action="store_true"
    )

    args = parser.parse_args()
    return args
Beispiel #8
0
def main():
    """ Main routine of this script
    """

    # Create the argument list and extract them
    parser = argparse.ArgumentParser(
        description="Create localizations report and thumbnails for the section(s) in the given project.")
    parser = tator.get_parser(parser=parser)
    parser.add_argument('--project', type=int, required=True,
        help='Unique project id')
    parser.add_argument('--section', type=str, required=False,
        help='Optional section name to process')
    parser.add_argument('--output', type=str, required=False,
        help='Filename of section csv report. Only use if section was provided.')
    parser.add_argument('--disable-thumbnails', action='store_true',
        help='Ignore thumbnail creation, no thumbnails reported.')
    parser.add_argument('--thumbnail-filename-pattern', type=str, required=False,
        help='Default thumbnail filename is just the localization id. Use this string to specify otherwise. \n' +
             'Use <all> to use "media-name_frame-num_localization-id_all-attributes.png" \n' +
             'Specify a specific set with: "media_name:frame_number:localization_id:Attribute Name 1:Attribute Name 2" \n' +
             'Note: media_name, frame_number, localization_id are the only parameters that can be used (outside of attributes). \n' +
             'Split up the set with the colon\n' +
             'Extension of media_name is not included. \n' +
             'Entire string needs to be encapsulated in double quotes. \n' +
             'This argument is ignored if disable-thumbnails is true. ')
    parser.add_argument('--rerun-project', action='store_true',
        help='Script will start at the last section it processed (using the current directory of csv filenames)). Do not combine with section option.')
    parser.add_argument('--print-timing-info', action='store_true',
        help='Print timing')
    args = parser.parse_args()

    logger.info(args)

    # Create the report(s) and thumbnail(s)
    process_project(
        host=args.host,
        token=args.token,
        project_id=args.project,
        section_name=args.section,
        summary_filename=args.output,
        disable_thumbnails=args.disable_thumbnails,
        thumbnail_filename_pattern=args.thumbnail_filename_pattern,
        rerun_project=args.rerun_project,
        print_timing_info=args.print_timing_info)
Beispiel #9
0
def parse_args() -> argparse.Namespace:
    """ Returns the arguments passed to the script
    """
    parser = tator.get_parser()
    parser.add_argument('--url', type=str, help='URL to rest service.')
    parser.add_argument('--gid',
                        type=str,
                        default='',
                        help='Group ID for sending progress.')
    parser.add_argument('--uid',
                        type=str,
                        default='',
                        help='Job ID for sending progress.')
    parser.add_argument('--media', type=int, help='Media ID related to track.')
    parser.add_argument('--track', type=int, help='Track ID to process.')
    parser.add_argument(
        '--algo',
        type=str,
        help='Algorithm to run. Options: fillgaps|extend|batchextend')
    parser.add_argument('--work-folder',
                        type=str,
                        default='/work',
                        help='Work folder that clips will be downloaded to')
    parser.add_argument(
        '--extend-direction',
        type=str,
        help='Extension algorithm direction. Options: forward|backward')
    parser.add_argument(
        '--extend-detection-id',
        type=int,
        help='ID of detection to start the extension process with.')
    parser.add_argument(
        '--extend-max-coast',
        type=int,
        default=0,
        help='Max coast frames to use with the extension algorithm.')
    parser.add_argument(
        '--extend-max-frames',
        type=int,
        help=
        "Max number of frames to extend if provided. If not provided, only coasting or end of media will prohibit the extension"
    )
    return parser.parse_args()
Beispiel #10
0
def main() -> None:
    """ Main routine of this script
    """

    # Set the arguments and grab them
    parser = tator.get_parser()
    parser.add_argument(
        '--project',
        help='Unique project ID associated with the argo workflow',
        required=True,
        type=int)
    parser.add_argument(
        '--manifest',
        help='Path to the argo manifest .yaml file to be uploaded',
        required=True)
    parser.add_argument('--algorithm_name',
                        help='Unique name of algorithm argo workflow',
                        required=True)
    parser.add_argument('--files_per_job',
                        help='Number of files to process per job batch',
                        type=int,
                        required=True)
    parser.add_argument('--description',
                        help='Description of algorithm workflow')
    parser.add_argument('--cluster_id',
                        help='Cluster ID to run the workflow on',
                        type=int)
    parser.add_argument('--categories',
                        help='List of categories this workflow belongs to',
                        nargs='+',
                        type=str)
    args = parser.parse_args()

    tator.util.register_algorithm(host=args.host,
                                  token=args.token,
                                  project=args.project,
                                  manifest=args.manifest,
                                  algorithm_name=args.algorithm_name,
                                  files_per_job=args.files_per_job,
                                  description=args.description,
                                  cluster_id=args.cluster_id,
                                  categories=args.categories)
Beispiel #11
0
def parse_args() -> argparse.Namespace:
    """ Parse the provided arguments

    Returns parsed arguments in a namespace object.

    """
    parser = argparse.ArgumentParser(
        description=
        "Creates a file (media) summary for the provided project/section. Localization counts, state counts, and last session duration are recorded."
    )
    parser = tator.get_parser(parser=parser)
    parser.add_argument('--project',
                        type=int,
                        required=True,
                        help='Unique project id')
    parser.add_argument('--section',
                        type=str,
                        required=True,
                        help='Name of section to process')

    args = parser.parse_args()
    logger.info(args)

    return args
Beispiel #12
0
#!/usr/bin/env python
""" This example shows how to download media.
"""

import logging
import sys
import os

import tator

logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
logger = logging.getLogger(__name__)

if __name__ == '__main__':
    # Create a parser that includes media name and project name.
    parser = tator.get_parser()
    parser.add_argument('--media_name',
                        help='Name of media to download.',
                        required=True)
    parser.add_argument('--project_name',
                        help='Name of project.',
                        required=True)
    parser.add_argument('--save_path',
                        help='Directory to save the media.',
                        required=True)
    args = parser.parse_args()

    # Create the api.
    tator_api = tator.get_api(args.host, args.token)

    # Find the project.
Beispiel #13
0
                continue

            media_dict["s3_key"] = uuid_filename

        for media_id in list(media_tracker.keys()):
            if media_tracker[media_id]["upload_attempts_rem"] < 1:
                media_tracker.pop(media_id)
                failures.add("upload")

    logger.info("Features uploaded to s3")
    return failures


if __name__ == "__main__":
    parser = argparse.ArgumentParser(description=__doc__)
    tator.get_parser(parser)
    parser.add_argument("--access-key", type=str, required=True)
    parser.add_argument("--secret-key", type=str, required=True)
    parser.add_argument("--s3-bucket", type=str, required=True)
    parser.add_argument("--endpoint-url", type=str, required=True)
    parser.add_argument("--attribute-name", type=str, required=True)
    parser.add_argument("--work-dir", type=str, required=True)
    parser.add_argument("--project-id", type=int, required=True)
    parser.add_argument("--media-ids", type=int, nargs="*", required=True)
    parser.add_argument("--frame-modulus", type=int, required=True)
    parser.add_argument("--image-size", type=int, nargs=2, required=True)
    parser.add_argument("--verbose", action="store_true")
    parser.add_argument("--force-extraction", action="store_true")
    args = parser.parse_args()

    logger.info(f"ARGS: {args}")
Beispiel #14
0
def main():
    """ Invokes the thumbnail classifier on a media in tator """
    parser = argparse.ArgumentParser(description=__doc__)
    parser = tator.get_parser(parser)
    parser.add_argument("--strategy",
                        help="path to strategy file",
                        required=True)
    parser.add_argument("media_ids", nargs="*",help="List of media ids")
    args = parser.parse_args()
    print(args)

    host = os.getenv("TATOR_API_SERVICE")
    if host:
        host = host.replace('/rest', '')
    token = os.getenv("TATOR_AUTH_TOKEN")
    media_ids = None
    media_ids_str = os.getenv("TATOR_MEDIA_IDS")
    if media_ids_str:
        media_ids = [int(x) for x in media_ids_str.split(',')]

    # Override ENV with CLI
    if host is None and args.host:
        host = args.host
    if args.token:
        token = args.token
    if args.media_ids:
        media_ids = args.media_ids


    api = tator.get_api(host, token)

    with open(args.strategy) as fp:
        strategy = yaml.safe_load(fp)

    data_image = strategy['data_image']
    print("Strategy:")
    pprint(strategy)

    extract_mode = strategy['tator'].get('extract_mode', 'state')
    assert extract_mode in ['state','localization']
    if extract_mode == 'state':
        project = _safe_retry(api.get_state_type,strategy['tator']['track_type_id']).project
    else:
        project = _safe_retry(api.get_localization_type,strategy['tator']['track_type_id']).project
    # Download the network files from docker
    network_dir = tempfile.mkdtemp()
    client=docker.from_env()
    image=client.images.pull(data_image)
    container=client.containers.create(data_image)
    bits, stats = container.get_archive("/network")
    network_tar = os.path.join(network_dir, "network.tar")
    with open(network_tar, 'wb') as tar_file:
        for chunk in bits:
            tar_file.write(chunk)
    container.remove()

    with tarfile.TarFile(network_tar) as tar_file:
        members = tar_file.getmembers()
        for member in members:
            tar_file.extract(member, network_dir)
    # Remove tar file
    os.remove(network_tar)

    run_tracker(api,
                project,
                media_ids,
                os.path.join(network_dir, 'network'),
                strategy)

    shutil.rmtree(network_dir)
Beispiel #15
0
#!/usr/bin/env python

""" This example demonstrates how to create a project and configure media
    and metadata type definitions.
"""

import logging
import sys

import tator

logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
logger = logging.getLogger(__name__)

if __name__ == '__main__':
    args = tator.get_parser().parse_args()
    tator_api = tator.get_api(args.host, args.token)

    # Create the project.
    result = tator_api.create_project(project_spec={
        'name': 'Test Project', 'summary': 'A test project.',
    })
    project = result.id
    logger.info(result.message)

    # Create image type.
    result = tator_api.create_media_type(project, media_type_spec={
        "name": "Test Images",
        "description": "A test image type.",
        "dtype": "image",
        "attribute_types": [