| 108 | */ |
| 109 | template <class Description> |
| 110 | inline Result validateFeatureDescriptions(const Description& interface, int modelVersion, const ValidationPolicy& validationPolicy) { |
| 111 | if (interface.input_size() < 1) { |
| 112 | if (!validationPolicy.allowsEmptyInput) { |
| 113 | return Result(ResultType::MODEL_TYPE_DOES_NOT_SUPPORT_EMPTY_INPUT, "Models must have one or more inputs."); |
| 114 | } |
| 115 | |
| 116 | if (modelVersion < MLMODEL_SPECIFICATION_VERSION_IOS18) { |
| 117 | return Result(ResultType::INVALID_COMPATIBILITY_VERSION, |
| 118 | "Empty input is only valid in specification verison >= " + std::to_string(MLMODEL_SPECIFICATION_VERSION_IOS18)+ |
| 119 | ". This model has version " + std::to_string(modelVersion)); |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | if (!validationPolicy.allowsEmptyOutput && interface.output_size() < 1) { |
| 124 | return Result(ResultType::INVALID_MODEL_INTERFACE, "Models must have one or more outputs."); |
| 125 | } |
| 126 | |
| 127 | for (const auto& input : interface.input()) { |
| 128 | Result r = validateFeatureDescription(input, modelVersion, FeatureIOType::INPUT); |
| 129 | if (!r.good()) { return r; } |
| 130 | } |
| 131 | |
| 132 | for (const auto& output : interface.output()) { |
| 133 | Result r = validateFeatureDescription(output, modelVersion, FeatureIOType::OUTPUT); |
| 134 | if (!r.good()) { return r; } |
| 135 | } |
| 136 | |
| 137 | for (const auto& state : interface.state()) { |
| 138 | Result r = validateFeatureDescription(state, modelVersion, FeatureIOType::STATE); |
| 139 | if (!r.good()) { return r; } |
| 140 | } |
| 141 | |
| 142 | // If we got here, all inputs/outputs seem good independently of each other. |
| 143 | return Result(); |
| 144 | } |
| 145 | |
| 146 | /* |
| 147 | * Validate model interface describes a valid classifier |
no test coverage detected