EyeAI
Loading...
Searching...
No Matches
MetricDepthModel.hpp
Go to the documentation of this file.
1#pragma once
2
5#include <memory>
6
7class DepthModel;
8
10 public:
11 constexpr static size_t POLYNOMIAL_DEGREE = 4;
12 constexpr static size_t COEFFS_COUNT = POLYNOMIAL_DEGREE + 1;
13
14 using CreateResult = tl::
15 expected<std::unique_ptr<MetricDepthModel>, TfLiteCreateRuntimeError>;
16
17 [[nodiscard]] static CreateResult create(
18 std::vector<int8_t>&& depth_model_data,
19 std::string_view gpu_delegate_serialization_dir,
20 std::string_view depth_model_token,
21 TfLiteLogWarningCallback log_warning_callback,
22 TfLiteLogErrorCallback log_error_callback,
23 bool enable_npu,
24 std::string npu_skel_directory
25 );
26
27 using RunResult = tl::expected<
29 TfLiteRunInferenceError>;
30
32 [[nodiscard]] RunResult
34
35 [[nodiscard]] std::span<const int> get_input_shape() const;
36
37 [[nodiscard]] std::span<const int> get_output_shape() const;
38
39 MetricDepthModel(std::unique_ptr<DepthModel>&& depth_model);
40
41 private:
42 constexpr static std::array<float, 5> REL2ABS_COEFFS = {
43 4.30595f, -6.5995E-03f, 5.25059E-6f, -2.7962E-9f, 9.28594E-13f
44 };
45
46 std::unique_ptr<DepthModel> depth_model;
47};
48
52);
53
61constexpr static float
62polynomial_4(float x, const std::array<float, 5>& coeffs) {
63 float y = coeffs[4];
64 y = y * x + coeffs[3];
65 y = y * x + coeffs[2];
66 y = y * x + coeffs[1];
67 y = y * x + coeffs[0];
68 return y;
69}
70
75template<size_t I, size_t N>
76constexpr static float
77polynomial_n_impl(float x, float y, const std::array<float, N + 1>& coeffs) {
78 static_assert(I <= N);
79
80 const float new_y = (I != N) ? (coeffs[I] + (y * x)) : coeffs[I];
81
82 if constexpr (I == 0) {
83 return new_y;
84 } else {
85 return polynomial_n_impl<I - 1, N>(x, new_y, coeffs);
86 }
87}
88
100template<size_t N>
101constexpr static float
102polynomial_n(float x, const std::array<float, N + 1>& coeffs) {
103 return polynomial_n_impl<N, N>(x, 0.f, coeffs);
104}
FloatTensorBuffer< FloatTensorFormat::Rel2AbsDepthInput > rel2abs_input_operator(const FloatTensorBuffer< FloatTensorFormat::ImageRGB255 > &rgb, const FloatTensorBuffer< FloatTensorFormat::RawRelativeDepth > &depth)
Definition MetricDepthModel.cpp:61
TensorBuffer< float, FloatTensorFormat, FORMAT > FloatTensorBuffer
Definition TensorBuffer.hpp:106
void(*)(std::string) TfLiteLogWarningCallback
Definition TfLiteRuntime.hpp:17
void(*)(std::string) TfLiteLogErrorCallback
Definition TfLiteRuntime.hpp:18
A utility class for running depth estimation models like MiDaS.
Definition DepthModel.hpp:7
static constexpr size_t POLYNOMIAL_DEGREE
Definition MetricDepthModel.hpp:11
std::span< const int > get_input_shape() const
Definition MetricDepthModel.cpp:47
static CreateResult create(std::vector< int8_t > &&depth_model_data, std::string_view gpu_delegate_serialization_dir, std::string_view depth_model_token, TfLiteLogWarningCallback log_warning_callback, TfLiteLogErrorCallback log_error_callback, bool enable_npu, std::string npu_skel_directory)
Definition MetricDepthModel.cpp:9
tl:: expected< std::unique_ptr< MetricDepthModel >, TfLiteCreateRuntimeError > CreateResult
Definition MetricDepthModel.hpp:14
static constexpr size_t COEFFS_COUNT
Definition MetricDepthModel.hpp:12
RunResult run(FloatTensorBuffer< FloatTensorFormat::ImageRGB255 > &input)
Definition MetricDepthModel.cpp:34
tl::expected< FloatTensorBuffer< FloatTensorFormat::MetricDepth >, TfLiteRunInferenceError > RunResult
Definition MetricDepthModel.hpp:27
MetricDepthModel(std::unique_ptr< DepthModel > &&depth_model)
Definition MetricDepthModel.cpp:6
std::span< const int > get_output_shape() const
Definition MetricDepthModel.cpp:51