Factory method to build an obj:`Pipeline`. Args: task (str): Task name defining which pipeline will be returned. model (str or List[str] or obj:`Model` or obj:list[`Model`]): (list of) model name or model object. preprocessor: preprocessor object. config_file (
(task: str = None,
model: Union[str, List[str], Model, List[Model]] = None,
preprocessor=None,
config_file: str = None,
pipeline_name: str = None,
framework: str = None,
device: str = None,
model_revision: Optional[str] = DEFAULT_MODEL_REVISION,
ignore_file_pattern: List[str] = None,
trust_remote_code: bool = False,
**kwargs)
| 73 | |
| 74 | |
| 75 | def pipeline(task: str = None, |
| 76 | model: Union[str, List[str], Model, List[Model]] = None, |
| 77 | preprocessor=None, |
| 78 | config_file: str = None, |
| 79 | pipeline_name: str = None, |
| 80 | framework: str = None, |
| 81 | device: str = None, |
| 82 | model_revision: Optional[str] = DEFAULT_MODEL_REVISION, |
| 83 | ignore_file_pattern: List[str] = None, |
| 84 | trust_remote_code: bool = False, |
| 85 | **kwargs) -> Pipeline: |
| 86 | """ Factory method to build an obj:`Pipeline`. |
| 87 | |
| 88 | |
| 89 | Args: |
| 90 | task (str): Task name defining which pipeline will be returned. |
| 91 | model (str or List[str] or obj:`Model` or obj:list[`Model`]): (list of) model name or model object. |
| 92 | preprocessor: preprocessor object. |
| 93 | config_file (str, optional): path to config file. |
| 94 | pipeline_name (str, optional): pipeline class name or alias name. |
| 95 | framework (str, optional): framework type. |
| 96 | model_revision: revision of model(s) if getting from model hub, for multiple models, expecting |
| 97 | all models to have the same revision |
| 98 | device (str, optional): whether to use gpu or cpu is used to do inference. |
| 99 | ignore_file_pattern(`str` or `List`, *optional*, default to `None`): |
| 100 | Any file pattern to be ignored in downloading, like exact file names or file extensions. |
| 101 | trust_remote_code (bool, optional): Whether to allow execution of remote code or |
| 102 | plugins declared in the model configuration. Defaults to False. |
| 103 | |
| 104 | Return: |
| 105 | pipeline (obj:`Pipeline`): pipeline object for certain task. |
| 106 | |
| 107 | Examples: |
| 108 | >>> # Using default model for a task |
| 109 | >>> p = pipeline('image-classification') |
| 110 | >>> # Using pipeline with a model name |
| 111 | >>> p = pipeline('text-classification', model='damo/distilbert-base-uncased') |
| 112 | >>> # Using pipeline with a model object |
| 113 | >>> resnet = Model.from_pretrained('Resnet') |
| 114 | >>> p = pipeline('image-classification', model=resnet) |
| 115 | >>> # Using pipeline with a list of model names |
| 116 | >>> p = pipeline('audio-kws', model=['damo/audio-tts', 'damo/auto-tts2']) |
| 117 | """ |
| 118 | if task is None and pipeline_name is None: |
| 119 | raise ValueError('task or pipeline_name is required') |
| 120 | |
| 121 | model_id = model[0] if isinstance(model, |
| 122 | list) and len(model) > 0 else model |
| 123 | _model_trusted = check_model_from_owner_group(model_id) |
| 124 | trust_remote_code = trust_remote_code or _model_trusted |
| 125 | pipeline_props = None |
| 126 | if pipeline_name is None: |
| 127 | # get default pipeline for this task |
| 128 | if isinstance(model, str) \ |
| 129 | or (isinstance(model, list) and isinstance(model[0], str)): |
| 130 | if is_official_hub_path(model, revision=model_revision): |
| 131 | # read config file from hub and parse |
| 132 | cfg = read_config( |
searching dependent graphs…