[英]no matching function for call to 'evaluate_net_weight' in C++11
我正在做一個深度學習項目,其中我編寫了一些測試來評估神經網絡中的凈重。 該代碼看起來像是evaluate_net_weight
:
/*! Compute the loss of the net as a function of the weight at index (i,j) in
* layer l. dx is added as an offset to the current value of the weight. */
//______________________________________________________________________________
template <typename Architecture>
auto evaluate_net_weight(TDeepNet<Architecture> &net, std::vector<typename Architecture::Matrix_t> & X,
const typename Architecture::Matrix_t &Y, const typename Architecture::Matrix_t &W, size_t l,
size_t k, size_t i, size_t j, typename Architecture::Scalar_t xvalue) ->
typename Architecture::Scalar_t
{
using Scalar_t = typename Architecture::Scalar_t;
Scalar_t prev_value = net.GetLayerAt(l)->GetWeightsAt(k).operator()(i,j);
net.GetLayerAt(l)->GetWeightsAt(k).operator()(i,j) = xvalue;
Scalar_t res = net.Loss(X, Y, W, false, false);
net.GetLayerAt(l)->GetWeightsAt(k).operator()(i,j) = prev_value;
//std::cout << "compute loss for weight " << xvalue << " " << prev_value << " result " << res << std::endl;
return res;
}
該函數被調用如下:
// Testing input gate: input weights k = 0
auto &Wi = layer->GetWeightsAt(0);
auto &dWi = layer->GetWeightGradientsAt(0);
for (size_t i = 0; i < (size_t) Wi.GetNrows(); ++i) {
for (size_t j = 0; j < (size_t) Wi.GetNcols(); ++j) {
auto f = [&lstm, &XArch, &Y, &weights, i, j](Scalar_t x) {
return evaluate_net_weight(lstm, XArch, Y, weights, 0, 0, i, j, x);
};
ROOT::Math::Functor1D func(f);
double dy = deriv.Derivative1(func, Wi(i,j), 1.E-5);
Double_t dy_ref = dWi(i,j);
// Compute relative error if dy != 0
Double_t error;
std::string errorType;
if (std::fabs(dy_ref) > 1e-15) {
error = std::fabs((dy - dy_ref) / dy_ref);
errorType = "relative";
} else {
error = std::fabs(dy - dy_ref);
errorType = "absolute";
}
if (debug) std::cout << "Input Gate: input weight gradients (" << i << "," << j << ") : (comp, ref) " << dy << ", " << dy_ref << std::endl;
if (error >= maximum_error) {
maximum_error = error;
maxErrorType = errorType;
}
}
}
XArch
是我的輸入, Y
是預測, lstm
是網絡類型。 這些已經定義。
當我嘗試使用cmake生成程序時,通常會出現以下錯誤:
/Users/harshitprasad/Desktop/gsoc-rnn/root/tmva/tmva/test/DNN/RNN/TestLSTMBackpropagation.h:385:24: error:
no matching function for call to 'evaluate_net_weight'
return evaluate_net_weight(lstm, XArch, Y, weights, 0, 2, i, j, x);
^~~~~~~~~~~~~~~~~~~
/Users/harshitprasad/Desktop/gsoc-rnn/root/tmva/tmva/test/DNN/RNN/TestLSTMBackpropagation.h:67:6: note:
candidate function [with Architecture = TMVA::DNN::TReference<double>] not viable: no known
conversion from 'Scalar_t' (aka 'TMatrixT<double>') to 'typename TReference<double>::Scalar_t'
(aka 'double') for 9th argument
auto evaluate_net_weight(TDeepNet<Architecture> &net, std::vector<typename Architecture::Matr...
我無法弄清楚,為什么會發生此錯誤? 如果有人可以幫助我解決這個問題,那就太好了。 謝謝!
在不同的范圍內,您對自定義類型Scalar_t
定義可能有不同且相互沖突的定義。
從錯誤消息中,我們可以看到該函數期望一個typename TReference<double>::Scalar_t
(相當於double
),但實際上您傳遞了一個Scalar_t
類型的參數(可能在全局范圍內定義),正如某些程序員所提到的那樣,它等效於TMatrixT<double>
,這會導致錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.