Skip to content
Closed
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: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,8 @@ set(
data/models/mediapipe.with_runtime_opt.ort.license
data/models/pphumanseg_fp32.with_runtime_opt.ort
data/models/pphumanseg_fp32.with_runtime_opt.ort.license
data/models/rvm_mobilenetv3_fp32.with_runtime_opt.ort
data/models/rvm_mobilenetv3_fp32.with_runtime_opt.ort.license
data/models/rvm_mobilenetv3_fp32.onnx
data/models/rvm_mobilenetv3_fp32.onnx.license
data/models/selfie_multiclass_256x256.with_runtime_opt.ort
data/models/selfie_multiclass_256x256.with_runtime_opt.ort.license
data/models/selfie_segmentation.with_runtime_opt.ort
Expand Down
Binary file not shown.
4 changes: 3 additions & 1 deletion src/consts.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ const char *const MODEL_SINET = "models/SINet_Softmax_simple.with_runtime_opt.or
const char *const MODEL_MEDIAPIPE = "models/mediapipe.with_runtime_opt.ort";
const char *const MODEL_SELFIE = "models/selfie_segmentation.with_runtime_opt.ort";
const char *const MODEL_SELFIE_MULTICLASS = "models/selfie_multiclass_256x256.with_runtime_opt.ort";
const char *const MODEL_RVM = "models/rvm_mobilenetv3_fp32.with_runtime_opt.ort";
// Use the original ONNX model for RVM: the pre-optimized .ort variant is
// CPU-EP-targeted and crashes GPU execution providers (e.g. CUDA).
const char *const MODEL_RVM = "models/rvm_mobilenetv3_fp32.onnx";
const char *const MODEL_PPHUMANSEG = "models/pphumanseg_fp32.with_runtime_opt.ort";
const char *const MODEL_ENHANCE_TBEFN = "models/tbefn_fp32.with_runtime_opt.ort";
const char *const MODEL_ENHANCE_URETINEX = "models/uretinex_net_180x320.with_runtime_opt.ort";
Expand Down
22 changes: 20 additions & 2 deletions src/models/Model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#include <opencv2/imgproc.hpp>
#include <algorithm>
#include <cstring>

template<typename T> T vectorProduct(const std::vector<T> &v)
{
Expand Down Expand Up @@ -282,8 +283,25 @@ class Model {
rawOutputNames.push_back(outputName.get());
}

session->Run(Ort::RunOptions{nullptr}, rawInputNames.data(), inputTensor.data(), inputNames.size(),
rawOutputNames.data(), outputTensor.data(), outputNames.size());
// Let ORT allocate the output tensors itself, then copy the results
// back into the pre-allocated CPU buffers. Pre-binding CPU output
// tensors can misbehave on GPU execution providers for stateful
// multi-output models (e.g. RVM).
std::vector<Ort::Value> results = session->Run(Ort::RunOptions{nullptr}, rawInputNames.data(),
inputTensor.data(), inputNames.size(),
rawOutputNames.data(), outputNames.size());

for (size_t i = 0; i < results.size() && i < outputTensor.size(); i++) {
const float *src = results[i].GetTensorData<float>();
float *dst = outputTensor[i].GetTensorMutableData<float>();
const size_t srcCount = results[i].GetTensorTypeAndShapeInfo().GetElementCount();
const size_t dstCount = outputTensor[i].GetTensorTypeAndShapeInfo().GetElementCount();
if (srcCount != dstCount) {
obs_log(LOG_WARNING, "Output %d size mismatch: model produced %d elements, expected %d",
(int)i, (int)srcCount, (int)dstCount);
}
memcpy(dst, src, (srcCount < dstCount ? srcCount : dstCount) * sizeof(float));
}
}
};

Expand Down