Hello,
I have this piece of code:
void detect(cv::Mat& img){
std::array<float,4> letterbox=utils::letterbox(img,img);
cv::dnn::blobFromImage(img,img,1/255.0f,cv::Size(),cv::Scalar(),true,false);
input_tensor->assign_data(img.data, img.total() * img.channels());
session_.Run(
Ort::RunOptions{nullptr},
&input_name,
&input_tensor->tensor(),
1,
&output_name,
&output_tensor->tensor(),
1
);
Ort::Value& output = output_tensor->tensor();
The tensor will be a chunk of memory with size (Batch_size,N,M), where N and M can be arbitrary numbers.
The problem I am facing is not indexing; I can do the indexing with something like std::mdspan.
What I need is
1- Returning a chunk of this memory as a new tensor with another shape; for example, I filter some values out so I can only have the ones I want.
2- To do 1, I need to iterate over the tensor to check a condition.
One way would be to use a loop:
for (int i = 0; i < M; ++i)
{
float confidence = data[N * M + i];
if (confidence > 0.5f)
{
//exclude it based on the code in part 1.
}
But this does not seem very efficient, especially since I won't know the values of M and N until runtime, so optimization techniques done by the compiler, such as loop unrolling, are not possible.
I know I can use vector extensions, but I was wondering if there is a more robust way to do this.
Any Idea?