MCPcopy Create free account
hub / github.com/apple/coremltools / validateClassifierInterface

Function validateClassifierInterface

mlmodel/src/Validation/Validators.hpp:153–209  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

151 */
152 template<typename T, typename U>
153 Result validateClassifierInterface(const T& model,
154 const U& modelParameters,
155 const bool allowEmptyLabels = false,
156 const bool defaultClassLabelIsInt64 = false,
157 const ValidationPolicy& validationPolicy = ValidationPolicy()) {
158
159 bool expected_class_is_int64;
160
161 // validate class labels
162 switch (modelParameters.ClassLabels_case()) {
163 case U::kInt64ClassLabels:
164 if (!allowEmptyLabels && modelParameters.int64classlabels().vector_size() == 0) {
165 return Result(ResultType::INVALID_MODEL_PARAMETERS,
166 "Classifier declared to have Int64 class labels must provide labels.");
167 }
168
169 if(modelParameters.stringclasslabels().vector_size() != 0) {
170 return Result(ResultType::INVALID_MODEL_PARAMETERS,
171 "Classifier declared with Int64 class labels must provide exclusively Int64 class labels.");
172 }
173
174 expected_class_is_int64 = true;
175
176 break;
177
178 case U::kStringClassLabels:
179 if (!allowEmptyLabels && modelParameters.stringclasslabels().vector_size() == 0) {
180 return Result(ResultType::INVALID_MODEL_PARAMETERS,
181 "Classifier declared to have String class labels must provide labels.");
182 }
183
184 if(modelParameters.int64classlabels().vector_size() != 0) {
185 return Result(ResultType::INVALID_MODEL_PARAMETERS,
186 "Classifier declared with String class labels must provide exclusively String class labels.");
187 }
188
189 expected_class_is_int64 = false;
190
191 break;
192
193 case U::CLASSLABELS_NOT_SET:
194 if (!allowEmptyLabels) {
195 return Result(ResultType::INVALID_MODEL_PARAMETERS, "Classifier models must provide class labels.");
196 }
197 expected_class_is_int64 = defaultClassLabelIsInt64;
198 break;
199 }
200 const Specification::ModelDescription& interface = model.description();
201
202 // Validate feature descriptions
203 Result result = validateFeatureDescriptions(interface, model.specificationversion(), validationPolicy);
204 if (!result.good()) {
205 return result;
206 }
207
208 return validateClassifierFeatureDescriptions(interface, expected_class_is_int64);
209 }
210

Calls 6

ValidationPolicyClass · 0.85
ResultClass · 0.85
descriptionMethod · 0.80
goodMethod · 0.80

Tested by

no test coverage detected