| 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, ¶ms); |
| 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); |
no test coverage detected