モデル使用可能性チェッカー
モデル使用可能性チェッカー
Section titled “モデル使用可能性チェッカー”モデル使用可能性チェッカーは、ONNXモデルを分析し、ORT Mobile、NNAPI、CoreMLでの使用に対する適合性を評価します。
python -m onnxruntime.tools.check_onnx_model_mobile_usability --helpusage: check_onnx_model_mobile_usability.py [-h] [--log_level {debug,info}] model_path
モバイルシナリオでの動作を判断するためにONNXモデルを分析します。
positional arguments: model_path チェックするONNXモデルへのパス
optional arguments: -h, --help このヘルプメッセージを表示して終了します --log_level {debug,info} ログレベル(デフォルト: info)NNAPIおよびCoreMLでの使用
Section titled “NNAPIおよびCoreMLでの使用”スクリプトは、モデル内の演算子がORTのNNAPI実行プロバイダー(EP)およびCoreML EPによってサポートされているかどうかをチェックします。サポートされている演算子の数と、それらがモデル内のどこにあるかに応じて、NNAPIまたはCoreMLの使用が有益である可能性があるかどうかを推定します。常にパフォーマンステストを実行して検証することをお勧めします。
このチェックからの出力例は次のようになります:
INFO: Checking resnet50-v1-7.onnx for usability with ORT Mobile.INFO: Checking NNAPIINFO: 1 partitions with a total of 121/122 nodes can be handled by the NNAPI EP.INFO: Partition sizes: [121]INFO: Unsupported nodes due to operator=0INFO: Caveats that have not been checked and may result in a node not actually being supported: ai.onnx:Conv:Only 2D Conv is supported. Weights and bias should be constant. ai.onnx:Gemm:If input B is not constant, transB should be 1. ai.onnx:GlobalAveragePool:Only 2D Pool is supported. ai.onnx:MaxPool:Only 2D Pool is supported.INFO: Unsupported nodes due to input having a dynamic shape=1INFO: NNAPI should work well for this model as there is one partition covering 99.2% of the nodes in the model.INFO: Model should perform well with NNAPI as is: YESモデルに動的入力形状がある場合、形状を固定サイズにすることで役立つかどうかを推定する追加チェックが行われます。詳細については、onnxruntime.tools.make_dynamic_shape_fixedを参照してください。
このチェックからの出力例:
INFO: Checking resnet50-v1-7.onnx for usability with ORT Mobile....INFO: Checking CoreML MLProgramINFO: 2 partitions with a total of 120/122 nodes can be handled by the CoreML MLProgram EP.INFO: Partition sizes: [119, 1]INFO: Unsupported nodes due to operator=1INFO: Unsupported ops: ai.onnx:FlattenINFO: Caveats that have not been checked and may result in a node not actually being supported: ai.onnx:Conv:Only 1D/2D Conv is supported. Bias if provided must be constant. ai.onnx:Gemm:Input B must be constant. ai.onnx:GlobalAveragePool:Only 2D Pool is supported currently. 3D and 5D support can be added if needed. ai.onnx:MaxPool:Only 2D Pool is supported currently. 3D and 5D support can be added if needed.INFO: Unsupported nodes due to input having a dynamic shape=1INFO: CoreML MLProgram can be considered for this model as there are two partitions covering 98.4% of the nodes. Performance testing is required to validate.INFO: Model should perform well with CoreML MLProgram as is: MAYBEINFO: --------INFO: Checking if model will perform better if the dynamic shapes are fixed...INFO: Partition information if the model was updated to make the shapes fixed:INFO: 2 partitions with a total of 121/122 nodes can be handled by the CoreML MLProgram EP.INFO: Partition sizes: [120, 1]INFO: Unsupported nodes due to operator=1INFO: Unsupported ops: ai.onnx:FlattenINFO: Caveats that have not been checked and may result in a node not actually being supported: ai.onnx:Conv:Only 1D/2D Conv is supported. Bias if provided must be constant. ai.onnx:Gemm:Input B must be constant. ai.onnx:GlobalAveragePool:Only 2D Pool is supported currently. 3D and 5D support can be added if needed. ai.onnx:MaxPool:Only 2D Pool is supported currently. 3D and 5D support can be added if needed.INFO: CoreML MLProgram can be considered for this model as there are two partitions covering 99.2% of the nodes. Performance testing is required to validate.INFO: Model should perform well with CoreML MLProgram if modified to have fixed input shapes: MAYBEINFO: Shapes can be altered using python -m onnxruntime.tools.make_dynamic_shape_fixed推奨事項が作成された理由についての詳細情報を提供する診断出力があります。
これには以下が含まれます:
- NNAPIおよびCoreML EPによってサポートされている、またはサポートされていない個々の演算子に関する情報
- サポートされている演算子がいくつのグループ(パーティションとも呼ばれる)に分割されているかに関する情報
- グループが多いほど、サポートされているノードのグループとサポートされていないノードのグループを切り替えるたびに、NPU(ニューラルプロセッシングユニット)とCPUの間で切り替える必要があるため、パフォーマンスが悪化します
最後に、スクリプトは使用するEPに関する推奨事項を提供します。
INFO: NNAPIまたはCoreMLがこのモデルでメリットを提供する可能性があるため、AndroidでNNAPI EPを使用する場合とiOSでCoreML EPを使用する場合のモデルのパフォーマンスを、CPU EPを使用する場合のパフォーマンスと比較することをお勧めします。