caffe-ssd模型训练遇到的问题(需要修改源码)
程序员文章站
2022-06-23 21:11:48
这遇到的几个问题反应了一个问题,就是caffe现在不火了,源码中存在很多的bug。问题1:math_functions.cpp:250] Check failed: a <= b <0 vs -1.19209e-007>解决方案找到math_functions.cpp,找到在路径为~/caffe/src/caffe/util的math_functions.cpp,找到第250行出错的地方,双斜杠屏蔽,然后重新编译问题2Data layer prefetch queue empt...
这遇到的几个问题反应了一个问题,就是caffe现在不火了,源码中存在很多的bug。
问题1:
math_functions.cpp:250] Check failed: a <= b <0 vs -1.19209e-007>
解决方案
找到math_functions.cpp,找到在路径为~/caffe/src/caffe/util的math_functions.cpp,找到第250行出错的地方,双斜杠屏蔽,然后重新编译
问题2
Data layer prefetch queue empty
解决方案:
找到在路径为~/caffe/src/caffe/util/sampler.cpp,如下代码(我用)
void SampleBBox(const Sampler& sampler, NormalizedBBox* sampled_bbox) {
// Get random scale.
CHECK_GE(sampler.max_scale(), sampler.min_scale());
CHECK_GT(sampler.min_scale(), 0.);
CHECK_LE(sampler.max_scale(), 1.);
float scale;
caffe_rng_uniform(1, sampler.min_scale(), sampler.max_scale(), &scale);
// Get random aspect ratio.
CHECK_GE(sampler.max_aspect_ratio(), sampler.min_aspect_ratio());
CHECK_GT(sampler.min_aspect_ratio(), 0.);
CHECK_LT(sampler.max_aspect_ratio(), FLT_MAX);
float aspect_ratio;
caffe_rng_uniform(1, sampler.min_aspect_ratio(), sampler.max_aspect_ratio(),
&aspect_ratio);
aspect_ratio = std::max<float>(aspect_ratio, std::pow(scale, 2.));
aspect_ratio = std::min<float>(aspect_ratio, 1 / std::pow(scale, 2.));
// Figure out bbox dimension.
float bbox_width = scale * sqrt(aspect_ratio);
float bbox_height = scale / sqrt(aspect_ratio);
////////////////////////////////////////////////添加的代码
if(bbox_width>=1.0){
bbox_width=1.0;
}
if(bbox_height>=1.0){
bbox_height=1.0;
}
///////////////////////////////////////////
// Figure out top left coordinates.
float w_off, h_off;
caffe_rng_uniform(1, 0.f, 1 - bbox_width, &w_off);
caffe_rng_uniform(1, 0.f, 1 - bbox_height, &h_off);
sampled_bbox->set_xmin(w_off);
sampled_bbox->set_ymin(h_off);
sampled_bbox->set_xmax(w_off + bbox_width);
sampled_bbox->set_ymax(h_off + bbox_height);
}
void GenerateSamples(const NormalizedBBox& source_bbox,
const vector<NormalizedBBox>& object_bboxes,
const BatchSampler& batch_sampler,
vector<NormalizedBBox>* sampled_bboxes) {
int found = 0;
for (int i = 0; i < batch_sampler.max_trials(); ++i) {
if (batch_sampler.has_max_sample() &&
found >= batch_sampler.max_sample()) {
break;
}
// Generate sampled_bbox in the normalized space [0, 1].
NormalizedBBox sampled_bbox;
SampleBBox(batch_sampler.sampler(), &sampled_bbox);
// Transform the sampled_bbox w.r.t. source_bbox.
LocateBBox(source_bbox, sampled_bbox, &sampled_bbox);
// Determine if the sampled bbox is positive or negative by the constraint.
if (SatisfySampleConstraint(sampled_bbox, object_bboxes,
batch_sampler.sample_constraint())) {
++found;
sampled_bboxes->push_back(sampled_bbox);
}
}
}
然后重新编译 终于完成了
本文地址:https://blog.csdn.net/qq_32582681/article/details/107246740