Optimum 文件

模型

您正在檢視的是需要從原始碼安裝。如果你希望進行常規的 pip 安裝,請檢視最新穩定版本 (v1.27.0)。
Hugging Face's logo
加入 Hugging Face 社群

並獲得增強的文件體驗

開始使用

模型

通用模型類

以下 Furiosa 類可用於例項化不帶特定頭的基本模型類。

FuriosaAI模型

class optimum.furiosa.FuriosaAIModel

< >

( model config: PretrainedConfig = None compute_metrics: typing.Optional[typing.Callable[[transformers.trainer_utils.EvalPrediction], typing.Dict]] = None label_names: typing.Optional[typing.List[str]] = None **kwargs )

評估迴圈

< >

( dataset: Dataset )

引數

  • 資料集 (datasets.Dataset) — 用於評估步驟的資料集。

執行評估並返回指標和預測結果。

< >

( device: str )

使用指定的 device 進行推理。例如:“cpu”或“gpu”。device 可以是大寫或小寫。為了加快首次推理,請在呼叫 .to() 後呼叫 .compile()

計算機視覺

以下類可用於以下計算機視覺任務。

FuriosaAIModelForImageClassification

class optimum.furiosa.FuriosaAIModelForImageClassification

< >

( model = None config = None **kwargs )

引數

  • 模型 (furiosa.runtime.model) — 用於執行推理的主要類。
  • 配置 (transformers.PretrainedConfig) — PretrainedConfig 是模型配置類,包含模型的所有引數。使用配置檔案初始化不會載入與模型相關的權重,只加載配置。請檢視 ~furiosa.modeling.FuriosaAIBaseModel.from_pretrained 方法以載入模型權重。
  • 裝置 (str, 預設為 "CPU") — 模型將為其最佳化的裝置型別。生成的編譯模型將包含特定於該裝置的節點。
  • furiosa_config (Optional[Dict], 預設為 None) — 包含模型編譯相關資訊的字典。
  • 編譯 (bool, 預設為 True) — 設定為 False 時,停用載入步驟中的模型編譯。

帶有 ImageClassifierOutput 的 FuriosaAI 模型,用於影像分類任務。

該模型繼承自 optimum.furiosa.FuriosaAIBaseModel。有關庫為其所有模型實現的通用方法(如下載或儲存),請檢視超類文件。

前向

< >

( pixel_values: typing.Union[torch.Tensor, numpy.ndarray] **kwargs )

引數

  • 畫素值 (torch.Tensor) — 當前批次影像對應的畫素值。畫素值可以使用 AutoFeatureExtractor 從編碼影像中獲取。

FuriosaAIModelForImageClassification 的前向方法,覆蓋了 __call__ 特殊方法。

雖然前向傳遞的實現需要在該函式內部定義,但之後應該呼叫 Module 例項而不是直接呼叫此函式,因為前者負責執行預處理和後處理步驟,而後者則默默忽略它們。

使用 transformers.pipelines 進行影像分類的示例

>>> from transformers import AutoFeatureExtractor, pipeline
>>> from optimum.furiosa import FuriosaAIModelForImageClassification

>>> preprocessor = AutoFeatureExtractor.from_pretrained("microsoft/resnet50")
>>> model = FuriosaAIModelForImageClassification.from_pretrained("microsoft/resnet50", export=True, input_shape_dict="dict('pixel_values': [1, 3, 224, 224])", output_shape_dict="dict("logits": [1, 1000])",)
>>> pipe = pipeline("image-classification", model=model, feature_extractor=preprocessor)
>>> url = "http://images.cocodataset.org/val2017/000000039769.jpg"
>>> outputs = pipe(url)

© . This site is unofficial and not affiliated with Hugging Face, Inc.