22#include <opencv2/core/core.hpp>
23#include <tensorflow/lite/c/common.h>
24#include <ovxlib/vsi_nn_pub.h>
27#include <hailo/hailort.h>
28#include <onnxruntime_cxx_api.h>
46 std::map<int, std::string>
readLabelsFile(std::string
const & fname);
51 std::string
getLabel(std::map<int, std::string>
const & labels,
int id,
bool namedonly =
false);
54 int stringToRGBA(std::string
const & label,
unsigned char alpha = 128);
57 void topK(
float const * pfProb,
float * pfMaxProb, uint32_t * pMaxClass, uint32_t outputCount, uint32_t topNum);
60 std::string
shapestr(cv::Mat
const & m);
63 std::string
shapestr(std::vector<size_t> dims,
int typ);
66 std::string
shapestr(std::vector<int> dims,
int typ);
69 std::string
shapestr(TfLiteTensor
const * t);
72 std::string
shapestr(vsi_nn_tensor_attr_t
const & attr);
75 std::vector<size_t>
strshape(std::string
const & str);
78 int tf2cv(TfLiteType t);
81 vsi_nn_type_e
tf2vsi(TfLiteType t);
84 int vsi2cv(vsi_nn_type_e t);
87 void clamp(cv::Rect & r,
int width,
int height);
90 void clamp(cv::Rect2f & r,
float width,
float height);
94 std::vector<vsi_nn_tensor_attr_t>
parseTensorSpecs(std::string
const & specs);
101 cv::Mat
attrmat(vsi_nn_tensor_attr_t
const & attr,
void * dataptr =
nullptr);
104 std::vector<int>
attrdims(vsi_nn_tensor_attr_t
const & attr);
107 cv::Size
attrsize(vsi_nn_tensor_attr_t
const & attr);
110 std::string
attrstr(vsi_nn_tensor_attr_t
const & attr);
113 bool attrmatch(vsi_nn_tensor_attr_t
const & attr, cv::Mat
const & blob);
116 vsi_nn_tensor_attr_t
tensorattr(TfLiteTensor
const * t);
132 size_t softmax(
float const * input,
size_t const n,
size_t const stride,
float const fac,
float * output,
137 float softmax_dfl(
float const * src,
float * dst,
size_t const n,
size_t const stride = 1);
142 cv::Mat
quantize(cv::Mat
const & m, vsi_nn_tensor_attr_t
const & attr);
146 cv::Mat
dequantize(cv::Mat
const & m, vsi_nn_tensor_attr_t
const & attr);
158 cv::Mat
concatenate(std::vector<cv::Mat>
const & tensors,
int axis);
162 std::vector<cv::Mat>
split(cv::Mat
const & tensor,
int axis, std::vector<int>
const & sizes);
166 std::string
shapestr(hailo_vstream_info_t
const & vi);
169 vsi_nn_tensor_attr_t
tensorattr(hailo_vstream_info_t
const & vi);
172 vsi_nn_type_e
hailo2vsi(hailo_format_type_t t);
175 vsi_nn_type_e
onnx2vsi(ONNXTensorElementDataType t);
178 std::string
shapestr(Ort::ConstTensorTypeAndShapeInfo
const & ti);
181 vsi_nn_tensor_attr_t
tensorattr(Ort::ConstTensorTypeAndShapeInfo
const & ti);
198#include <jevois/DNN/details/UtilsImpl.H>
float fastexp(float x)
Compute fast exponential using approximation formula.
int tf2cv(TfLiteType t)
Convert from TensorFlow data type to OpenCV.
int vsi2cv(vsi_nn_type_e t)
Convert from NPU data type to OpenCV.
size_t softmax(float const *input, size_t const n, size_t const stride, float const fac, float *output, bool maxonly)
Apply softmax to a float vector.
vsi_nn_tensor_attr_t tensorattr(TfLiteTensor const *t)
Get tensor shape and type attributes for a TensorFlow Lite tensor.
std::string getLabel(std::map< int, std::string > const &labels, int id, bool namedonly=false)
Get a label from an id.
cv::Mat quantize(cv::Mat const &m, vsi_nn_tensor_attr_t const &attr)
Quantize from float32 to fixed-point according to the quantization spec in attr.
std::map< int, std::string > readLabelsFile(std::string const &fname)
Read a label file.
float sigmoid(float x)
Compute sigmoid using fastexp.
vsi_nn_type_e onnx2vsi(ONNXTensorElementDataType t)
Convert from ONNX-Runtime data type to vsi_nn.
std::vector< cv::Mat > split(cv::Mat const &tensor, int axis, std::vector< int > const &sizes)
Split a tensor into several, along a given axis.
std::vector< vsi_nn_tensor_attr_t > parseTensorSpecs(std::string const &specs)
Parse tensor specification.
void clamp(cv::Rect &r, int width, int height)
Clamp a rectangle to within given image width and height.
std::string attrstr(vsi_nn_tensor_attr_t const &attr)
Get a string describing the specs of a tensor, including quantification specs (not provided by shapes...
float softmax_dfl(float const *src, float *dst, size_t const n, size_t const stride=1)
Compute softmax and return DFL distance.
cv::Mat attrmat(vsi_nn_tensor_attr_t const &attr, void *dataptr=nullptr)
Construct a cv::Mat from attr and possibly data pointer.
size_t effectiveDims(cv::Mat const &m)
Returns the number of non-unit dims in a cv::Mat.
vsi_nn_type_e hailo2vsi(hailo_format_type_t t)
Convert from Hailo data type to vsi_nn.
cv::Mat concatenate(std::vector< cv::Mat > const &tensors, int axis)
Concatenate several tensors into one.
int stringToRGBA(std::string const &label, unsigned char alpha=128)
Compute a color from a label name.
cv::Size attrsize(vsi_nn_tensor_attr_t const &attr)
Get a tensor's (width, height) size in cv::Size format, skipping over other dimensions.
cv::Mat dequantize(cv::Mat const &m, vsi_nn_tensor_attr_t const &attr)
Dequantize an output to float32 according to the quantization spec in attr.
vsi_nn_type_e tf2vsi(TfLiteType t)
Convert from TensorFlow data type to vsi_nn.
void topK(float const *pfProb, float *pfMaxProb, uint32_t *pMaxClass, uint32_t outputCount, uint32_t topNum)
Get top-k entries and their indices.
std::string shapestr(cv::Mat const &m)
Get a string of the form: "nD AxBxC... TYPE" from an n-dimensional cv::Mat with data type TYPE.
std::vector< int > attrdims(vsi_nn_tensor_attr_t const &attr)
Get a tensor dims as a vector of int, useful to construct a matching cv::Mat.
std::vector< size_t > strshape(std::string const &str)
Get a vector of size_t from a string containing AxBxC...
bool attrmatch(vsi_nn_tensor_attr_t const &attr, cv::Mat const &blob)
Check that a cv::Mat blob matches exactly the spec of an attr.
Main namespace for all JeVois classes and functions.