quantizationDetails
説明
例
この例では、ニューラル ネットワークの量子化詳細を表示する方法を示します。
事前学習済みのネットワークを読み込みます。net
は、MerchData
データ セット内のイメージを分類するために転移学習を使用して再学習させた SqueezeNet 畳み込みニューラル ネットワークです。
load squeezedlnetmerch
net
net = dlnetwork with properties: Layers: [67×1 nnet.cnn.layer.Layer] Connections: [74×2 table] Learnables: [52×3 table] State: [0×3 table] InputNames: {'data'} OutputNames: {'prob'} Initialized: 1 View summary with summary.
quantizationDetails 関数を使用して、ネットワークが量子化されていないことを確認します。
qDetails_original = quantizationDetails(net)
qDetails_original = struct with fields:
IsQuantized: 0
TargetLibrary: ""
QuantizedLayerNames: [0×0 string]
QuantizedLearnables: [0×3 table]
元のネットワークは単精度浮動小数点データ型を使用しているため、IsQuantized
フィールドは 0
(false) を返します。
MerchData イメージを解凍し、イメージ データストアとして読み込みます。augmentedImageDatastore オブジェクトを定義してネットワークのデータのサイズを変更し、量子化に使用するためにデータをキャリブレーション データ セットと検証データ セットに分割します。
unzip('MerchData.zip'); imds = imageDatastore('MerchData', ... 'IncludeSubfolders',true, ... 'LabelSource','foldernames'); [calData, valData] = splitEachLabel(imds, 0.7, 'randomized'); aug_calData = augmentedImageDatastore([227 227], calData); aug_valData = augmentedImageDatastore([227 227], valData);
dlquantizer
オブジェクトを作成し、量子化するネットワークを指定します。実行環境を MATLAB に設定します。MATLAB 実行環境を使用する場合、量子化は fi
固定小数点データ型を使用して実行されますが、これには Fixed-Point Designer™ のライセンスが必要です。
quantObj = dlquantizer(net,'ExecutionEnvironment','MATLAB');
calibrate 関数を使用して、サンプル入力でネットワークを実行し、範囲情報を収集します。
calResults = calibrate(quantObj,aug_calData);
quantize
メソッドを使用してネットワーク オブジェクトを量子化し、シミュレーション可能な量子化ネットワークを返します。
qNet = quantize(quantObj)
qNet = Quantized dlnetwork with properties: Layers: [67×1 nnet.cnn.layer.Layer] Connections: [74×2 table] Learnables: [52×3 table] State: [0×3 table] InputNames: {'data'} OutputNames: {'prob'} Initialized: 1 View summary with summary. Use the quantizationDetails function to extract quantization details.
量子化詳細を抽出するには、quantizationDetails
メソッドを使用します。
qDetails = quantizationDetails(qNet)
qDetails = struct with fields:
IsQuantized: 1
TargetLibrary: "none"
QuantizedLayerNames: [56×1 string]
QuantizedLearnables: [52×3 table]
QuantizedLayerNames
フィールドを検査して、量子化された層のリストを表示します。
qDetails.QuantizedLayerNames
ans = 56×1 string
"data"
"conv1"
"relu_conv1"
"pool1"
"fire2-squeeze1x1"
"fire2-relu_squeeze1x1"
"fire2-expand1x1"
"fire2-relu_expand1x1"
"fire2-expand3x3"
"fire2-relu_expand3x3"
"fire3-squeeze1x1"
"fire3-relu_squeeze1x1"
"fire3-expand1x1"
"fire3-relu_expand1x1"
"fire3-expand3x3"
"fire3-relu_expand3x3"
"fire4-squeeze1x1"
"fire4-relu_squeeze1x1"
"fire4-expand1x1"
"fire4-relu_expand1x1"
"fire4-expand3x3"
"fire4-relu_expand3x3"
"fire5-squeeze1x1"
"fire5-relu_squeeze1x1"
"fire5-expand1x1"
"fire5-relu_expand1x1"
"fire5-expand3x3"
"fire5-relu_expand3x3"
"fire6-squeeze1x1"
"fire6-relu_squeeze1x1"
⋮
QuantizedLearnables
フィールドを検査して、ネットワーク内の学習可能なパラメーターの量子化された値を確認します。
qDetails.QuantizedLearnables
ans=52×3 table
Layer Parameter Value
__________________ _________ ________________________
"conv1" "Weights" {3×3×3×64 embedded.fi}
"conv1" "Bias" {1×1×64 embedded.fi}
"fire2-squeeze1x1" "Weights" {1×1×64×16 embedded.fi}
"fire2-squeeze1x1" "Bias" {1×1×16 embedded.fi}
"fire2-expand1x1" "Weights" {1×1×16×64 embedded.fi}
"fire2-expand1x1" "Bias" {1×1×64 embedded.fi}
"fire2-expand3x3" "Weights" {3×3×16×64 embedded.fi}
"fire2-expand3x3" "Bias" {1×1×64 embedded.fi}
"fire3-squeeze1x1" "Weights" {1×1×128×16 embedded.fi}
"fire3-squeeze1x1" "Bias" {1×1×16 embedded.fi}
"fire3-expand1x1" "Weights" {1×1×16×64 embedded.fi}
"fire3-expand1x1" "Bias" {1×1×64 embedded.fi}
"fire3-expand3x3" "Weights" {3×3×16×64 embedded.fi}
"fire3-expand3x3" "Bias" {1×1×64 embedded.fi}
"fire4-squeeze1x1" "Weights" {1×1×128×32 embedded.fi}
"fire4-squeeze1x1" "Bias" {1×1×32 embedded.fi}
⋮
入力引数
量子化ニューラル ネットワーク。dlnetwork
オブジェクト、SeriesNetwork
オブジェクト、または DAGNetwork
オブジェクトとして指定します。
参考
アプリ
関数
トピック
- 深層ニューラル ネットワークの量子化
- オブジェクト検出器の層の量子化と CUDA コードの生成
- Classify Images on FPGA Using Quantized Neural Network (Deep Learning HDL Toolbox)
- Raspberry Pi での深層学習ネットワークの INT8 コードの生成 (MATLAB Coder)
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)