Skip to content

Commit

Permalink
Add iter information to layer
Browse files Browse the repository at this point in the history
  • Loading branch information
eric612 committed Aug 23, 2019
1 parent 96bb265 commit de32caa
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
13 changes: 10 additions & 3 deletions include/caffe/layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,13 @@ class Layer {
}
param_propagate_down_[param_id] = value;
}


/**
*/
virtual void set_iter(int iter,int max_iter) {
iter_ = iter;
max_iter_ = max_iter;
}

protected:
/** The protobuf that stores the layer parameters */
LayerParameter layer_param_;
Expand All @@ -305,7 +310,9 @@ class Layer {
/** The vector that indicates whether each top blob has a non-zero weight in
* the objective function. */
vector<Dtype> loss_;

/**
*/
int iter_ , max_iter_;
/** @brief Using the CPU device, compute the layer output. */
virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,
const vector<Blob<Dtype>*>& top) = 0;
Expand Down
7 changes: 6 additions & 1 deletion include/caffe/net.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,10 @@ class Net {
void add_after_backward(Callback* value) {
after_backward_.push_back(value);
}

void set_iter(int iter,int max_iter) {
iter_ = iter;
max_iter_ = max_iter;
}
protected:
// Helpers for Init.
/// @brief Append a new top blob to the net.
Expand Down Expand Up @@ -335,6 +338,8 @@ class Net {
vector<Callback*> after_forward_;
vector<Callback*> before_backward_;
vector<Callback*> after_backward_;
int iter_;
int max_iter_;

DISABLE_COPY_AND_ASSIGN(Net);
};
Expand Down
1 change: 1 addition & 0 deletions src/caffe/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,7 @@ Dtype Net<Dtype>::ForwardFromTo(int start, int end) {
for (int c = 0; c < before_forward_.size(); ++c) {
before_forward_[c]->run(i);
}
layers_[i]->set_iter(iter_,max_iter_);
Dtype layer_loss = layers_[i]->Forward(bottom_vecs_[i], top_vecs_[i]);
loss += layer_loss;
if (debug_info_) { ForwardDebugInfo(i); }
Expand Down
1 change: 1 addition & 0 deletions src/caffe/solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ void Solver<Dtype>::Step(int iters) {
while (iter_ < stop_iter) {
// zero-init the params
net_->ClearParamDiffs();
net_->set_iter(iter_,stop_iter);
if (param_.test_interval() && iter_ % param_.test_interval() == 0
&& (iter_ > 0 || param_.test_initialization())) {
if (Caffe::root_solver()) {
Expand Down

0 comments on commit de32caa

Please sign in to comment.