from torchvision.tv_tensors import BoundingBoxes
from torchvision.tv_tensors import Mask
...
self._pred_bboxes = BoundingBoxes(
model_output[0]["boxes"][scores_mask]
format="xyxy",
canvas_size=self._input_img.size[::-1],
)
self._pred_masks = torch.nn.functional.interpolate(
model_output[0]["masks"][scores_mask], size=self._color_image.size[::-1]
)
# mask is a two classificaiton problem
self._pred_masks = torch.concat(
[
Mask(torch.where(mask >= 0.5, 1, 0), dtype=torch.bool)
for mask in self._pred_masks
]
)
I want to transform it into C++ codes.
I’ve found function for interpolate
, it is as below
torch::Tensor _pred_masks = torch::nn::functional::interpolate(
image_tensor,
F::InterpolateFuncOptions()
.size(std::vector<int64_t>({_color_img.rows, _color_img.cols}))
);
But for torchvision, I havent found corresponding functions. I decided to store the _pred_bboxes
as torch::tensor
or std::vector
.
For torchvision::tv_tensors::Mask
, I don’t even know what it means. the documentation says
torch.Tensor
subclass for segmentation and detection masks
but it is very vague for what it does.
I have read this post Is torchvision also available in C++? - #6 by Shisho_Sama but didnt find useful information about my issue.