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
Copy file name to clipboardExpand all lines: Tools/ML/MlResponse.h
+10-2Lines changed: 10 additions & 2 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 << ")";
// Product of all non-batch dimensions; dynamic dimensions (< 0) cannot be inferred
145
+
int64_t totalSize = 1;
146
+
bool hasDynamicDim = false;
147
+
for (std::size_t idim = 1; idim < modelShape.size(); idim++) {
148
+
if (modelShape[idim] < 0) {
149
+
hasDynamicDim = true;
150
+
} else {
151
+
totalSize *= modelShape[idim];
152
+
}
153
+
}
154
+
155
+
if (hasDynamicDim) {
156
+
if (modelShape.size() == 2) {
157
+
// [batch, features] with dynamic feature dimension: interpret the vector as a single sample
158
+
return {1, size};
159
+
}
160
+
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.";
161
+
}
162
+
163
+
if (totalSize <= 0 || size % totalSize != 0) {
164
+
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) << ")";
165
+
}
166
+
167
+
std::vector<int64_t> inputShape;
168
+
inputShape.reserve(modelShape.size());
169
+
inputShape.push_back(size / totalSize);
170
+
for (std::size_t idim = 1; idim < modelShape.size(); idim++) {
LOG(fatal) << "Shape of output tensor " << i << " does not agree with model specification! Output: " << printShape(shape) << " model: " << printShape(mOutputShapes[i]);
0 commit comments