Skip to content

Commit

Permalink
specify NetParameters directly in the SolverParameter
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffdonahue committed May 10, 2014
1 parent 6fcf5ed commit 65ef9ff
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
12 changes: 10 additions & 2 deletions src/caffe/proto/caffe.proto
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,16 @@ message NetParameter {
}

message SolverParameter {
optional string train_net = 1; // The proto file for the training net.
optional string test_net = 2; // The proto file for the testing net.
// {train,test}_net specify a path to a file containing the {train,test} net
// parameters; {train,test}_net_param specify the net parameters directly
// inside the SolverParameter.
//
// If {train,test}_net is specified, {train,test}_net_param should not be,
// and vice versa.
optional string train_net = 1; // The proto filename for the train net.
optional string test_net = 2; // The proto filename for the test net.
optional NetParameter train_net_param = 21; // Full params for the train net.
optional NetParameter test_net_param = 22; // Full params for the test net.
// The number of iterations for each testing phase.
optional int32 test_iter = 3 [default = 0];
// The number of iterations between two testing phases.
Expand Down
26 changes: 22 additions & 4 deletions src/caffe/solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,29 @@ void Solver<Dtype>::Init(const SolverParameter& param) {
Caffe::set_random_seed(param_.random_seed());
}
// Scaffolding code
LOG(INFO) << "Creating training net.";
net_.reset(new Net<Dtype>(param_.train_net()));
if (param_.has_test_net()) {
LOG(INFO) << "Creating testing net.";
if (param_.has_train_net_param()) {
CHECK(!param_.has_train_net()) << "Either train_net_param or train_net may "
<< "be specified, but not both.";
LOG(INFO) << "Creating training net specified in SolverParameter.";
net_.reset(new Net<Dtype>(param_.train_net_param()));
} else {
LOG(INFO) << "Creating training net from file: " << param_.train_net();
net_.reset(new Net<Dtype>(param_.train_net()));
}
bool has_test_net = false;
NetParameter test_net_param;
if (param_.has_test_net_param()) {
CHECK(!param_.has_test_net()) << "Either test_net_param or test_net may be "
<< "specified, but not both.";
LOG(INFO) << "Creating testing net specified in SolverParameter.";
test_net_.reset(new Net<Dtype>(param_.test_net_param()));
has_test_net = true;
} else if (param_.has_test_net()) {
LOG(INFO) << "Creating testing net from file: " << param_.test_net();
test_net_.reset(new Net<Dtype>(param_.test_net()));
has_test_net = true;
}
if (has_test_net) {
CHECK_GT(param_.test_iter(), 0);
CHECK_GT(param_.test_interval(), 0);
}
Expand Down

0 comments on commit 65ef9ff

Please sign in to comment.