serizba / cppflow

Run TensorFlow models in C++ without installation and without Bazel
https://serizba.github.io/cppflow/
MIT License
785 stars 178 forks source link

How to index cppflow::tensor data. #218

Open edargham opened 2 years ago

edargham commented 2 years ago

I'm trying to implement the non-max suppression algorithm on the raw output generated by the YOLOv5 model I trained and loaded into my C++ cppflow model instance.

To extract the candidate bounding boxes in python we must perform this operation

    .
    .
    .
    candidates = predictions[..., 4]
    .
    .
    .

I did not find any way I can access the internal data of the cppflow::tensors. The only way is to extract it into an std::vector<T> using tensor.get_data<T>(). Then rearranging the dumped output into the desired shape.

I have no qualms doing this, however I do worry about the performance cost of this approach.

It would be wonderful if we could directly query the tensor object to and access the desired indeces using the [] operator. Is there no alternative approach to the one I mentioned that is less costly?

yochananscharf commented 1 year ago

Have you tried using the cppflow::slice operator?