Optimum 文档
RyzenAI模型
并获得增强的文档体验
开始使用
RyzenAI模型
optimum.amd.ryzenai.pipeline
< 源 >( task model: typing.Optional[typing.Any] = None vaip_config: typing.Optional[str] = None model_type: typing.Optional[str] = None feature_extractor: typing.Union[str, ForwardRef('PreTrainedFeatureExtractor'), NoneType] = None image_processor: typing.Union[str, transformers.image_processing_utils.BaseImageProcessor, NoneType] = None use_fast: bool = True token: typing.Union[bool, str, NoneType] = None revision: typing.Optional[str] = None **kwargs ) → Pipeline
参数
- task (
str
) — 定义将返回哪个管道的任务。可用任务包括:- “image-classification”(图像分类)
- “object-detection”(目标检测)
- model (
Optional[Any]
, 默认为None
) — 管道将用于进行预测的模型。这可以是一个模型标识符或一个预训练模型的实际实例。如果未提供,将加载指定任务的默认模型。 - vaip_config (
Optional[str]
, 默认为None
) — 用于 Ryzen IPU 推理的运行时配置文件。默认配置文件可在 Ryzen AI VOE 包中找到,在安装过程中会提取名为vaip_config.json
的文件。 - model_type (
Optional[str]
, 默认为None
) — 模型的模型类型 - feature_extractor (
Union[str, "PreTrainedFeatureExtractor"]
, 默认为None
) — 管道将用于编码模型数据的特征提取器。这可以是一个模型标识符或一个实际的预训练特征提取器。 - image_processor (
Union[str, BaseImageProcessor]
, 默认为None
) — 管道将用于图像相关任务的图像处理器。 - use_fast (
bool
, 默认为True
) — 如果可能,是否使用快速分词器。 - token (
Union[str, bool
], 默认为None
) — 用作远程文件 HTTP 持有者授权的令牌。如果为 True,将使用运行huggingface-cli login
时生成的令牌(存储在~/.huggingface
中)。 - revision (
str
, 默认为None
) — 要使用的特定模型版本,指定为分支名称、标签名称或提交 ID。 - **kwargs — 传递给底层管道类的附加关键字参数。
返回
流水线
给定任务和模型的指定管道实例。
构建用于各种 RyzenAI 任务的管道的实用方法。
此函数为指定任务创建一个管道,利用给定模型或加载该任务的默认模型。该管道包括图像处理器和模型等组件。
计算机视觉
class optimum.amd.ryzenai.pipelines.TimmImageClassificationPipeline
< 源 >( model: typing.Union[ForwardRef('PreTrainedModel'), ForwardRef('TFPreTrainedModel')] tokenizer: typing.Optional[transformers.tokenization_utils.PreTrainedTokenizer] = None feature_extractor: typing.Optional[ForwardRef('SequenceFeatureExtractor')] = None image_processor: typing.Optional[transformers.image_processing_utils.BaseImageProcessor] = None processor: typing.Optional[transformers.processing_utils.ProcessorMixin] = None modelcard: typing.Optional[transformers.modelcard.ModelCard] = None framework: typing.Optional[str] = None task: str = '' args_parser: ArgumentHandler = None device: typing.Union[int, ForwardRef('torch.device')] = None torch_dtype: typing.Union[str, ForwardRef('torch.dtype'), NoneType] = None binary_output: bool = False **kwargs )
用法示例
import requests
from PIL import Image
from optimum.amd.ryzenai import pipeline
url = "http://images.cocodataset.org/val2017/000000039769.jpg"
image = Image.open(requests.get(url, stream=True).raw)
model_id = "mohitsha/timm-resnet18-onnx-quantized-ryzen"
pipe = pipeline("image-classification", model=model_id, vaip_config="vaip_config.json")
print(pipe(image))
class optimum.amd.ryzenai.pipelines.YoloObjectDetectionPipeline
< 源 >( model: typing.Union[ForwardRef('PreTrainedModel'), ForwardRef('TFPreTrainedModel')] tokenizer: typing.Optional[transformers.tokenization_utils.PreTrainedTokenizer] = None feature_extractor: typing.Optional[ForwardRef('SequenceFeatureExtractor')] = None image_processor: typing.Optional[transformers.image_processing_utils.BaseImageProcessor] = None processor: typing.Optional[transformers.processing_utils.ProcessorMixin] = None modelcard: typing.Optional[transformers.modelcard.ModelCard] = None framework: typing.Optional[str] = None task: str = '' args_parser: ArgumentHandler = None device: typing.Union[int, ForwardRef('torch.device')] = None torch_dtype: typing.Union[str, ForwardRef('torch.dtype'), NoneType] = None binary_output: bool = False **kwargs )
支持的模型类型
- yolox
- yolov3
- yolov5
- yolov8
用法示例
import requests
from PIL import Image
from optimum.amd.ryzenai import pipeline
img = ".\\image.jpg"
url = "http://images.cocodataset.org/val2017/000000039769.jpg"
image = Image.open(requests.get(url, stream=True).raw)
img = ".\\image2.jpg"
image = Image.open(img)
model_id = "amd/yolox-s"
detector = pipeline("object-detection", model=model_id, vaip_config="vaip_config.json", model_type="yolox")
detector = pipe(image)