Optimum 文档

RyzenAI模型

您正在查看 main 版本,该版本需要从源代码安装。如果您想进行常规 pip 安装,请查看最新的稳定版本 (v1.24.0)。
Hugging Face's logo
加入 Hugging Face 社区

并获得增强的文档体验

开始使用

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) — 定义将返回哪个pipeline的任务。可用任务包括:
    • “图像分类”
    • “物体检测”
  • model (Optional[Any], 默认为 None) — pipeline将用于进行预测的模型。这可以是模型标识符或预训练模型的实际实例。如果未提供,则将加载指定任务的默认模型。
  • vaip_config (Optional[str], 默认为 None) — 使用 Ryzen IPU 进行推理的运行时配置文件。默认配置文件可以在 Ryzen AI VOE 包中找到,在安装期间解压,文件名为 vaip_config.json
  • model_type (Optional[str], 默认为 None) — 模型的模型类型
  • feature_extractor (Union[str, "PreTrainedFeatureExtractor"], 默认为 None) — pipeline将用于为模型编码数据的特征提取器。这可以是模型标识符或预训练特征提取器的实际实例。
  • image_processor (Union[str, BaseImageProcessor], 默认为 None) — pipeline将用于图像相关任务的图像处理器。
  • use_fast (bool, 默认为 True) — 是否在可能的情况下使用 Fast tokenizer。
  • token (Union[str, bool], 默认为 None) — 用作远程文件 HTTP Bearer 授权的令牌。如果为 True,将使用运行 huggingface-cli login 时生成的令牌(存储在 ~/.huggingface 中)。
  • revision (str, 默认为 None) — 要使用的特定模型版本,指定为分支名称、标签名称或提交 ID。
  • **kwargs — 传递给底层 pipeline 类的其他关键字参数。

返回

Pipeline

给定任务和模型的指定 pipeline 的一个实例。

用于为各种 RyzenAI 任务构建 pipeline 的实用方法。

此函数为指定任务创建一个 pipeline,利用给定的模型或加载任务的默认模型。该 pipeline 包括诸如图像处理器和模型之类的组件。

计算机视觉

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)
< > 在 GitHub 上更新