NVIDIA DeepStream SDK API Reference

9.2 Release
sources/gst-plugins/gst-nvdsvideotemplate/ds-sparse4d/postprocess/sparse_box_3d_generator.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef SPARSE_BOX_3D_GENERATOR_H
19 #define SPARSE_BOX_3D_GENERATOR_H
20 
21 #include <torch/torch.h>
22 #include <vector>
23 #include <tuple>
24 #include <variant>
25 #include <iostream>
26 #include "instance_bank.h"
27 
34 class SparseBox3DKeyPointsGenerator : public AnchorHandler, public torch::nn::Module {
35 public:
44  int embed_dims = 256,
45  int num_learnable_pts = 0,
46  const std::vector<std::tuple<float, float, float>>& fix_scale = {{0.0, 0.0, 0.0}}
47  );
48 
52  void init_weight();
53 
64  std::variant<torch::Tensor, std::tuple<torch::Tensor, std::vector<torch::Tensor>>>
65  forward(
66  const torch::Tensor& anchor,
67  const torch::Tensor& instance_feature = torch::Tensor(),
68  const std::vector<torch::Tensor>& T_cur2temp_list = {},
69  const torch::Tensor& cur_timestamp = torch::Tensor(),
70  const std::vector<torch::Tensor>& temp_timestamps = {}
71  );
72 
81  std::vector<torch::Tensor> anchor_projection(
82  const torch::Tensor& anchors,
83  const std::vector<torch::Tensor>& transforms,
84  const std::vector<torch::Tensor>& time_intervals) override;
85 
96  static std::vector<torch::Tensor> anchor_projection_static(
97  const torch::Tensor& anchor,
98  const std::vector<torch::Tensor>& T_src2dst_list,
99  const torch::Tensor& src_timestamp = torch::Tensor(),
100  const std::vector<torch::Tensor>& dst_timestamps = {},
101  const std::vector<torch::Tensor>& time_intervals = {}
102  );
103 
110  static torch::Tensor distance(const torch::Tensor& anchor);
111 
112 private:
113  int embed_dims;
114  int num_learnable_pts;
115  int num_pts;
116  torch::Tensor fix_scale;
117  torch::nn::Linear learnable_fc{nullptr};
118 };
119 
120 #endif // SPARSE_BOX_3D_GENERATOR_H
SparseBox3DKeyPointsGenerator::anchor_projection
std::vector< torch::Tensor > anchor_projection(const torch::Tensor &anchors, const std::vector< torch::Tensor > &transforms, const std::vector< torch::Tensor > &time_intervals) override
Project anchors using transformation matrices and time intervals.
SparseBox3DKeyPointsGenerator::init_weight
void init_weight()
Initialize weights with proper initialization schemes.
SparseBox3DKeyPointsGenerator::SparseBox3DKeyPointsGenerator
SparseBox3DKeyPointsGenerator(int embed_dims=256, int num_learnable_pts=0, const std::vector< std::tuple< float, float, float >> &fix_scale={{0.0, 0.0, 0.0}})
Constructor for SparseBox3DKeyPointsGenerator.
SparseBox3DKeyPointsGenerator::distance
static torch::Tensor distance(const torch::Tensor &anchor)
Calculate Euclidean distance of anchors from origin in 2D.
instance_bank.h
SparseBox3DKeyPointsGenerator::forward
std::variant< torch::Tensor, std::tuple< torch::Tensor, std::vector< torch::Tensor > > > forward(const torch::Tensor &anchor, const torch::Tensor &instance_feature=torch::Tensor(), const std::vector< torch::Tensor > &T_cur2temp_list={}, const torch::Tensor &cur_timestamp=torch::Tensor(), const std::vector< torch::Tensor > &temp_timestamps={})
Forward pass to generate key points from anchors.
SparseBox3DKeyPointsGenerator::anchor_projection_static
static std::vector< torch::Tensor > anchor_projection_static(const torch::Tensor &anchor, const std::vector< torch::Tensor > &T_src2dst_list, const torch::Tensor &src_timestamp=torch::Tensor(), const std::vector< torch::Tensor > &dst_timestamps={}, const std::vector< torch::Tensor > &time_intervals={})
Static method to project anchors using various parameters.
AnchorHandler
Interface class for anchor projection operations.
Definition: sources/gst-plugins/gst-nvdsvideotemplate/ds-sparse4d/postprocess/instance_bank.h:32
SparseBox3DKeyPointsGenerator
Class for generating 3D bounding box key points based on anchors.
Definition: sources/gst-plugins/gst-nvdsvideotemplate/ds-sparse4d/postprocess/sparse_box_3d_generator.h:34