You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit abafa83
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: Tools/ML/MlResponse.h
+19-6Lines changed: 19 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -190,8 +190,16 @@ class MlResponse
190
190
LOG(fatal) << "Number of input nodes in the model " << mPaths[nModel] << " is different from the number of input features to be tested (" << numInputNodes << " vs " << numInputFeatures << ")";
LOG(fatal) << "Model " << mPaths[nModel] << " returned " << output.size() << " scores, but " << static_cast<int>(mNClasses) << " classes are expected. Please check your configurables.";
197
+
}
198
+
if (output.size() > mNClasses) {
199
+
// keep only the first mNClasses scores (e.g. single-candidate probabilities of a multi-output model)
200
+
output.resize(mNClasses);
201
+
}
202
+
return output;
195
203
}
196
204
197
205
/// Get vector with model predictions for a batch of candidates
@@ -221,11 +229,16 @@ class MlResponse
221
229
LOG(fatal) << "Number of input nodes in the model " << mPaths[nModel] << " differs from features per row (" << numInputNodes << " vs " << featuresPerRow << ")";
// Product of all non-batch dimensions; dynamic dimensions (< 0) cannot be inferred
153
+
int64_t totalSize = 1;
154
+
bool hasDynamicDim = false;
155
+
for (std::size_t idim = 1; idim < modelShape.size(); idim++) {
156
+
if (modelShape[idim] < 0) {
157
+
hasDynamicDim = true;
158
+
} else {
159
+
totalSize *= modelShape[idim];
160
+
}
161
+
}
162
+
163
+
if (hasDynamicDim) {
164
+
if (modelShape.size() == 2) {
165
+
// [batch, features] with dynamic feature dimension: interpret the vector as a single sample
166
+
return {1, size};
167
+
}
168
+
LOG(fatal) << "Input " << iinput << " (" << mInputNames[iinput] << ") has dynamic non-batch dimensions (" << printShape(modelShape) << "), the tensor shape cannot be inferred from a flat vector. Please provide std::vector<Ort::Value> inputs instead.";
169
+
}
170
+
171
+
if (totalSize <= 0 || size % totalSize != 0) {
172
+
LOG(fatal) << "Size of the input vector (" << size << ") is not a multiple of the model input size (" << totalSize << ") for input " << iinput << " (" << mInputNames[iinput] << ", shape " << printShape(modelShape) << ")";
173
+
}
174
+
175
+
std::vector<int64_t> inputShape;
176
+
inputShape.reserve(modelShape.size());
177
+
inputShape.push_back(size / totalSize);
178
+
for (std::size_t idim = 1; idim < modelShape.size(); idim++) {
LOG(fatal) << "Shape of output tensor " << index << " does not agree with model specification! Output: " << printShape(shape) << " model: " << printShape(mOutputShapes[index]);
0 commit comments