diff --git a/Tools/ML/model.cxx b/Tools/ML/model.cxx index ebf3919a891..01649b53d6a 100644 --- a/Tools/ML/model.cxx +++ b/Tools/ML/model.cxx @@ -75,7 +75,9 @@ bool OnnxModel::checkHyperloop(const bool verbose) void OnnxModel::initModel(const std::string& localPath, const bool enableOptimizations, const int threads, const uint64_t from, const uint64_t until) { - assert(from <= until); + if (from > until) { + LOGF(fatal, "from > until"); + } LOG(info) << "--- ONNX-ML model ---"; modelPath = localPath; diff --git a/Tools/ML/model.h b/Tools/ML/model.h index 81222677620..6d58d33df73 100644 --- a/Tools/ML/model.h +++ b/Tools/ML/model.h @@ -186,7 +186,9 @@ class OnnxModel std::vector> evalModelFull(std::vector& input) { const int64_t size = input.size(); - assert(size % mInputShapes[0][1] == 0); + if (size % mInputShapes[0][1] != 0) { + LOGF(fatal, "Wrong input size"); + } std::vector inputShape{size / mInputShapes[0][1], mInputShapes[0][1]}; std::vector inputTensors; Ort::MemoryInfo memInfo = Ort::MemoryInfo::CreateCpu(OrtAllocatorType::OrtArenaAllocator, OrtMemType::OrtMemTypeDefault); @@ -207,7 +209,9 @@ class OnnxModel for (std::size_t idim = 1; idim < mInputShapes[iinput].size(); idim++) { totalSize *= mInputShapes[iinput][idim]; } - assert(size % totalSize == 0); + if (size % totalSize != 0) { + LOGF(fatal, "Wrong input size"); + } std::vector inputShape{static_cast(size / totalSize)}; for (std::size_t idim = 1; idim < mInputShapes[iinput].size(); idim++) { diff --git a/Tools/PIDML/pidOnnxModel.h b/Tools/PIDML/pidOnnxModel.h index 4ee88106ab0..c9fb82c1668 100644 --- a/Tools/PIDML/pidOnnxModel.h +++ b/Tools/PIDML/pidOnnxModel.h @@ -86,7 +86,9 @@ struct PidONNXModel { int pid, double minCertainty, const double* pLimits = &pidml_pt_cuts::defaultModelPLimits[0]) : mPid(pid), mMinCertainty(minCertainty), mPLimits(pLimits, pLimits + kNDetectors) { - assert(mPLimits.size() == kNDetectors); + if (mPLimits.size() != kNDetectors) { + LOGF(fatal, "mPLimits.size() != kNDetectors"); + } std::string modelFile; loadInputFiles(localPath, ccdbPath, useCCDB, ccdbApi, timestamp, pid, modelFile); @@ -122,7 +124,9 @@ struct PidONNXModel { } // Assume model has 1 input node and 1 output node. - assert(mInputNames.size() == 1 && mOutputNames.size() == 1); + if (mInputNames.size() != 1 || mOutputNames.size() != 1) { + LOGF(fatal, "mInputNames.size() != 1 || mOutputNames.size() != 1"); + } } PidONNXModel() = default; PidONNXModel(PidONNXModel&&) = default; @@ -268,8 +272,9 @@ struct PidONNXModel { inputTensors.emplace_back(Ort::Value::CreateTensor(memInfo, inputTensorValues.data(), inputTensorValues.size(), inputShape.data(), inputShape.size())); // Double-check the dimensions of the input tensor - assert(inputTensors[0].IsTensor() && - inputTensors[0].GetTensorTypeAndShapeInfo().GetShape() == inputShape); + if (!inputTensors[0].IsTensor() || inputTensors[0].GetTensorTypeAndShapeInfo().GetShape() != inputShape) { + LOGF(fatal, "Wrong dimensions of the input tensors"); + } LOG(debug) << "input tensor shape: " << printShape(inputTensors[0].GetTensorTypeAndShapeInfo().GetShape()); try { @@ -285,7 +290,9 @@ struct PidONNXModel { // Double-check the dimensions of the output tensors // The number of output tensors is equal to the number of output nodes specified in the Run() call - assert(outputTensors.size() == mOutputNames.size() && outputTensors[0].IsTensor()); + if (outputTensors.size() != mOutputNames.size() || !outputTensors[0].IsTensor()) { + LOGF(fatal, "Wrong dimensions of the output tensors"); + } LOG(debug) << "output tensor shape: " << printShape(outputTensors[0].GetTensorTypeAndShapeInfo().GetShape()); const float* outputValue = outputTensors[0].GetTensorData();