pcod-common v1.0.0
Shared preprocessing and postprocessing for point-cloud object detection
Loading...
Searching...
No Matches
test_pbod_postprocess.cpp File Reference
#include "pcod_common/pbod_postprocess.hpp"
#include <cassert>
#include <cmath>
#include <vector>
#include "pcod_common/pillar_grid.hpp"

Go to the source code of this file.

Functions

int main ()
 

Function Documentation

◆ main()

int main ( )

Run PBOD decoder regression checks.

Definition at line 13 of file test_pbod_postprocess.cpp.

13 {
14 {
15 pcod_common::PillarGrid grid = pcod_common::BuildPillarGrid({1, 1}, {{{0.0F, 1.0F}, {0.0F, 1.0F}, {0.0F, 1.0F}}}, 1, 1);
16
17 const int num_pillars = 1;
18 const int num_classes = 2;
19 float focal_logits[num_pillars] = {0.0F};
20 std::vector<float> size_posterior(static_cast<std::size_t>(num_pillars * num_classes * 3), 1.0F);
21 float class_logits[num_pillars * num_classes] = {0.1F, 0.9F};
22 std::vector<float> reg_logits(static_cast<std::size_t>(num_pillars * num_classes * 7), 0.0F);
23
25 view.focal_logits = focal_logits;
26 view.size_posterior = size_posterior.data();
27 view.class_logits = class_logits;
28 view.reg_logits = reg_logits.data();
29 view.num_pillars = num_pillars;
30 view.num_classes = num_classes;
31 view.reg_dim = 7;
32
34 config.class_names = {"car", "pedestrian"};
35
36 auto boxes = pcod_common::DecodePbod(view, grid, config);
37 assert(boxes.size() == 1);
38 const auto& box = boxes[0];
39 assert(box.classification.size() == 2);
40 assert(!box.has_velocity);
41 assert(std::abs(box.length - 1.0F) < 1e-6F);
42 assert(std::abs(box.width - 1.0F) < 1e-6F);
43 assert(std::abs(box.height - 1.0F) < 1e-6F);
44 assert(std::abs(box.center[0] - 0.5F) < 1e-6F);
45 assert(std::abs(box.center[1] - 0.5F) < 1e-6F);
46 }
47
48 {
49 pcod_common::PillarGrid grid = pcod_common::BuildPillarGrid({2, 1}, {{{0.0F, 2.0F}, {0.0F, 1.0F}, {0.0F, 2.0F}}}, 1, 1);
50
51 const int num_pillars = 2;
52 const int num_classes = 2;
53 float focal_logits[num_pillars] = {0.0F, 2.0F};
54 std::vector<float> size_posterior = {1.0F, 2.0F, 3.0F, 4.0F, 5.0F, 6.0F, 7.0F, 8.0F, 9.0F, 10.0F, 11.0F, 12.0F};
55 std::vector<float> class_logits = {0.7F, 0.2F, 0.1F, 1.2F};
56 std::vector<float> reg_logits(static_cast<std::size_t>(num_pillars * num_classes * 7), 0.0F);
57 reg_logits[0] = 0.25F;
58 reg_logits[1] = -0.5F;
59 reg_logits[2] = 0.75F;
60 reg_logits[3] = std::log(2.0F);
61 reg_logits[4] = std::log(0.5F);
62 reg_logits[5] = std::log(1.5F);
63 reg_logits[6] = 3.5F;
64
65 const std::size_t second_pillar_class_one = static_cast<std::size_t>((1 * num_classes + 1) * 7);
66 reg_logits[second_pillar_class_one + 0] = -0.2F;
67 reg_logits[second_pillar_class_one + 1] = 0.3F;
68 reg_logits[second_pillar_class_one + 2] = -0.4F;
69 reg_logits[second_pillar_class_one + 3] = std::log(0.5F);
70 reg_logits[second_pillar_class_one + 4] = std::log(2.0F);
71 reg_logits[second_pillar_class_one + 5] = std::log(1.0F);
72 reg_logits[second_pillar_class_one + 6] = -3.5F;
73
75 view.focal_logits = focal_logits;
76 view.size_posterior = size_posterior.data();
77 view.class_logits = class_logits.data();
78 view.reg_logits = reg_logits.data();
79 view.num_pillars = num_pillars;
80 view.num_classes = num_classes;
81 view.reg_dim = 7;
82
84 config.class_names = {"car", "pedestrian"};
85 config.score_thresholds = {0.4F, 0.8F};
86
87 auto boxes = pcod_common::DecodePbod(view, grid, config);
88 assert(boxes.size() == 2);
89
90 const auto& first = boxes[0];
91 assert(first.classification[0].class_idx == 0);
92 assert(std::abs(first.existence_probability - 0.5F) < 1e-6F);
93 assert(std::abs(first.length - 2.0F) < 1e-6F);
94 assert(std::abs(first.width - 1.0F) < 1e-6F);
95 assert(std::abs(first.height - 4.5F) < 1e-6F);
96 assert(std::abs(first.center[0] - 0.75F) < 1e-6F);
97 assert(std::abs(first.center[1] + 0.5F) < 1e-6F);
98 assert(std::abs(first.z - 2.25F) < 1e-6F);
99 assert(std::abs(first.yaw + 2.7831855F) < 1e-5F);
100
101 const auto& second = boxes[1];
102 assert(second.classification[1].class_idx == 1);
103 assert(std::abs(second.existence_probability - 0.880797F) < 1e-5F);
104 assert(std::abs(second.length - 5.0F) < 1e-6F);
105 assert(std::abs(second.width - 22.0F) < 1e-6F);
106 assert(std::abs(second.height - 12.0F) < 1e-6F);
107 assert(std::abs(second.center[0] + 0.5F) < 1e-6F);
108 assert(std::abs(second.center[1] - 3.8F) < 1e-6F);
109 assert(std::abs(second.z + 4.8F) < 1e-6F);
110 assert(std::abs(second.yaw - 2.7831855F) < 1e-5F);
111 }
112 return 0;
113}
PillarGrid BuildPillarGrid(const std::array< int, 2 > &pillar_map_size, const std::array< std::array< float, 2 >, 3 > &pillar_map_range, int first_up_stride, int stride)
std::vector< BoundingBox > DecodePbod(const PbodOutputsView &outputs, const PillarGrid &grid, const PbodPostprocessConfig &config)
const float * focal_logits
Shape [num_pillars].
int num_classes
Number of semantic classes.
int reg_dim
Regression values per pillar and class.
int num_pillars
Number of spatial pillars.
const float * class_logits
Shape [num_pillars, num_classes].
const float * size_posterior
Shape [num_pillars, num_classes * 3].
const float * reg_logits
Shape [num_pillars, num_classes * reg_dim].
std::vector< float > score_thresholds
Per-class thresholds, or one shared threshold.
std::vector< std::string > class_names
Class name in model-output order.

References pcod_common::BuildPillarGrid(), pcod_common::PbodOutputsView::class_logits, pcod_common::PbodPostprocessConfig::class_names, pcod_common::DecodePbod(), pcod_common::PbodOutputsView::focal_logits, pcod_common::PbodOutputsView::num_classes, pcod_common::PbodOutputsView::num_pillars, pcod_common::PbodOutputsView::reg_dim, pcod_common::PbodOutputsView::reg_logits, pcod_common::PbodPostprocessConfig::score_thresholds, and pcod_common::PbodOutputsView::size_posterior.