Unverified Commit 614f69d4 authored by Guolin Ke's avatar Guolin Ke Committed by GitHub
Browse files

fix load parameter (#1495)

parent c948194d
...@@ -456,8 +456,10 @@ protected: ...@@ -456,8 +456,10 @@ protected:
std::unique_ptr<ObjectiveFunction> loaded_objective_; std::unique_ptr<ObjectiveFunction> loaded_objective_;
bool average_output_; bool average_output_;
bool need_re_bagging_; bool need_re_bagging_;
std::string loaded_parameter_;
Json forced_splits_json_; Json forced_splits_json_;
}; };
} // namespace LightGBM } // namespace LightGBM
......
...@@ -280,6 +280,7 @@ std::string GBDT::SaveModelToString(int num_iteration) const { ...@@ -280,6 +280,7 @@ std::string GBDT::SaveModelToString(int num_iteration) const {
ss << tree_strs[i]; ss << tree_strs[i];
tree_strs[i].clear(); tree_strs[i].clear();
} }
ss << "end of trees" << "\n";
std::vector<double> feature_importances = FeatureImportance(num_iteration, 0); std::vector<double> feature_importances = FeatureImportance(num_iteration, 0);
// store the importance first // store the importance first
...@@ -301,8 +302,13 @@ std::string GBDT::SaveModelToString(int num_iteration) const { ...@@ -301,8 +302,13 @@ std::string GBDT::SaveModelToString(int num_iteration) const {
ss << pairs[i].second << "=" << std::to_string(pairs[i].first) << '\n'; ss << pairs[i].second << "=" << std::to_string(pairs[i].first) << '\n';
} }
if (config_ != nullptr) { if (config_ != nullptr) {
ss << "parameters:" << '\n'; ss << "\nparameters:" << '\n';
ss << config_->ToString() << "\n"; ss << config_->ToString() << "\n";
ss << "end of parameters" << '\n';
} else if (!loaded_parameter_.empty()) {
ss << "\nparameters:" << '\n';
ss << loaded_parameter_ << "\n";
ss << "end of parameters" << '\n';
} }
return ss.str(); return ss.str();
} }
...@@ -465,7 +471,26 @@ bool GBDT::LoadModelFromString(const char* buffer, size_t len) { ...@@ -465,7 +471,26 @@ bool GBDT::LoadModelFromString(const char* buffer, size_t len) {
num_iteration_for_pred_ = static_cast<int>(models_.size()) / num_tree_per_iteration_; num_iteration_for_pred_ = static_cast<int>(models_.size()) / num_tree_per_iteration_;
num_init_iteration_ = num_iteration_for_pred_; num_init_iteration_ = num_iteration_for_pred_;
iter_ = 0; iter_ = 0;
bool is_inparameter = false;
std::stringstream ss;
while (p < end) {
auto line_len = Common::GetLine(p);
std::string cur_line(p, line_len);
if (line_len > 0) {
if (cur_line == std::string("parameters:")) {
is_inparameter = true;
} else if (cur_line == std::string("end of parameters")) {
break;
} else if (is_inparameter) {
ss << cur_line << "\n";
}
}
p += line_len;
p = Common::SkipNewLine(p);
}
if (!ss.str().empty()) {
loaded_parameter_ = ss.str();
}
return true; return true;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment