Skip to content

Commit ead3e43

Browse files
committed
Try to fix CI.
1 parent 27a175d commit ead3e43

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

attachments/ml_inference/onnx_inference.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include <iostream>
55
#include <cmath>
66

7+
#ifdef HAS_ONNX_RUNTIME
8+
79
ONNXClassifier::ONNXClassifier(const std::string& modelPath)
810
: env(ORT_LOGGING_LEVEL_WARNING, "ONNXClassifier") {
911

@@ -185,3 +187,27 @@ std::vector<std::pair<int, float>> ONNXClassifier::getTopK(
185187
indexed.resize(k);
186188
return indexed;
187189
}
190+
191+
#else // HAS_ONNX_RUNTIME
192+
193+
ONNXClassifier::ONNXClassifier(const std::string& modelPath) {
194+
std::cerr << "ONNX Runtime not available. Model not loaded: " << modelPath << "\n";
195+
}
196+
197+
ONNXClassifier::ClassificationResult ONNXClassifier::classify(const PreprocessedImage&, int topK) {
198+
return {{}, 0.0f};
199+
}
200+
201+
ONNXClassifier::GenericResult ONNXClassifier::runGeneric(const PreprocessedImage&) {
202+
return {{}, {}, 0.0f};
203+
}
204+
205+
std::vector<float> ONNXClassifier::softmax(const float*, size_t size) {
206+
return std::vector<float>(size, 0.0f);
207+
}
208+
209+
std::vector<std::pair<int, float>> ONNXClassifier::getTopK(const std::vector<float>& probabilities, int k) {
210+
return {};
211+
}
212+
213+
#endif // HAS_ONNX_RUNTIME

attachments/ml_inference/onnx_inference.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
#pragma once
22

3-
#include <onnxruntime_cxx_api.h>
43
#include <string>
54
#include <vector>
65
#include <memory>
76
#include <array>
87
#include "common/preprocessing/vulkan_preprocessing.h"
98

9+
#ifdef HAS_ONNX_RUNTIME
10+
#include <onnxruntime_cxx_api.h>
11+
#endif
12+
1013
class ONNXClassifier {
1114
public:
1215
struct ClassificationResult {
@@ -30,6 +33,7 @@ class ONNXClassifier {
3033
std::vector<float> softmax(const float* logits, size_t size);
3134
std::vector<std::pair<int, float>> getTopK(const std::vector<float>& probabilities, int k);
3235

36+
#ifdef HAS_ONNX_RUNTIME
3337
Ort::Env env;
3438
Ort::SessionOptions sessionOptions;
3539
std::unique_ptr<Ort::Session> session;
@@ -38,4 +42,5 @@ class ONNXClassifier {
3842
std::vector<const char*> outputNames;
3943

4044
size_t numClasses = 0;
45+
#endif
4146
};

0 commit comments

Comments
 (0)