mirror of
https://github.com/modelscope/modelscope.git
synced 2026-07-11 21:09:08 +02:00
[to #41999503] refine doc and requirements for linux and mac
1. refine quick start and pipeline doc 2. remove tf pytorch easynlp from requirements 3. lazy import for torch and tensorflow 4. test successfully on linux and mac intel cpu 5. update api doc Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/8882373
This commit is contained in:
@@ -27,7 +27,7 @@
|
||||
执行如下python代码
|
||||
```python
|
||||
>>> from maas_lib.pipelines import pipeline
|
||||
>>> img_matting = pipeline(task='image-matting', model_path='matting_person.pb')
|
||||
>>> img_matting = pipeline(task='image-matting', model='damo/image-matting-person')
|
||||
```
|
||||
|
||||
2. 传入单张图像url进行处理
|
||||
@@ -35,6 +35,8 @@
|
||||
>>> import cv2
|
||||
>>> result = img_matting('http://pai-vision-data-hz.oss-cn-zhangjiakou.aliyuncs.com/data/test/maas/image_matting/test.png')
|
||||
>>> cv2.imwrite('result.png', result['output_png'])
|
||||
>>> import os.path as osp
|
||||
>>> print(f'result file path is {osp.abspath("result.png")}')
|
||||
```
|
||||
|
||||
pipeline对象也支持传入一个列表输入,返回对应输出列表,每个元素对应输入样本的返回结果
|
||||
@@ -57,10 +59,12 @@
|
||||
pipeline函数支持传入实例化的预处理对象、模型对象,从而支持用户在推理过程中定制化预处理、模型。
|
||||
下面以文本情感分类为例进行介绍。
|
||||
|
||||
由于demo模型为EasyNLP提供的模型,首先,安装EasyNLP
|
||||
```shell
|
||||
pip install https://atp-modelzoo-sh.oss-cn-shanghai.aliyuncs.com/release/package/whl/easynlp-0.0.4-py2.py3-none-any.whl
|
||||
```
|
||||
|
||||
|
||||
注: 当前release版本还未实现AutoModel的语法糖,需要手动实例化模型,后续会加上对应语法糖简化调用
|
||||
|
||||
下载模型文件
|
||||
```shell
|
||||
wget https://atp-modelzoo-sh.oss-cn-shanghai.aliyuncs.com/release/easynlp_modelzoo/alibaba-pai/bert-base-sst2.zip && unzip bert-base-sst2.zip
|
||||
@@ -68,18 +72,17 @@ wget https://atp-modelzoo-sh.oss-cn-shanghai.aliyuncs.com/release/easynlp_modelz
|
||||
|
||||
创建tokenizer和模型
|
||||
```python
|
||||
>>> from maas_lib.models.nlp import SequenceClassificationModel
|
||||
>>> path = 'bert-base-sst2'
|
||||
>>> model = SequenceClassificationModel(path)
|
||||
>>> from maas_lib.models import Model
|
||||
>>> from maas_lib.preprocessors import SequenceClassificationPreprocessor
|
||||
>>> model = Model.from_pretrained('damo/bert-base-sst2')
|
||||
>>> tokenizer = SequenceClassificationPreprocessor(
|
||||
path, first_sequence='sentence', second_sequence=None)
|
||||
model.model_dir, first_sequence='sentence', second_sequence=None)
|
||||
```
|
||||
|
||||
使用tokenizer和模型对象创建pipeline
|
||||
```python
|
||||
>>> from maas_lib.pipelines import pipeline
|
||||
>>> semantic_cls = pipeline('text-classification', model=model, preprocessor=tokenizer)
|
||||
>>> semantic_cls = pipeline('text-classification', model=model, preprocessor=tokenizer)
|
||||
>>> semantic_cls("Hello world!")
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user