MCPcopy Create free account
hub / github.com/catboost/catboost / ExportModel

Function ExportModel

catboost/libs/model/model_export/model_exporter.cpp:136–216  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

134 }
135
136 void ExportModel(
137 const TFullModel& model,
138 const TString& modelFile,
139 const EModelType format,
140 const TString& userParametersJson,
141 bool addFileFormatExtension,
142 const TVector<TString>* featureId,
143 const THashMap<ui32, TString>* catFeaturesHashToString
144 ) {
145 //TODO(eermishkina): support non symmetric trees
146 CB_ENSURE(model.IsOblivious() || format == EModelType::CatboostBinary || format == EModelType::Json || format == EModelType::Pmml,
147 "Can save non symmetric trees only in cbm, Json, or Pmml format");
148 //TODO(d-kruchinin): support text features
149 CB_ENSURE(
150 !model.TextProcessingCollection || format == EModelType::CatboostBinary,
151 "Can save model with text features only in cbm format"
152 );
153 //TODO(akhropov): support embedding features
154 CB_ENSURE(
155 !model.EmbeddingProcessingCollection || format == EModelType::CatboostBinary,
156 "Can save model with embedding features only in cbm format"
157 );
158 const auto modelFileName = NCatboostOptions::AddExtension(format, modelFile, addFileFormatExtension);
159 switch (format) {
160 case EModelType::CatboostBinary:
161 CB_ENSURE(
162 userParametersJson.empty(),
163 "JSON user params for CatBoost model export are not supported"
164 );
165 OutputModel(model, modelFileName);
166 break;
167 case EModelType::AppleCoreML:
168 {
169 TStringInput is(userParametersJson);
170 NJson::TJsonValue params;
171 NJson::ReadJsonTree(&is, &params);
172 CB_ENSURE_SCALE_IDENTITY(model.GetScaleAndBias(), "exporting CoreML model");
173 OutputModelCoreML(model, modelFileName, params, catFeaturesHashToString);
174 }
175 break;
176 case EModelType::Json:
177 {
178 CB_ENSURE(
179 userParametersJson.empty(),
180 "JSON user params for JSON model export are not supported"
181 );
182
183 OutputModelJson(model, modelFileName, featureId, catFeaturesHashToString);
184 }
185 break;
186 case EModelType::Onnx:
187 {
188 OutputModelOnnx(model, modelFileName, userParametersJson);
189 }
190 break;
191 case EModelType::Pmml:
192 {
193 TStringInput is(userParametersJson);

Callers 8

mode_normalize_modelMethod · 0.85
set_keyFunction · 0.85
mode_model_sumFunction · 0.85
ExportFullModelFunction · 0.85
Y_UNIT_TESTFunction · 0.85
SaveLoadCoreMLFunction · 0.85
Y_UNIT_TESTFunction · 0.85
CatBoostOutputModel_RFunction · 0.85

Calls 11

OutputModelCoreMLFunction · 0.85
OutputModelJsonFunction · 0.85
OutputModelOnnxFunction · 0.85
OutputModelFunction · 0.70
AddExtensionFunction · 0.50
ReadJsonTreeFunction · 0.50
IsObliviousMethod · 0.45
emptyMethod · 0.45
c_strMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected