Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Tools/ML/model.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 6 additions & 2 deletions Tools/ML/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,9 @@ class OnnxModel
std::vector<std::vector<T>> evalModelFull(std::vector<T>& 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<int64_t> inputShape{size / mInputShapes[0][1], mInputShapes[0][1]};
std::vector<Ort::Value> inputTensors;
Ort::MemoryInfo memInfo = Ort::MemoryInfo::CreateCpu(OrtAllocatorType::OrtArenaAllocator, OrtMemType::OrtMemTypeDefault);
Expand All @@ -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<int64_t> inputShape{static_cast<int64_t>(size / totalSize)};
for (std::size_t idim = 1; idim < mInputShapes[iinput].size(); idim++) {
Expand Down
17 changes: 12 additions & 5 deletions Tools/PIDML/pidOnnxModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -268,8 +272,9 @@ struct PidONNXModel {
inputTensors.emplace_back(Ort::Value::CreateTensor<float>(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 {
Expand All @@ -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<float>();
Expand Down
Loading