Skip to content

Commit ad14081

Browse files
authored
Add possibility to load ML models converted to tensor format with unknown input shape (#489)
1 parent 4370931 commit ad14081

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

EventFiltering/PWGHF/HFFilter.cxx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,10 @@ struct HfFilter { // Main struct for HF triggers
344344

345345
inputNamesML2P = session2Prong->GetInputNames();
346346
inputShapesML2P = session2Prong->GetInputShapes();
347+
if (inputShapesML2P[0][0] < 0) {
348+
LOG(warning) << "Model with negative input shape likely because converted with ummingbird, setting it to 1.";
349+
inputShapesML2P[0][0] = 1;
350+
}
347351
outputNamesML2P = session2Prong->GetOutputNames();
348352
outputShapesML2P = session2Prong->GetOutputShapes();
349353
}
@@ -623,7 +627,9 @@ struct HfFilter { // Main struct for HF triggers
623627
inputTensor2P.push_back(Ort::Experimental::Value::CreateTensor<float>(inputFeatures2P.data(), inputFeatures2P.size(), inputShapesML2P[0]));
624628

625629
// double-check the dimensions of the input tensor
626-
assert(inputTensor2P[0].IsTensor() && inputTensor2P[0].GetTensorTypeAndShapeInfo().GetShape() == inputShapesML2P[0]);
630+
if (inputTensor2P[0].GetTensorTypeAndShapeInfo().GetShape()[0] > 0) { // vectorial models can have negative shape if the shape is unknown
631+
assert(inputTensor2P[0].IsTensor() && inputTensor2P[0].GetTensorTypeAndShapeInfo().GetShape() == inputShapesML2P[0]);
632+
}
627633
try {
628634
auto outputTensor2P = session2Prong->Run(inputNamesML2P, inputTensor2P, outputNamesML2P);
629635
assert(outputTensor2P.size() == outputNamesML2P.size() && outputTensor2P[1].IsTensor());

0 commit comments

Comments
 (0)