Deep learning 如何在内部产品层中设置权重平方?
我从Deep learning 如何在内部产品层中设置权重平方?,deep-learning,conv-neural-network,caffe,inner-product,Deep Learning,Conv Neural Network,Caffe,Inner Product,我从Caffe开始,并且运行得很好。我需要在内积层中平方权重。Forward\u cpu函数表示权重,但我不知道如何将其平方 forward\u cpu功能定义如下: template <typename Dtype> void InnerProductLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype
Caffe
开始,并且运行得很好。我需要在内积层
中平方权重。Forward\u cpu
函数表示权重,但我不知道如何将其平方
forward\u cpu
功能定义如下:
template <typename Dtype>
void InnerProductLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,
const vector<Blob<Dtype>*>& top) {
const Dtype* bottom_data = bottom[0]->cpu_data();
Dtype* top_data = top[0]->mutable_cpu_data();
const Dtype* weight = this->blobs_[0]->cpu_data();
Dtype* sqr_weight;
caffe_sqr<Dtype>(this->blobs_[0]->count(), weight, sqr_weight);
caffe_cpu_gemm<Dtype>(CblasNoTrans, transpose_ ? CblasNoTrans : CblasTrans,
M_, N_, K_, (Dtype)1.,
bottom_data, weight, (Dtype)0., top_data);
if (bias_term_) {
caffe_cpu_gemm<Dtype>(CblasNoTrans, CblasNoTrans, M_, N_, 1, (Dtype)1.,
bias_multiplier_.cpu_data(),
this->blobs_[1]->cpu_data(), (Dtype)1., top_data);
}
}
在训练我的模型后,错误是:
F1229 20:00:38.622575 5272 mkl_alternate.hpp:34] Check failed: y
Check failure stack trace:
@ 0x7f4f97e675cd google::LogMessage::Fail()
@ 0x7f4f97e69433 google::LogMessage::SendToLog()
@ 0x7f4f97e6715b google::LogMessage::Flush()
@ 0x7f4f97e69e1e google::LogMessageFatal::~LogMessageFatal()
@ 0x7f4f98338760 vSqr<>()
@ 0x7f4f982eb45a caffe::PositiveInnerProductLayer<>::Forward_cpu()
@ 0x7f4f9830b0d3 caffe::Net<>::ForwardFromTo()
@ 0x7f4f9830b347 caffe::Net<>::ForwardPrefilled()
@ 0x7f4f981e075f caffe::Solver<>::Test()
@ 0x7f4f981e119e caffe::Solver<>::TestAll()
@ 0x7f4f981e12eb caffe::Solver<>::Step()
@ 0x7f4f981e1f85 caffe::Solver<>::Solve()
@ 0x40aafb train()
@ 0x406f48 main
@ 0x7f4f970f6830 __libc_start_main
@ 0x407609 _start
@ (nil) (unknown)
F1229 20:00:38.622575 5272 mkl_备用。hpp:34]检查失败:y
检查故障堆栈跟踪:
@0x7f4f97e675cd谷歌::日志消息::失败()
@0x7f4f97e69433 google::LogMessage::SendToLog()
@0x7f4f97e6715b谷歌::日志消息::刷新()
@0x7f4f97e69e1e谷歌::LogMessageFatal::~LogMessageFatal()
@0x7f4f98338760 vSqr()
@0x7f4f982eb45a caffe::PositiveInnerProductLayer::Forward_cpu()
@0x7f4f9830b0d3 caffe::Net::ForwardFromTo()
@0x7f4f9830b347 caffe::Net::ForwardPrefilled()
@0x7f4f981e075f caffe::解算器::测试()
@0x7f4f981e119e caffe::Solver::TestAll()
@0x7f4f981e12eb caffe::解算器::步骤()
@0x7f4f981e1f85 caffe::解算器::解算()
@0x40aafb列车()
@0x406f48主
@0x7f4f970f6830\uuuu libc\u start\u main
@0x407609_开始
@(无)(未知)
注意,weight
被定义为指向Dtype
的指针,指针没有count()
方法
您需要权重块的count()
:
this->blobs_[0]->count()
亲爱的@shai,非常感谢您的时间,但是如何计算重量@ahmadnavidghanizadehcaffe_sqr
有什么问题吗?亲爱的@shai,我编辑了我的问题。请检查一下。感谢您的关注。@ahmadnavidghanizadeh您需要预先分配内存。Blob temp;临时整形(此->水滴[0]->shape());sqr_权重=温度可变_cpu_数据();我能做到吗?找不到错误。对吗?
this->blobs_[0]->count()