softmax層内での計算方法
2 views (last 30 days)
Show older comments
MATLABのHPにあるドキュメンテーション「イメージ分類用の積層自己符号化器の学習」で求めた重み・バイアスの値を用いて、C言語で数字認識を行おうと考えています。
softmax層で行われている計算を、C言語で以下のように組んでいるのですが、数字認識の結果がMATLABとC言語で異なってしまいます。
以下の計算式とMATLAB内での計算の差異を教えていただけないでしょうか?
sum = 0.0;
for(j = 0; j < 10; j++){
Dst_soft[j] = 0.0;
for(i = 0; i < 50; i++){
a = input[i] * SW[j][i];
Dst_soft[j] = Dst_soft[j] + a;
}
Dst_soft[j] = Dst_soft[j] + SB[j];
sum = sum + exp(Dst_soft[j]);
}
for(j = 0; j < 10; j++){
Dst_soft[j] = exp(Dst_soft[j])/sum;
}
0 Comments
Accepted Answer
Kenta
on 24 Mar 2020
こんにちは、以下の通りです
a = softmax(n) = exp(n)/sum(exp(n))
また以下のような記載もあります。edit softmax と打てば出ます。
takes an SxQ matrix of S N-element net input column
% vectors and returns an SxQ matrix A of output vectors where each column
% vector of A sums to 1, with elements exponentially proportional to the
% respective elements in N.
また、カスタムループによるCNNでは、softmaxを関数として多く用いるので、その例の中で実際に使い、
想定した値と、softmax関数の返す値を比較すればより確実と思います。例えば以下の例など
More Answers (0)
See Also
Categories
Find more on イメージを使用した深層学習 in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!