我在OpenCV中使用随机森林时出现此错误:
OpenCV Error: Bad argument (5273-th value of 220-th (ordered) variable (=-1.70141e+38) is too large) in CvDTreeTrainData::set_data, file /home/XXX/Downloads/opencv-2.4.6.1/modules/ml/src/tree.cpp, line 551
terminate called after throwing an instance of 'cv::Exception'
what(): /home/XXX/Downloads/opencv-2.4.6.1/modules/ml/src/tree.cpp:551: error: (-5) 5273-th value of 220-th (ordered) variable (=-1.70141e+38) is too large in function CvDTreeTrainData::set_data
Aborted (core dumped)
这很奇怪,因为打印的数字不在浮动范围之外 (-3.4E + 38至+ 3.4E + 38)
我发现在opencv源代码中打印的位置,但我无法理解问题所在:
文件是tree.cpp
for( i = 0; i < sample_count; i++ )
{
float val = ord_nan;
int si = sidx ? sidx[i] : i;
if( !mask || !mask[(size_t)si*m_step] )
{
if( idata )
val = (float)idata[(size_t)si*step];
else
val = fdata[(size_t)si*step];
if( fabs(val) >= ord_nan )
{
sprintf( err, "%d-th value of %d-th (ordered) "
"variable (=%g) is too large", i, vi, val );
CV_ERROR( CV_StsBadArg, err );
}
num_valid++;
}
if (is_buf_16u)
udst[i] = (unsigned short)i; // TODO: memory corruption may be here
else
idst[i] = i;
_fdst[i] = val;
}
任何人都可以给我一个提示吗?
答案 0 :(得分:1)
如果您检查tree.cpp文件中的第551行,则可以看到fabs(val) >= ord_nan
所需的ord_nan = FLT_MAX*0.5f
。因此它在val == -1.70141e+38
时失败,因为它大于此限制。