Solver<Dtype>::Solver(const SolverParameter& param) : param_(param), net_(), test_net_() { // Scaffolding code NetParameter train_net_param; ReadProtoFromTextFile(param_.train_net(), &train_net_param); LOG(INFO)<< "Creating training net."; net_.reset(new Net<Dtype>(train_net_param)); if (param_.has_test_net()) { LOG(INFO)<< "Creating testing net."; NetParameter test_net_param; ReadProtoFromTextFile(param_.test_net(), &test_net_param); test_net_.reset(new Net<Dtype>(test_net_param)); CHECK_GT(param_.test_iter(), 0); CHECK_GT(param_.test_interval(), 0); } LOG(INFO)<< "Solver scaffolding done."; }
Solver<Dtype>::Solver(const SolverParameter& param) : param_(param), net_(), test_net_() { // Scaffolding code NetParameter train_net_param; ReadProtoFromTextFile(param_.train_net(), &train_net_param); LOG(INFO) << "Creating training net."; net_.reset(new Net<Dtype>(train_net_param)); if (param_.has_test_net()) { LOG(INFO) << "Creating testing net."; NetParameter test_net_param; ReadProtoFromTextFile(param_.test_net(), &test_net_param); test_net_.reset(new Net<Dtype>(test_net_param)); CHECK_GT(param_.test_iter(), 0); CHECK_GT(param_.test_interval(), 0); } LOG(INFO) << "Installing info monitor."; for (int i = 0; i < param_.info_size(); ++i) { info_.push_back(shared_ptr<Info<Dtype> >(GetInfo<Dtype>(param_.info(i), net_))); } LOG(INFO) << "Solver scaffolding done."; }
void ReadNetParamsFromTextFileOrDie(const string& param_file, NetParameter* param) { CHECK(ReadProtoFromTextFile(param_file, param)) << "Failed to parse NetParameter file: " << param_file; if (NetNeedsUpgrade(*param)) { // NetParameter was specified using the old style (V0LayerParameter); try to // upgrade it. LOG(ERROR) << "Attempting to upgrade input file specified using deprecated " << "V0LayerParameter: " << param_file; NetParameter original_param(*param); if (!UpgradeV0Net(original_param, param)) { LOG(ERROR) << "Warning: had one or more problems upgrading " << "V0NetParameter to NetParameter (see above); continuing anyway."; } else { LOG(INFO) << "Successfully upgraded file specified using deprecated " << "V0LayerParameter"; } LOG(ERROR) << "Note that future Caffe releases will not support " << "V0NetParameter; use ./build/tools/upgrade_net_proto_text.bin to " << "upgrade this and any other network proto files to the new format."; } }
void ReadNetParamsFromTextFileOrDie(const string& param_file, NetParameter* param) { CHECK(ReadProtoFromTextFile(param_file, param)) << "Failed to parse NetParameter file: " << param_file; UpgradeNetAsNeeded(param_file, param); }
// Read parameters from a file into a SolverParameter proto message. void ReadSolverParamsFromTextFileOrDie(const string& param_file, SolverParameter* param) { CHECK(ReadProtoFromTextFile(param_file, param)) << "Failed to parse SolverParameter file: " << param_file; //UpgradeSolverAsNeeded(param_file, param); }
void DetectionOutputLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) { const DetectionOutputParameter& detection_output_param = this->layer_param_.detection_output_param(); CHECK(detection_output_param.has_num_classes()) << "Must specify num_classes"; num_classes_ = detection_output_param.num_classes(); share_location_ = detection_output_param.share_location(); num_loc_classes_ = share_location_ ? 1 : num_classes_; background_label_id_ = detection_output_param.background_label_id(); code_type_ = detection_output_param.code_type(); variance_encoded_in_target_ = detection_output_param.variance_encoded_in_target(); keep_top_k_ = detection_output_param.keep_top_k(); confidence_threshold_ = detection_output_param.has_confidence_threshold() ? detection_output_param.confidence_threshold() : -FLT_MAX; // Parameters used in nms. nms_threshold_ = detection_output_param.nms_param().nms_threshold(); CHECK_GE(nms_threshold_, 0.) << "nms_threshold must be non negative."; top_k_ = -1; if (detection_output_param.nms_param().has_top_k()) { top_k_ = detection_output_param.nms_param().top_k(); } const SaveOutputParameter& save_output_param = detection_output_param.save_output_param(); output_directory_ = save_output_param.output_directory(); if (!output_directory_.empty() && !boost::filesystem::is_directory(output_directory_)) { if (!boost::filesystem::create_directories(output_directory_)) { LOG(FATAL) << "Failed to create directory: " << output_directory_; } } output_name_prefix_ = save_output_param.output_name_prefix(); need_save_ = output_directory_ == "" ? false : true; output_format_ = save_output_param.output_format(); if (save_output_param.has_label_map_file()) { string label_map_file = save_output_param.label_map_file(); if (label_map_file.empty()) { // Ignore saving if there is no label_map_file provided. LOG(WARNING) << "Provide label_map_file if output results to files."; need_save_ = false; } else { LabelMap label_map; CHECK(ReadProtoFromTextFile(label_map_file, &label_map)) << "Failed to read label map file: " << label_map_file; CHECK(MapLabelToName(label_map, true, &label_to_name_)) << "Failed to convert label to name."; CHECK(MapLabelToDisplayName(label_map, true, &label_to_display_name_)) << "Failed to convert label to display name."; } } else { need_save_ = false; } if (save_output_param.has_name_size_file()) { string name_size_file = save_output_param.name_size_file(); if (name_size_file.empty()) { // Ignore saving if there is no name_size_file provided. LOG(WARNING) << "Provide name_size_file if output results to files."; need_save_ = false; } else { std::ifstream infile(name_size_file.c_str()); CHECK(infile.good()) << "Failed to open name size file: " << name_size_file; // The file is in the following format: // name height width // ... string name; int height, width; while (infile >> name >> height >> width) { names_.push_back(name); sizes_.push_back(std::make_pair(height, width)); } infile.close(); if (save_output_param.has_num_test_image()) { num_test_image_ = save_output_param.num_test_image(); } else { num_test_image_ = names_.size(); } CHECK_LE(num_test_image_, names_.size()); } } else {
inline void ReadProtoFromTextFile(const string& filename, Message* proto) { ReadProtoFromTextFile(filename.c_str(), proto); }
inline void ReadProtoFromTextFileOrDie(const char* filename, Message* proto) { CHECK(ReadProtoFromTextFile(filename, proto)); }
inline bool ReadProtoFromTextFile(const string& filename, Message* proto) { return ReadProtoFromTextFile(filename.c_str(), proto); }
Net<Dtype>::Net(const string& param_file) { NetParameter param; ReadProtoFromTextFile(param_file, ¶m); Init(param); }
FeedbackSolver<Dtype>::FeedbackSolver(const string& param_file) : net_(), test_net_() { SolverParameter param; ReadProtoFromTextFile(param_file, ¶m); Init(param); }