您的位置:首页 > Web前端

Ubuntu16.04+CUDA9.1+cudnn-..-v7环境安装caffe runtest出现问题

2017-12-27 15:49 471 查看
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.6739168052989799, which exceeds threshold_ * scale, where
computed_gradient evaluates to 0.6739168052989799,
estimated_gradient evaluates to 0, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,143,0,119; feat = 0.6739168052989799; objective+ = -0.037382097476710979; objective- = -0.037382097476710979
[  FAILED  ] BatchReindexLayerTest/3.TestGradient, where TypeParam = caffe::GPUDevice<double> (1207 ms)

.......

[----------] Global test environment tear-down
[==========] 2123 tests from 281 test cases ran. (284030 ms total)
[  PASSED  ] 2122 tests.
[  FAILED  ] 1 test, listed below:
[  FAILED  ] BatchReindexLayerTest/3.TestGradient, where TypeParam = caffe::GPUDevice<double>

1 FAILED TEST
Makefile:532: recipe for target 'runtest' failed
make: *** [runtest] Error 1

错误如上面所示

不知道为什么别人好像没有这个错误

一个暂时的解决办法是将BatchReindexLayer的GPU版本中的forward和backward改回cpu执行

具体是将~/caffe/src/caffe/layers/batch_reindex_layer.cu修改为

#include <algorithm>
#include <utility>
#include <vector>

#include "caffe/layers/batch_reindex_layer.hpp"
#include "caffe/util/math_functions.hpp"

namespace caffe {

template<typename Dtype>
void BatchReindexLayer<Dtype>::Reshape(const vector<Blob<Dtype>*>& bottom,
const vector<Blob<Dtype>*>& top) {
CHECK_EQ(1, bottom[1]->num_axes());
vector<int> newshape;
newshape.push_back(bottom[1]->shape(0));
for (int i = 1; i < bottom[0]->shape().size(); ++i) {
newshape.push_back(bottom[0]->shape()[i]);
}
top[0]->Reshape(newshape);
}

template<typename Dtype>
void BatchReindexLayer<Dtype>::check_batch_reindex(int initial_num,
int final_num,
const Dtype* ridx_data) {
for (int i = 0; i < final_num; ++i) {
CHECK_GE(ridx_data[i], 0)
<< "Index specified for reindex layer was negative.";
CHECK_LT(ridx_data[i], initial_num)
<< "Index specified for reindex layer was greater than batch size.";
}
}

template<typename Dtype>
void BatchReindexLayer<Dtype>::Forward_gpu(const vector<Blob<Dtype>*>& bottom,
const vector<Blob<Dtype>*>& top) {
check_batch_reindex(bottom[0]->shape(0), bottom[1]->count(),
bottom[1]->cpu_data());
if (top[0]->count() == 0) {
return;
}
int inner_dim = bottom[0]->count() / bottom[0]->shape(0);
const Dtype* in = bottom[0]->cpu_data();
const Dtype* permut = bottom[1]->cpu_data();
Dtype* out = top[0]->mutable_cpu_data();
for (int index = 0; index < top[0]->count(); ++index) {
int n = index / (inner_dim);
int in_n = static_cast<int>(permut
);
out[index] = in[in_n * (inner_dim) + index % (inner_dim)];
}
}

template<typename Dtype>
void BatchReindexLayer<Dtype>::Backward_gpu(
const vector<Blob<Dtype>*>& top, const vector<bool>& propagate_down,
const vector<Blob<Dtype>*>& bottom) {
CHECK(!propagate_down[1]) << "Cannot backprop to index.";
if (!propagate_down[0]) {
return;
}
int inner_dim = bottom[0]->count() / bottom[0]->shape(0);
Dtype* bot_diff = bottom[0]->mutable_cpu_diff();
const Dtype* permut = bottom[1]->cpu_data();
const Dtype* top_diff = top[0]->cpu_diff();
caffe_set(bottom[0]->count(), Dtype(0), bot_diff);
for (int index = 0; index < top[0]->count(); ++index) {
int n = index / (inner_dim);
int in_n = static_cast<int>(permut
);
bot_diff[in_n * (inner_dim) + index % (inner_dim)] += top_diff[index];
}
}

INSTANTIATE_LAYER_GPU_FUNCS(BatchReindexLayer);

} // namespace caffe

希望能够帮助到大家,谢谢!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐