OpenCV 是否用零初始化权重矩阵,cv::ml::ANN_MLP
Does OpenCV initialize weights matrix with zeros, cv::ml::ANN_MLP
OpenCV 文档中提到了它 here
Artificial Neural Networks - Multi-Layer Perceptrons.
Unlike many other models in ML that are constructed and trained at
once, in the MLP model these steps are separated. First, a network
with the specified topology is created using the non-default
constructor or the method ANN_MLP::create. All the weights are set
to zeros. Then, the network is trained using a set of input and
output vectors. The training procedure can be repeated more than once,
that is, the weights can be adjusted based on the new training data.
还提到了:
UPDATE_WEIGHTS
Update the network weights, rather than compute them from scratch.
In the latter case the weights are initialized using the Nguyen-Widrow algorithm.
所以我想知道当我开始训练模型时权重初始化到底发生了什么。也感谢与 OpenCV 3.3.1 相关的答案
您有任何理由怀疑文档吗? OpenCV是开源库,下面的内容大家自己看吧here
ANN_MLPImpl()
{
clear();
setActivationFunction( SIGMOID_SYM, 0, 0);
setLayerSizes(Mat());
setTrainMethod(ANN_MLP::RPROP, 0.1, FLT_EPSILON);
}
当你调用train
时可能会调用init_weights()
bool train( const Ptr<TrainData>& trainData, int flags )
{
// Some code
// ... and link weights
if( !(flags & UPDATE_WEIGHTS) )
init_weights();
// Even more code
这里是init_weights()
void init_weights()
{
//... More code
// initialize weights using Nguyen-Widrow algorithm
for( j = 0; j < n2; j++ )
{
double s = 0;
// .. more initialization code
OpenCV 文档中提到了它 here
Artificial Neural Networks - Multi-Layer Perceptrons.
Unlike many other models in ML that are constructed and trained at once, in the MLP model these steps are separated. First, a network with the specified topology is created using the non-default constructor or the method ANN_MLP::create. All the weights are set to zeros. Then, the network is trained using a set of input and output vectors. The training procedure can be repeated more than once, that is, the weights can be adjusted based on the new training data.
还提到了:
UPDATE_WEIGHTS
Update the network weights, rather than compute them from scratch. In the latter case the weights are initialized using the Nguyen-Widrow algorithm.
所以我想知道当我开始训练模型时权重初始化到底发生了什么。也感谢与 OpenCV 3.3.1 相关的答案
您有任何理由怀疑文档吗? OpenCV是开源库,下面的内容大家自己看吧here
ANN_MLPImpl()
{
clear();
setActivationFunction( SIGMOID_SYM, 0, 0);
setLayerSizes(Mat());
setTrainMethod(ANN_MLP::RPROP, 0.1, FLT_EPSILON);
}
当你调用train
时可能会调用init_weights()
bool train( const Ptr<TrainData>& trainData, int flags )
{
// Some code
// ... and link weights
if( !(flags & UPDATE_WEIGHTS) )
init_weights();
// Even more code
这里是init_weights()
void init_weights()
{
//... More code
// initialize weights using Nguyen-Widrow algorithm
for( j = 0; j < n2; j++ )
{
double s = 0;
// .. more initialization code