trains/model.py
def import_model(
        cls,
        weights_url,
        config_text=None,
        config_dict=None,
        label_enumeration=None,
        name=None,
        tags=None,
        comment=None,
        logger=None,
        is_package=False,
        create_as_published=False,
        framework=None,
    ):
        """
        Create a model from pre-existing model file (link must be valid), and model configuration.

        If the url to the weights file already exists, the import process will stop with a warning
        and automatically it will try to import the model that was found.
        The Model will be read-only and can be used to pre initialize a network
        We can connect the model to a task as input model, then when running remotely override it with the UI.
        Load model based on id, returned object is read-only and can be connected to a task
        That is, we can override the input model when running remotely

        :param weights_url: valid url for the weights file (string).
            examples: "https://domain.com/file.bin" or "s3://bucket/file.bin" or "file:///home/user/file.bin".
            NOTE: if a model with the exact same URL exists, it will be used, and all other arguments will be ignored.
        :param config_text: model configuration  (unconstrained text string). usually the content of
            configuration file. If `config_text` is not None, `config_dict` must not be provided.
        :param config_dict: model configuration parameters (dict).
            If `config_dict` is not None, `config_text` must not be provided.
        :param label_enumeration: dictionary of string to integer, enumerating the model output to labels
            example: {'background': 0 , 'person': 1}
        :param name: optional, name for the newly imported model
        :param tags: optional, list of strings as tags
        :param comment: optional, string description for the model
        :param logger: The logger to use. If None, use the default logger
        :param is_package: Boolean. Indicates that the imported weights file is a package.
            If True, and a new model was created, a package tag will be added.
        :param create_as_published: Boolean. If True, and a new model is created, it will be published.
        :param framework: optional, string name of the framework of the model or Framework
        """
        config_text = cls._resolve_config(config_text=config_text, config_dict=config_dict)
        weights_url = StorageHelper.conform_url(weights_url)
        result = _Model._get_default_session().send(models.GetAllRequest(
            uri=[weights_url],
            only_fields=["id", "name"],
            tags=["-" + ARCHIVED_TAG]
        ))

        if result.response.models:
            if not logger:
                logger = get_logger()

            logger.debug('A model with uri "{}" already exists. Selecting it'.format(weights_url))

            model = get_single_result(
                entity='model',
                query=weights_url,
                results=result.response.models,
                log=logger,
                raise_on_error=False,
            )

            logger.info("Selected model id: {}".format(model.id))

            return InputModel(model_id=model.id)

        base_model = _Model(
            upload_storage_uri=None,
            cache_dir=get_cache_dir(),
        )

        from .task import Task
        task = Task.current_task()
        if task:
            comment = 'Imported by task id: {}'.format(task.id) + ('\n'+comment if comment else '')
            project_id = task.project
            task_id = task.id
        else:
            project_id = None
            task_id = None

        if not framework:
            framework, file_ext = Framework._get_file_ext(
                framework=framework,
                filename=weights_url
            )

        base_model.update(
            design=config_text,
            labels=label_enumeration,
            name=name,
            comment=comment,
            tags=tags,
            uri=weights_url,
            framework=framework,
            project_id=project_id,
            task_id=task_id,
        )

        this_model = InputModel(model_id=base_model.id)
        this_model._base_model = base_model

        if is_package:
            this_model._set_package_tag()

        if create_as_published:
            this_model.publish()

        return this_model

        Create a model from pre-existing model file (link must be valid), and model configuration.

        If the url to the weights file already exists, the import process will stop with a warning
        and automatically it will try to import the model that was found.
        The Model will be read-only and can be used to pre initialize a network
        We can connect the model to a task as input model, then when running remotely override it with the UI.
        Load model based on id, returned object is read-only and can be connected to a task
        That is, we can override the input model when running remotely

        :param weights_url: valid url for the weights file (string).
            examples: "https://domain.com/file.bin" or "s3://bucket/file.bin" or "file:///home/user/file.bin".
            NOTE: if a model with the exact same URL exists, it will be used, and all other arguments will be ignored.
        :param config_text: model configuration  (unconstrained text string). usually the content of
            configuration file. If `config_text` is not None, `config_dict` must not be provided.
        :param config_dict: model configuration parameters (dict).
            If `config_dict` is not None, `config_text` must not be provided.
        :param label_enumeration: dictionary of string to integer, enumerating the model output to labels
            example: {'background': 0 , 'person': 1}
        :param name: optional, name for the newly imported model
        :param tags: optional, list of strings as tags
        :param comment: optional, string description for the model
        :param logger: The logger to use. If None, use the default logger
        :param is_package: Boolean. Indicates that the imported weights file is a package.
            If True, and a new model was created, a package tag will be added.
        :param create_as_published: Boolean. If True, and a new model is created, it will be published.
        :param framework: optional, string name of the framework of the model or Framework
        
Create a model from pre-existing model file (link must be valid), and model configuration.
If the url to the weights file already exists, the import process will stop with a warning
and automatically it will try to import the model that was found.
The Model will be read-only and can be used to pre initialize a network
We can connect the model to a task as input model, then when running remotely override it with the UI.
Load model based on id, returned object is read-only and can be connected to a task
That is, we can override the input model when running remotely
Create a model from pre - existing model file ( link must be valid ) and model configuration . If the url to the weights file already exists the import process will stop with a warning and automatically it will try to import the model that was found . The Model will be read - only and can be used to pre initialize a network We can connect the model to a task as input model then when running remotely override it with the UI . Load model based on id returned object is read - only and can be connected to a task That is we can override the input model when running remotely
def import_model(
        cls,
        weights_url,
        config_text=None,
        config_dict=None,
        label_enumeration=None,
        name=None,
        tags=None,
        comment=None,
        logger=None,
        is_package=False,
        create_as_published=False,
        framework=None,
    ):
        config_text = cls._resolve_config(config_text=config_text, config_dict=config_dict)
        weights_url = StorageHelper.conform_url(weights_url)
        result = _Model._get_default_session().send(models.GetAllRequest(
            uri=[weights_url],
            only_fields=["id", "name"],
            tags=["-" + ARCHIVED_TAG]
        ))
        if result.response.models:
            if not logger:
                logger = get_logger()
            logger.debug('A model with uri "{}" already exists. Selecting it'.format(weights_url))
            model = get_single_result(
                entity='model',
                query=weights_url,
                results=result.response.models,
                log=logger,
                raise_on_error=False,
            )
            logger.info("Selected model id: {}".format(model.id))
            return InputModel(model_id=model.id)
        base_model = _Model(
            upload_storage_uri=None,
            cache_dir=get_cache_dir(),
        )
        from .task import Task
        task = Task.current_task()
        if task:
            comment = 'Imported by task id: {}'.format(task.id) + ('\n'+comment if comment else '')
            project_id = task.project
            task_id = task.id
        else:
            project_id = None
            task_id = None
        if not framework:
            framework, file_ext = Framework._get_file_ext(
                framework=framework,
                filename=weights_url
            )
        base_model.update(
            design=config_text,
            labels=label_enumeration,
            name=name,
            comment=comment,
            tags=tags,
            uri=weights_url,
            framework=framework,
            project_id=project_id,
            task_id=task_id,
        )
        this_model = InputModel(model_id=base_model.id)
        this_model._base_model = base_model
        if is_package:
            this_model._set_package_tag()
        if create_as_published:
            this_model.publish()
        return this_model
def import_model ( cls , weights_url , config_text = None , config_dict = None , label_enumeration = None , name = None , tags = None , comment = None , logger = None , is_package = False , create_as_published = False , framework = None , ) : config_text = cls . _resolve_config ( config_text = config_text , config_dict = config_dict ) weights_url = StorageHelper . conform_url ( weights_url ) result = _Model . _get_default_session ( ) . send ( models . GetAllRequest ( uri = [ weights_url ] , only_fields = [ "id" , "name" ] , tags = [ "-" + ARCHIVED_TAG ] ) ) if result . response . models : if not logger : logger = get_logger ( ) logger . debug ( 'A model with uri "{}" already exists. Selecting it' . format ( weights_url ) ) model = get_single_result ( entity = 'model' , query = weights_url , results = result . response . models , log = logger , raise_on_error = False , ) logger . info ( "Selected model id: {}" . format ( model . id ) ) return InputModel ( model_id = model . id ) base_model = _Model ( upload_storage_uri = None , cache_dir = get_cache_dir ( ) , ) from . task import Task task = Task . current_task ( ) if task : comment = 'Imported by task id: {}' . format ( task . id ) + ( '\n' + comment if comment else '' ) project_id = task . project task_id = task . id else : project_id = None task_id = None if not framework : framework , file_ext = Framework . _get_file_ext ( framework = framework , filename = weights_url ) base_model . update ( design = config_text , labels = label_enumeration , name = name , comment = comment , tags = tags , uri = weights_url , framework = framework , project_id = project_id , task_id = task_id , ) this_model = InputModel ( model_id = base_model . id ) this_model . _base_model = base_model if is_package : this_model . _set_package_tag ( ) if create_as_published : this_model . publish ( ) return this_model
Create a model from pre-existing model file (link must be valid), and model configuration.
Create a model from pre - existing model file ( link must be valid ) and model configuration .
"""
        Create a model from pre-existing model file (link must be valid), and model configuration.

        If the url to the weights file already exists, the import process will stop with a warning
        and automatically it will try to import the model that was found.
        The Model will be read-only and can be used to pre initialize a network
        We can connect the model to a task as input model, then when running remotely override it with the UI.
        Load model based on id, returned object is read-only and can be connected to a task
        That is, we can override the input model when running remotely

        :param weights_url: valid url for the weights file (string).
            examples: "https://domain.com/file.bin" or "s3://bucket/file.bin" or "file:///home/user/file.bin".
            NOTE: if a model with the exact same URL exists, it will be used, and all other arguments will be ignored.
        :param config_text: model configuration  (unconstrained text string). usually the content of
            configuration file. If `config_text` is not None, `config_dict` must not be provided.
        :param config_dict: model configuration parameters (dict).
            If `config_dict` is not None, `config_text` must not be provided.
        :param label_enumeration: dictionary of string to integer, enumerating the model output to labels
            example: {'background': 0 , 'person': 1}
        :param name: optional, name for the newly imported model
        :param tags: optional, list of strings as tags
        :param comment: optional, string description for the model
        :param logger: The logger to use. If None, use the default logger
        :param is_package: Boolean. Indicates that the imported weights file is a package.
            If True, and a new model was created, a package tag will be added.
        :param create_as_published: Boolean. If True, and a new model is created, it will be published.
        :param framework: optional, string name of the framework of the model or Framework
        """
cls
weights_url
valid url for the weights file (string).
valid url for the weights file ( string ) .
config_text
model configuration  (unconstrained text string). usually the content of
configuration file. If `config_text` is not None, `config_dict` must not be provided.
model configuration ( unconstrained text string ) . usually the content of configuration file . If ` config_text ` is not None ` config_dict ` must not be provided .
config_dict
model configuration parameters (dict).
If `config_dict` is not None, `config_text` must not be provided.
model configuration parameters ( dict ) . If ` config_dict ` is not None ` config_text ` must not be provided .
label_enumeration
dictionary of string to integer, enumerating the model output to labels
example: {'background': 0 , 'person': 1}
dictionary of string to integer enumerating the model output to labels example : { ' background ' : 0 ' person ' : 1 }
name
optional, name for the newly imported model
optional name for the newly imported model
tags
optional, list of strings as tags
optional list of strings as tags
comment
optional, string description for the model
optional string description for the model
logger
The logger to use. If None, use the default logger
The logger to use . If None use the default logger
is_package
Boolean. Indicates that the imported weights file is a package.
If True, and a new model was created, a package tag will be added.
Boolean . Indicates that the imported weights file is a package . If True and a new model was created a package tag will be added .
create_as_published
Boolean. If True, and a new model is created, it will be published.
Boolean . If True and a new model is created it will be published .
framework
optional, string name of the framework of the model or Framework
optional string name of the framework of the model or Framework