trains/task.py
def init(
        cls,
        project_name=None,
        task_name=None,
        task_type=TaskTypes.training,
        reuse_last_task_id=True,
        output_uri=None,
        auto_connect_arg_parser=True,
        auto_connect_frameworks=True,
    ):
        """
        Return the Task object for the main execution task (task context).

        :param project_name: project to create the task in (if project doesn't exist, it will be created)
        :param task_name: task name to be created (in development mode, not when running remotely)
        :param task_type: task type to be created (in development mode, not when running remotely)
        :param reuse_last_task_id: start with the previously used task id (stored in the data cache folder). \
            if False every time we call the function we create a new task with the same name \
            Notice! The reused task will be reset. (when running remotely, the usual behaviour applies) \
            Note: A closed or published task will not be reused, and a new task will be created.
        :param output_uri: Default location for output models (currently support folder/S3/GS/ ).
            notice: sub-folders (task_id) is created in the destination folder for all outputs.
        :param auto_connect_arg_parser: Automatically grab the ArgParser and connect it with the task.
            if set to false, you can manually connect the ArgParser with task.connect(parser)
        :param auto_connect_frameworks: If true automatically patch MatplotLib, Keras callbacks, and TensorBoard/X to
            serialize plots, graphs and model location to trains backend (in addition to original output destination)
        :return: Task() object
        """

        def verify_defaults_match():
            validate = [
                ('project name', project_name, cls.__main_task.get_project_name()),
                ('task name', task_name, cls.__main_task.name),
                ('task type', task_type, cls.__main_task.task_type),
            ]

            for field, default, current in validate:
                if default is not None and default != current:
                    raise UsageError(
                        "Current task already created "
                        "and requested {field} '{default}' does not match current {field} '{current}'".format(
                            field=field,
                            default=default,
                            current=current,
                        )
                    )

        if cls.__main_task is not None:
            if not running_remotely():
                verify_defaults_match()

            return cls.__main_task

        # check that we are not a child process, in that case do nothing
        if PROC_MASTER_ID_ENV_VAR.get() and PROC_MASTER_ID_ENV_VAR.get() != os.getpid():
            class _TaskStub(object):
                def __call__(self, *args, **kwargs):
                    return self

                def __getattr__(self, attr):
                    return self

                def __setattr__(self, attr, val):
                    pass

            return _TaskStub()
        # set us as master process
        PROC_MASTER_ID_ENV_VAR.set(os.getpid())

        if task_type is None:
            # Backwards compatibility: if called from Task.current_task and task_type
            # was not specified, keep legacy default value of TaskTypes.training
            task_type = cls.TaskTypes.training

        try:
            if not running_remotely():
                task = cls._create_dev_task(
                    project_name,
                    task_name,
                    task_type,
                    reuse_last_task_id,
                )
                if output_uri:
                    task.output_uri = output_uri
            else:
                task = cls(
                    private=cls.__create_protection,
                    task_id=get_remote_task_id(),
                    log_to_backend=False,
                )
        except Exception:
            raise
        else:
            Task.__main_task = task
            # Patch argparse to be aware of the current task
            argparser_update_currenttask(Task.__main_task)
            if auto_connect_frameworks:
                PatchedMatplotlib.update_current_task(Task.__main_task)
                PatchAbsl.update_current_task(Task.__main_task)
                PatchSummaryToEventTransformer.update_current_task(task)
                # PatchModelCheckPointCallback.update_current_task(task)
                PatchTensorFlowEager.update_current_task(task)
                PatchKerasModelIO.update_current_task(task)
                PatchTensorflowModelIO.update_current_task(task)
                PatchPyTorchModelIO.update_current_task(task)
            # Check if parse args already called. If so, sync task parameters with parser
            if argparser_parseargs_called():
                parser, parsed_args = get_argparser_last_args()
                task._connect_argparse(parser=parser, parsed_args=parsed_args)

            # make sure all random generators are initialized with new seed
            make_deterministic(task.get_random_seed())

            if auto_connect_arg_parser:
                # Patch ArgParser to be aware of the current task
                argparser_update_currenttask(Task.__main_task)
                # Check if parse args already called. If so, sync task parameters with parser
                if argparser_parseargs_called():
                    parser, parsed_args = get_argparser_last_args()
                    task._connect_argparse(parser, parsed_args=parsed_args)

        # Make sure we start the logger, it will patch the main logging object and pipe all output
        # if we are running locally and using development mode worker, we will pipe all stdout to logger.
        # The logger will automatically take care of all patching (we just need to make sure to initialize it)
        task.get_logger()

        # Make sure we start the dev worker if required, otherwise it will only be started when we write
        # something to the log.
        task._dev_mode_task_start()

        return task

        Return the Task object for the main execution task (task context).

        :param project_name: project to create the task in (if project doesn't exist, it will be created)
        :param task_name: task name to be created (in development mode, not when running remotely)
        :param task_type: task type to be created (in development mode, not when running remotely)
        :param reuse_last_task_id: start with the previously used task id (stored in the data cache folder). \
            if False every time we call the function we create a new task with the same name \
            Notice! The reused task will be reset. (when running remotely, the usual behaviour applies) \
            Note: A closed or published task will not be reused, and a new task will be created.
        :param output_uri: Default location for output models (currently support folder/S3/GS/ ).
            notice: sub-folders (task_id) is created in the destination folder for all outputs.
        :param auto_connect_arg_parser: Automatically grab the ArgParser and connect it with the task.
            if set to false, you can manually connect the ArgParser with task.connect(parser)
        :param auto_connect_frameworks: If true automatically patch MatplotLib, Keras callbacks, and TensorBoard/X to
            serialize plots, graphs and model location to trains backend (in addition to original output destination)
        :return: Task() object
        
Return the Task object for the main execution task (task context).
Return the Task object for the main execution task ( task context ) .
def init(
        cls,
        project_name=None,
        task_name=None,
        task_type=TaskTypes.training,
        reuse_last_task_id=True,
        output_uri=None,
        auto_connect_arg_parser=True,
        auto_connect_frameworks=True,
    ):
        def verify_defaults_match():
            validate = [
                ('project name', project_name, cls.__main_task.get_project_name()),
                ('task name', task_name, cls.__main_task.name),
                ('task type', task_type, cls.__main_task.task_type),
            ]
            for field, default, current in validate:
                if default is not None and default != current:
                    raise UsageError(
                        "Current task already created "
                        "and requested {field} '{default}' does not match current {field} '{current}'".format(
                            field=field,
                            default=default,
                            current=current,
                        )
                    )
        if cls.__main_task is not None:
            if not running_remotely():
                verify_defaults_match()
            return cls.__main_task
        if PROC_MASTER_ID_ENV_VAR.get() and PROC_MASTER_ID_ENV_VAR.get() != os.getpid():
            class _TaskStub(object):
                def __call__(self, *args, **kwargs):
                    return self
                def __getattr__(self, attr):
                    return self
                def __setattr__(self, attr, val):
                    pass
            return _TaskStub()
        PROC_MASTER_ID_ENV_VAR.set(os.getpid())
        if task_type is None:
            task_type = cls.TaskTypes.training
        try:
            if not running_remotely():
                task = cls._create_dev_task(
                    project_name,
                    task_name,
                    task_type,
                    reuse_last_task_id,
                )
                if output_uri:
                    task.output_uri = output_uri
            else:
                task = cls(
                    private=cls.__create_protection,
                    task_id=get_remote_task_id(),
                    log_to_backend=False,
                )
        except Exception:
            raise
        else:
            Task.__main_task = task
            argparser_update_currenttask(Task.__main_task)
            if auto_connect_frameworks:
                PatchedMatplotlib.update_current_task(Task.__main_task)
                PatchAbsl.update_current_task(Task.__main_task)
                PatchSummaryToEventTransformer.update_current_task(task)
                PatchTensorFlowEager.update_current_task(task)
                PatchKerasModelIO.update_current_task(task)
                PatchTensorflowModelIO.update_current_task(task)
                PatchPyTorchModelIO.update_current_task(task)
            if argparser_parseargs_called():
                parser, parsed_args = get_argparser_last_args()
                task._connect_argparse(parser=parser, parsed_args=parsed_args)
            make_deterministic(task.get_random_seed())
            if auto_connect_arg_parser:
                argparser_update_currenttask(Task.__main_task)
                if argparser_parseargs_called():
                    parser, parsed_args = get_argparser_last_args()
                    task._connect_argparse(parser, parsed_args=parsed_args)
        task.get_logger()
        task._dev_mode_task_start()
        return task
def init ( cls , project_name = None , task_name = None , task_type = TaskTypes . training , reuse_last_task_id = True , output_uri = None , auto_connect_arg_parser = True , auto_connect_frameworks = True , ) : def verify_defaults_match ( ) : validate = [ ( 'project name' , project_name , cls . __main_task . get_project_name ( ) ) , ( 'task name' , task_name , cls . __main_task . name ) , ( 'task type' , task_type , cls . __main_task . task_type ) , ] for field , default , current in validate : if default is not None and default != current : raise UsageError ( "Current task already created " "and requested {field} '{default}' does not match current {field} '{current}'" . format ( field = field , default = default , current = current , ) ) if cls . __main_task is not None : if not running_remotely ( ) : verify_defaults_match ( ) return cls . __main_task if PROC_MASTER_ID_ENV_VAR . get ( ) and PROC_MASTER_ID_ENV_VAR . get ( ) != os . getpid ( ) : class _TaskStub ( object ) : def __call__ ( self , * args , ** kwargs ) : return self def __getattr__ ( self , attr ) : return self def __setattr__ ( self , attr , val ) : pass return _TaskStub ( ) PROC_MASTER_ID_ENV_VAR . set ( os . getpid ( ) ) if task_type is None : task_type = cls . TaskTypes . training try : if not running_remotely ( ) : task = cls . _create_dev_task ( project_name , task_name , task_type , reuse_last_task_id , ) if output_uri : task . output_uri = output_uri else : task = cls ( private = cls . __create_protection , task_id = get_remote_task_id ( ) , log_to_backend = False , ) except Exception : raise else : Task . __main_task = task argparser_update_currenttask ( Task . __main_task ) if auto_connect_frameworks : PatchedMatplotlib . update_current_task ( Task . __main_task ) PatchAbsl . update_current_task ( Task . __main_task ) PatchSummaryToEventTransformer . update_current_task ( task ) PatchTensorFlowEager . update_current_task ( task ) PatchKerasModelIO . update_current_task ( task ) PatchTensorflowModelIO . update_current_task ( task ) PatchPyTorchModelIO . update_current_task ( task ) if argparser_parseargs_called ( ) : parser , parsed_args = get_argparser_last_args ( ) task . _connect_argparse ( parser = parser , parsed_args = parsed_args ) make_deterministic ( task . get_random_seed ( ) ) if auto_connect_arg_parser : argparser_update_currenttask ( Task . __main_task ) if argparser_parseargs_called ( ) : parser , parsed_args = get_argparser_last_args ( ) task . _connect_argparse ( parser , parsed_args = parsed_args ) task . get_logger ( ) task . _dev_mode_task_start ( ) return task
Return the Task object for the main execution task (task context).
Return the Task object for the main execution task ( task context ) .
"""
        Return the Task object for the main execution task (task context).

        :param project_name: project to create the task in (if project doesn't exist, it will be created)
        :param task_name: task name to be created (in development mode, not when running remotely)
        :param task_type: task type to be created (in development mode, not when running remotely)
        :param reuse_last_task_id: start with the previously used task id (stored in the data cache folder). \
            if False every time we call the function we create a new task with the same name \
            Notice! The reused task will be reset. (when running remotely, the usual behaviour applies) \
            Note: A closed or published task will not be reused, and a new task will be created.
        :param output_uri: Default location for output models (currently support folder/S3/GS/ ).
            notice: sub-folders (task_id) is created in the destination folder for all outputs.
        :param auto_connect_arg_parser: Automatically grab the ArgParser and connect it with the task.
            if set to false, you can manually connect the ArgParser with task.connect(parser)
        :param auto_connect_frameworks: If true automatically patch MatplotLib, Keras callbacks, and TensorBoard/X to
            serialize plots, graphs and model location to trains backend (in addition to original output destination)
        :return: Task() object
        """ # check that we are not a child process, in that case do nothing # set us as master process # Backwards compatibility: if called from Task.current_task and task_type # was not specified, keep legacy default value of TaskTypes.training # Patch argparse to be aware of the current task # PatchModelCheckPointCallback.update_current_task(task) # Check if parse args already called. If so, sync task parameters with parser # make sure all random generators are initialized with new seed # Patch ArgParser to be aware of the current task # Check if parse args already called. If so, sync task parameters with parser # Make sure we start the logger, it will patch the main logging object and pipe all output # if we are running locally and using development mode worker, we will pipe all stdout to logger. # The logger will automatically take care of all patching (we just need to make sure to initialize it) # Make sure we start the dev worker if required, otherwise it will only be started when we write # something to the log.
None
cls
project_name
project to create the task in (if project doesn't exist, it will be created)
project to create the task in ( if project doesn ' t exist it will be created )
task_name
task name to be created (in development mode, not when running remotely)
task name to be created ( in development mode not when running remotely )
task_type
task type to be created (in development mode, not when running remotely)
task type to be created ( in development mode not when running remotely )
reuse_last_task_id
start with the previously used task id (stored in the data cache folder). \
if False every time we call the function we create a new task with the same name \
Notice. The reused task will be reset. (when running remotely, the usual behaviour applies) \
Note: A closed or published task will not be reused, and a new task will be created.
start with the previously used task id ( stored in the data cache folder ) . \ if False every time we call the function we create a new task with the same name \ Notice . The reused task will be reset . ( when running remotely the usual behaviour applies ) \ Note : A closed or published task will not be reused and a new task will be created .
output_uri
Default location for output models (currently support folder/S3/GS/ ).
notice: sub-folders (task_id) is created in the destination folder for all outputs.
Default location for output models ( currently support folder / S3 / GS / ) . notice : sub - folders ( task_id ) is created in the destination folder for all outputs .
auto_connect_arg_parser
Automatically grab the ArgParser and connect it with the task.
if set to false, you can manually connect the ArgParser with task.connect(parser)
Automatically grab the ArgParser and connect it with the task . if set to false you can manually connect the ArgParser with task . connect ( parser )
auto_connect_frameworks
If true automatically patch MatplotLib, Keras callbacks, and TensorBoard/X to
serialize plots, graphs and model location to trains backend (in addition to original output destination)
If true automatically patch MatplotLib Keras callbacks and TensorBoard / X to serialize plots graphs and model location to trains backend ( in addition to original output destination )