FAQ (常見問題集)FAQ (Frequently Asked Questions)

此頁面包含來自社群最熱門問題的解答。This page contains answers to the most popular questions from the community.

如何知道我的 ONNX 模型是否會與 Windows ML 搭配執行?How do I know if the ONNX model I have will run with Windows ML?

檢查您的模型是否會與 Windows ML 搭配執行最簡單的方法,是使用 WinML 模型執行器工具The easiest way to check if your model will run with Windows ML is by using the WinML Model Runner tool. 或者,您也可以參閱 ONNX 版本和 Windows 組建,以取得指定 Windows 版本所有支援 ONNX 版本的詳細資訊。Alternatively, you can check ONNX versions and Windows builds for more information on all supported ONNX versions for a given Windows release.

如何將不同格式的模型轉換成 ONNX?How do I convert a model of a different format to ONNX?

您可以使用 WinMLTools,將數種不同格式的模型 (例如 Apple CoreML 和 scikit-learn) 轉換成 ONNX。You can use WinMLTools to convert models of several different formats, such as Apple CoreML and scikit-learn, to ONNX.

我在嘗試匯出和/或將模型轉換成 ONNX 時遇到錯誤,錯誤顯示我的模型有「不支援的運算子」。I am getting errors when trying to export and/or convert my model to ONNX that say my model has "unsupported operators." 我該怎麼做?What should I do?

ONNX 版本目前可能不支援原生定型架構中的某些運算子。Some operators in the native training framework might not be currently supported by an ONNX version. 首先,建議您檢查支援的目標 Windows 組建的 ONNX 版本,並嘗試將您的模型轉換成支援的最大版本。First, we recommend you check supported ONNX versions for your target Windows build, and try to convert your model to the max supported version. 較新版本的 ONNX 相較於舊版,包含較大的運算子集合支援。Later versions of ONNX include support for a larger set of operators compared to previous versions.

如果您持續遇到問題,建議您與資料科學小組合作,以嘗試避免不支援的運算子。If you continue to run into issues, we recommend working with your data science team to try and avoid the unsupported operators. 我們建議的其中一個方法是在來源架構中變更模型的架構,並嘗試將模型轉換/匯出至目標 ONNX 版本。One of the approaches we recommend is to change the model's architecture in the source framework and attempt to convert/export the model to the target ONNX version. 請注意,您還不需要重新定型模型—您可以嘗試轉換架構,如果成功,您可以繼續進行模型的完整重新定型。Note that you don't need to retrain the model yet—you can attempt to convert the architecture and, if successful, then you can move on to full retraining of your model.

為什麼無法載入模型?Why can't I load a model?

您無法載入模型可能有數個原因,但是在 UWP 上進行開發時,其中一個最常見的原因是檔案存取限制所致。There are several reasons why you might have trouble loading a model, but one of the most common ones when developing on UWP is due to file access restrictions. 根據預設,UWP 應用程式只能存取檔案系統的某些部分,而且需要使用者權限或額外的功能,才能存取其他位置。By default, UWP applications can only access certain parts of the file system, and require user permission or extra capabilities in order to access other locations. 如需詳細資訊,請參閱檔案存取權限See File access permissions for more information.

應該使用哪一個版本的 WinMLTools?Which version of WinMLTools should I use?

我們一律建議您下載並安裝最新版的 winmltools 套件。We always recommend you download and install the latest version of the winmltools package. 這樣能夠確保您可以建立以最新版本 Windows 為目標的 ONNX 模型。This will ensure you can create ONNX models that target the latest versions of Windows.

我可以使用 onnxmltools 而不是 winmltools 嗎?Can I use onnxmltools instead of winmltools?

是,您可以,但是您必須確定安裝正確的 onnxmltools 版本,才能將目標設為 ONNX v1.2.2,這是 Windows ML 所支援的最低 ONNX 版本。Yes, you can, but you will need to make sure you install the correct version of onnxmltools in order to target ONNX v1.2.2, which is the minimum ONNX version supported by Windows ML. 如果您不確定要安裝哪個版本,建議您改為安裝最新版本的 winmltoolsIf you are unsure of which version to install, we recommend installing the latest version of winmltools instead. 這樣能夠確保您可以 Windows 支援的 ONNX 版本為目標。This will ensure you will be able to target the ONNX version supported by Windows.

我應該使用哪一個版本的 Visual Studio 來取得自動產生程式碼 (mlgen)?Which version of Visual Studio should I use in order to get automatic code generation (mlgen)?

具有 mlgen 支援的 Visual Studio 最低建議版本是 15.8.7。The minimum recommended version of Visual Studio with support for mlgen is 15.8.7. 在 Windows 10 版本 1903 和更新版本中,mlgen 已不再包含在 SDK 中,因此您必須下載並安裝擴充功能。In Windows 10, version 1903 and later, mlgen is no longer included in the SDK, so you'll need to download and install the extension. 有一個適用於 Visual Studio 2017,另一個適用於 Visual Studio 2019There is one for Visual Studio 2017 and one for Visual Studio 2019.

我在嘗試執行 mlgen 時收到錯誤訊息,而且未產生任何程式碼。I get an error message when trying to run mlgen and no code is generated. 發生什麼情況?What could possibly be happening?

嘗試執行 mlgen 時,最常見的兩個錯誤是:The two most common errors when trying to execute mlgen are:

  • 缺少必要的屬性 'consumed_inputs' :如果您遇到這個錯誤訊息,則很可能是您嘗試使用比 17763 還要舊的 Windows 10 SDK 版本來執行 ONNX v1.2 模型;我們建議您檢查 SDK 版本,並將其更新為 17763 版或更新版本。Required attribute 'consumed_inputs' is missing: If you run into this error message, then most likely you are trying to run an ONNX v1.2 model with a version of the Windows 10 SDK older than 17763; we recommend that you check your SDK version and update it to version 17763 or later.
  • 類型錯誤:節點 (ZipMap) 的輸出引數 (loss) 類型 (map(string,tensor(float))) 不符合預期類型... :如果您遇到此錯誤,則最有可能是 ONNX 模型的版本比 WinML 從組建 17763 開始所能接受的版本還要舊。Type Error: Type (map(string,tensor(float))) of output arg (loss) of node (ZipMap) does not match the expected type...: If you run into this error, then most likely your ONNX model is an older version than the one accepted by WinML starting with build 17763. 我們建議您將您的轉換器套件更新為最新的可用版本,並將您的模型重新轉換為 1.2 版的 ONNX。We recommend that you update your converter package to the latest available version and reconvert your model to the 1.2 version of ONNX.

WinML 預設會在什麼裝置上執行?What does WinML run on by default?

如果您未使用 LearningModelDeviceKind 指定執行所在的裝置,或者如果您使用 LearningModelDeviceKind.Default,則系統會決定哪一個裝置將評估模型。If you don't specify a device to run on with LearningModelDeviceKind, or if you use LearningModelDeviceKind.Default, the system will decide which device will evaluate the model. 這通常是 CPU。This is usually the CPU. 若要在 GPU 上執行 WinML,請在建立 LearningModelDevice 時指定下列其中一個值:To make WinML run on the GPU, specify one of the following values when creating the LearningModelDevice:

  • LearningModelDeviceKind.DirectXLearningModelDeviceKind.DirectX
  • LearningModelDeviceKind.DirectXHighPerformanceLearningModelDeviceKind.DirectXHighPerformance
  • LearningModelDeviceKind.DirectXMinPowerLearningModelDeviceKind.DirectXMinPower

注意

使用下列資源取得 Windows ML 的說明:Use the following resources for help with Windows ML:

  • 如需詢問或回答有關 Windows ML 的技術問題,請使用 Stack Overflow 上的 windows-machine-learning 標籤。To ask or answer technical questions about Windows ML, please use the windows-machine-learning tag on Stack Overflow.
  • 如需回報錯誤 (bug),請在 GitHub 上提出問題。To report a bug, please file an issue on our GitHub.
  • 如需要求功能,請前往 Windows 開發人員意見反應To request a feature, please head over to Windows Developer Feedback.