我想当迭代次数达到一定次数时改变损失层中的损失计算方法。
为了实现它,我认为我需要获取当前的学习率或迭代次数,然后我使用if
短语选择是否改变损失计算方法。
您可以添加一个成员变量咖啡类保存当前的学习率或迭代次数并在您想要的层中访问它。
例如,要获得您想要的当前迭代时间,您需要进行 3 个关键修改(为了简化):
-
In 通用.hpp https://github.com/BVLC/caffe/blob/master/include/caffe/common.hpp:
class Caffe {
public:
static Caffe& Get();
...//Some other public members
//Returns the current iteration times
inline static int current_iter() { return Get().cur_iter_; }
//Sets the current iteration times
inline static void set_cur_iter(int iter) { Get().cur_iter_ = iter; }
protected:
//The variable to save the current itertion times
int cur_iter_;
...//Some other protected members
}
-
In 求解器.cpp https://github.com/BVLC/caffe/blob/master/src/caffe/solver.cpp:
template <typename Dtype>
void Solver<Dtype>::Step(int iters) {
...
while (iter_ < stop_iter) {
Caffe::set_cur_iter(iter_ );
...//Left Operations
}
}
-
您要访问当前迭代次数的位置:
template <typename Dtype>
void SomeLayer<Dtype>::some_func() {
int current_iter = Caffe::current_iter();
...//Operations you want
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)