このページの翻訳は最新ではありません。ここをクリックして,英語の最新版を参照してください。
この例では,予測用の複数の出力ネットワークを組み立てる方法を説明します。
予測用のdlnetwork
オブジェクトを使用する代わりに,関数assembleNetwork
を使用して,予測の準備が整っているDAGNetwork
内にネットワークを組み立てることができます。これにより,データストアなどの他のデータ型で関数预测
を使用できます。
垫ファイルdlnetDigits.mat
からモデルパラメーターを読み込みます。垫ファイルには、カテゴリカル ラベルのスコアと数字イメージの回転角度の両方を予測するdlnetwork
オブジェクト,ならびにクラス名が含まれます。
s =负载(“dlnetDigits.mat”);dlnet = s.dlnet;一会= s.classNames;
関数layerGraph
を使用して,dlnetwork
オブジェクトから層グラフを抽出します。
lgraph = layerGraph (dlnet);
層グラフに出力層は含まれません。関数addLayers
およびconnectLayers
を使用し,層グラフに分類層と回帰層を追加します。
层= classificationLayer (“类”一会,“名字”,“coutput”);lgraph = addLayers (lgraph层);lgraph = connectLayers (lgraph,“softmax”,“coutput”);层= regressionLayer (“名字”,“routput”);lgraph = addLayers (lgraph层);lgraph = connectLayers (lgraph,“取得”,“routput”);
ネットワークのプロットを表示します。
图绘制(lgraph)
関数assembleNetwork
を使用してネットワークを組み立てます。
净= assembleNetwork (lgraph)
net = DAGNetwork with properties: Layers: [19x1 nnet.cnn.layer.Layer] Connections: [19x2 table] InputNames: {'in'} OutputNames: {'coutput' 'routput'}
テストデータを読み込みます。
[XTest, Y1Test Y2Test] = digitTest4DArrayData;
組み立てたネットワークを使用して予測を行うには,関数预测
を使用します。分類出力のカテゴリカルラベルを返すには,“ReturnCategorical”
オプションを真正的
に設定します。
[Y1Pred, Y2Pred] =预测(XTest净,“ReturnCategorical”,真正的);
分類精度を評価します。
精度=意味着(Y1Pred = = Y1Test)
精度= 0.9870
回帰精度を評価します。
angleRMSE = sqrt(mean(Y2Pred - Y2Test).^2))
angleRMSE =单6.0091
一部のイメージと,その予測を表示します。予測角度を赤,正解ラベルを緑で表示します。
idx = randperm(大小(XTest, 4), 9);数字为i = XTest(:,:,:,idx(i));imshow (I)在深圳=大小(我,1);抵消= sz / 2;thetaPred = Y2Pred (idx (i));情节(抵消* [1-tand (thetaPred) 1 +罐内(thetaPred)], [sz 0],“r——”) thetaValidation = Y2Test(idx(i));情节(抵消* [1-tand (thetaValidation) 1 +罐内(thetaValidation)], [sz 0],“g——”)举行从标签=字符串(Y1Pred (idx (i)));标题(”的标签:“+标签)结束
assembleNetwork
|batchNormalizationLayer
|convolution2dLayer
|fullyConnectedLayer
|预测
|reluLayer
|softmaxLayer