コード例 #1
0
def _lightly_cli(cfg, is_cli_call=True):

    cfg['loader']['shuffle'] = True
    cfg['loader']['drop_last'] = True
    checkpoint = _train_cli(cfg, is_cli_call)

    cfg['loader']['shuffle'] = False
    cfg['loader']['drop_last'] = False
    cfg['checkpoint'] = checkpoint

    embeddings = _embed_cli(cfg, is_cli_call)
    cfg['embeddings'] = embeddings

    if cfg['token'] and cfg['dataset_id']:
        _upload_cli(cfg)
コード例 #2
0
ファイル: core.py プロジェクト: lightly-ai/lightly
def embed_images(checkpoint: str, config_path: str = None, **kwargs):
    """Embed images with a self-supervised model.

    Calls the same function as lightly-embed. All arguments passed to
    lightly-embed can also be passed to this function (see below for an
    example).

    Args:
        checkpoint:
            Path to the checkpoint file for the embedding model.
        config_path:
            Path to config.yaml. If None, the default configs will be used.
        **kwargs:
            Overwrite default configs py passing keyword arguments.

    Returns:
        Embeddings, labels, and filenames of the images.

    Examples:
        >>> import lightly
        >>> my_checkpoint_path = 'path/to/checkpoint.ckpt'
        >>>
        >>> # embed images with default configs
        >>> embeddings, _, _ = lightly.embed_images(
        >>>     my_checkpoint_path, input_dir='path/to/data')
        >>>
        >>> # embed images with separate config file
        >>> my_config_path = 'my/config/file.yaml'
        >>> embeddings, _, _ = lightly.embed_images(
        >>>     my_checkpoint_path, input_dir='path/to/data', config_path=my_config_path)
        >>>
        >>> # embed images with default settings and overwrites: at inference,
        >>> # we can use larger input_sizes because it requires less memory.
        >>> my_collate = {input_size: 256}
        >>> embeddings, _, _ = lightly.embed_images(
        >>>     my_checkpoint_path, input_dir='path/to/data', collate=my_collate)
        >>> # the command above is equivalent to:
        >>> # lightly-embed input_dir='path/to/data' collate.input_size=256

    """
    config_path = _get_config_path(config_path)
    config_args = _load_config_file(config_path)
    config_args = _add_kwargs(config_args, kwargs)

    config_args['checkpoint'] = checkpoint

    return _embed_cli(config_args, is_cli_call=False)
コード例 #3
0
def _lightly_cli(cfg, is_cli_call=True):

    cfg['loader']['shuffle'] = True
    cfg['loader']['drop_last'] = True
    if cfg['trainer']['max_epochs'] > 0:
        checkpoint = _train_cli(cfg, is_cli_call)
    else:
        checkpoint = ''

    cfg['loader']['shuffle'] = False
    cfg['loader']['drop_last'] = False
    cfg['checkpoint'] = checkpoint

    embeddings = _embed_cli(cfg, is_cli_call)
    cfg['embeddings'] = embeddings

    if cfg['token'] and (cfg['dataset_id'] or cfg['new_dataset_name']):
        _upload_cli(cfg)   
コード例 #4
0
def _lightly_cli(cfg, is_cli_call=True):

    cfg['loader']['shuffle'] = True
    cfg['loader']['drop_last'] = True
    if cfg['trainer']['max_epochs'] > 0:
        print('#' * 10 + ' Starting to train an embedding model.')
        checkpoint = _train_cli(cfg, is_cli_call)
    else:
        checkpoint = ''

    cfg['loader']['shuffle'] = False
    cfg['loader']['drop_last'] = False
    cfg['checkpoint'] = checkpoint

    print('#' * 10 + ' Starting to embed your dataset.')
    embeddings = _embed_cli(cfg, is_cli_call)
    cfg['embeddings'] = embeddings

    if cfg['token'] and (cfg['dataset_id'] or cfg['new_dataset_name']):
        print('#' * 10 +
              ' Starting to upload your dataset to the Lightly platform.')
        _upload_cli(cfg)

    print('#' * 10 + ' Finished')