Skip to content

Commit 3fef41c

Browse files
committed
fix: resolve runtime error in preprocess and postprocess
Signed-off-by: ktro2828 <kotaro.uetake@tier4.jp>
1 parent a65a8b8 commit 3fef41c

File tree

13 files changed

+529
-521
lines changed

13 files changed

+529
-521
lines changed

perception/tensorrt_mtr/config/tensorrt_mtr.param.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
max_num_polyline: 798
1010
max_num_point: 20
1111
point_break_distance: 1.0
12-
offset_xy: [30.0, 0.0]
1312
intention_point_filepath: "$(var data_path)/intention_point.csv"
1413
num_intention_point_cluster: 64
1514
polyline_label_path: "$(var data_path)/polyline_label.txt"

perception/tensorrt_mtr/include/tensorrt_mtr/agent.hpp

+68-73
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ enum AgentLabel { VEHICLE = 0, PEDESTRIAN = 1, CYCLIST = 2 };
3434
*/
3535
struct AgentState
3636
{
37-
/**
38-
* @brief Construct a new instance filling all elements by `0.0f`.
39-
*/
37+
// Construct a new instance filling all elements by `0.0f`.
4038
AgentState() : data_({0.0f}) {}
4139

4240
/**
@@ -84,33 +82,49 @@ struct AgentState
8482
std::copy(itr, itr + dim(), data_.begin());
8583
}
8684

87-
static size_t dim() { return AgentStateDim; }
88-
89-
/**
90-
* @brief Construct a new instance filling all elements by `0.0f`.
91-
*
92-
* @return AgentState
93-
*/
85+
// Construct a new instance filling all elements by `0.0f`.
9486
static AgentState empty() noexcept { return AgentState(); }
9587

96-
/**
97-
* @brief Return the address pointer of data array.
98-
*
99-
* @return float*
100-
*/
88+
// Return the agent state dimensions `D`.
89+
static size_t dim() { return AgentStateDim; }
90+
91+
// Return the address pointer of data array.
10192
float * data_ptr() noexcept { return data_.data(); }
10293

94+
// Return the x position.
10395
float x() const { return x_; }
96+
97+
// Return the y position.
10498
float y() const { return y_; }
99+
100+
// Return the z position.
105101
float z() const { return z_; }
102+
103+
// Return the length of object size.
106104
float length() const { return length_; }
105+
106+
// Return the width of object size.
107107
float width() const { return width_; }
108+
109+
// Return the height of object size.
108110
float height() const { return height_; }
111+
112+
// Return the yaw angle `[rad]`.
109113
float yaw() const { return yaw_; }
114+
115+
// Return the x velocity.
110116
float vx() const { return vx_; }
117+
118+
// Return the y velocity.
111119
float vy() const { return vy_; }
120+
121+
// Return the x acceleration.
112122
float ax() const { return ax_; }
123+
124+
// Return the y acceleration.
113125
float ay() const { return ay_; }
126+
127+
// Return `true` if the value is `1.0`.
114128
bool is_valid() const { return is_valid_ == 1.0f; }
115129

116130
private:
@@ -163,34 +177,19 @@ struct AgentHistory
163177
{
164178
}
165179

166-
static size_t state_dim() { return AgentStateDim; }
167-
168-
/**
169-
* @brief Return the history length.
170-
*
171-
* @return size_t History length.
172-
*/
180+
// Return the history time length `T`.
173181
size_t length() const { return max_time_length_; }
174182

175-
/**
176-
* @brief Return the data size of history `T * D`.
177-
*
178-
* @return size_t
179-
*/
183+
// Return the number of agent state dimensions `D`.
184+
static size_t state_dim() { return AgentStateDim; }
185+
186+
// Return the data size of history `T * D`.
180187
size_t size() const { return max_time_length_ * state_dim(); }
181188

182-
/**
183-
* @brief Return the shape of history matrix ordering in `(T, D)`.
184-
*
185-
* @return std::tuple<size_t, size_t>
186-
*/
189+
// Return the shape of history matrix ordering in `(T, D)`.
187190
std::tuple<size_t, size_t> shape() const { return {max_time_length_, state_dim()}; }
188191

189-
/**
190-
* @brief Return the object id.
191-
*
192-
* @return const std::string&
193-
*/
192+
// Return the object id.
194193
const std::string & object_id() const { return object_id_; }
195194

196195
size_t label_index() const { return label_index_; }
@@ -220,10 +219,7 @@ struct AgentHistory
220219
latest_time_ = current_time;
221220
}
222221

223-
/**
224-
* @brief Update history with all-zeros state, but latest time is not updated.
225-
*
226-
*/
222+
// Update history with all-zeros state, but latest time is not updated.
227223
void update_empty() noexcept
228224
{
229225
// remove the state at the oldest timestamp
@@ -235,11 +231,7 @@ struct AgentHistory
235231
}
236232
}
237233

238-
/**
239-
* @brief Return the address pointer of data array.
240-
*
241-
* @return float* The pointer of data array.
242-
*/
234+
// Return the address pointer of data array.
243235
float * data_ptr() noexcept { return data_.data(); }
244236

245237
/**
@@ -264,11 +256,7 @@ struct AgentHistory
264256
*/
265257
bool is_valid_latest() const { return get_latest_state().is_valid(); }
266258

267-
/**
268-
* @brief Get the latest agent state.
269-
*
270-
* @return AgentState
271-
*/
259+
// Get the latest agent state at `T`.
272260
AgentState get_latest_state() const
273261
{
274262
const auto & latest_itr = (data_.begin() + state_dim() * (max_time_length_ - 1));
@@ -338,49 +326,55 @@ struct AgentData
338326
}
339327
}
340328

341-
static size_t state_dim() { return AgentStateDim; }
329+
// Return the number of classes `C`.
342330
static size_t num_class() { return 3; } // TODO(ktro2828): Do not use magic number.
331+
332+
// Return the number of target agents `B`.
343333
size_t num_target() const { return num_target_; }
334+
335+
// Return the number of agents `N`.
344336
size_t num_agent() const { return num_agent_; }
337+
338+
// Return the timestamp length `T`.
345339
size_t time_length() const { return time_length_; }
340+
341+
// Return the number of agent state dimensions `D`.
342+
static size_t state_dim() { return AgentStateDim; }
343+
344+
// Return the index of ego.
346345
int sdc_index() const { return sdc_index_; }
346+
347+
// Return the vector of indices of target agents, in shape `[B]`.
347348
const std::vector<size_t> & target_index() const { return target_index_; }
349+
350+
// Return the vector of label indices of all agents, in shape `[N]`.
348351
const std::vector<size_t> & label_index() const { return label_index_; }
352+
353+
// Return the vector of label indices of target agents, in shape `[B]`.
349354
const std::vector<size_t> & target_label_index() const { return target_label_index_; }
355+
356+
// Return the vector of timestamps in shape `[T]`.
350357
const std::vector<float> & timestamps() const { return timestamps_; }
351358

359+
// Return the number of all elements `N*T*D`.
352360
size_t size() const { return num_agent_ * time_length_ * state_dim(); }
353-
size_t input_dim() const { return num_agent_ + time_length_ + num_class() + 3; }
354361

355-
/**
356-
* @brief Return the data shape ordering in (N, T, D).
357-
*
358-
* @return std::tuple<size_t, size_t, size_t>
359-
*/
362+
// Return the number of state dimensions of MTR input `T+C+D+3`.
363+
size_t input_dim() const { return time_length_ + state_dim() + num_class() + 3; }
364+
365+
// Return the data shape ordering in (N, T, D).
360366
std::tuple<size_t, size_t, size_t> shape() const
361367
{
362368
return {num_agent_, time_length_, state_dim()};
363369
}
364370

365-
/**
366-
* @brief Return the address pointer of data array.
367-
*
368-
* @return float* The pointer of data array.
369-
*/
371+
// Return the address pointer of data array.
370372
float * data_ptr() noexcept { return data_.data(); }
371373

372-
/**
373-
* @brief Return the address pointer of data array for target agents.
374-
*
375-
* @return float* The pointer of data array for target agents.
376-
*/
374+
// Return the address pointer of data array for target agents.
377375
float * target_data_ptr() noexcept { return target_data_.data(); }
378376

379-
/**
380-
* @brief Return the address pointer of data array for ego vehicle.
381-
*
382-
* @return float* The pointer of data array for ego vehicle.
383-
*/
377+
// Return the address pointer of data array for ego vehicle.
384378
float * ego_data_ptr() noexcept { return ego_data_.data(); }
385379

386380
private:
@@ -397,6 +391,7 @@ struct AgentData
397391
std::vector<float> ego_data_;
398392
};
399393

394+
// Get label names from label indices.
400395
std::vector<std::string> getLabelNames(const std::vector<size_t> & label_index)
401396
{
402397
std::vector<std::string> label_names;

perception/tensorrt_mtr/include/tensorrt_mtr/intention_point.hpp

+2-10
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,10 @@ struct IntentionPoint
107107
return points;
108108
}
109109

110-
/**
111-
* @brief Return the size of intension point K * D.
112-
*
113-
* @return size_t
114-
*/
110+
// Return the size of intension point `K*D`.
115111
size_t size() const { return num_cluster_ * state_dim(); }
116112

117-
/**
118-
* @brief Return the number of clusters contained in intention points.
119-
*
120-
* @return size_t
121-
*/
113+
// Return the number of clusters contained in intention points `K`.
122114
size_t num_cluster() const { return num_cluster_; }
123115

124116
private:

perception/tensorrt_mtr/include/tensorrt_mtr/node.hpp

+15-61
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,8 @@ class PolylineTypeMap
8888
}
8989
}
9090

91-
/**
92-
* @brief Return the ID of the corresponding label type.
93-
* If specified type is not contained in map, return -1.
94-
*
95-
* @param type
96-
* @return int
97-
*/
91+
// Return the ID of the corresponding label type. If specified type is not contained in map,
92+
// return `-1`.
9893
int getTypeID(const std::string & type) const
9994
{
10095
return label_map_.count(type) == 0 ? -1 : label_map_.at(type);
@@ -109,83 +104,42 @@ class MTRNode : public rclcpp::Node
109104
public:
110105
explicit MTRNode(const rclcpp::NodeOptions & node_options);
111106

112-
// Object ID for ego vehicle
107+
// Object ID of the ego vehicle
113108
const std::string EGO_ID{"EGO"};
114109

115110
private:
116-
/**
117-
* @brief Main callback being invoked when the tracked objects topic is subscribed.
118-
*
119-
* @param object_msg
120-
*/
111+
// Main callback being invoked when the tracked objects topic is subscribed.
121112
void callback(const TrackedObjects::ConstSharedPtr object_msg);
122113

123-
/**
124-
* @brief Callback being invoked when the HD map topic is subscribed.
125-
*
126-
* @param map_msg
127-
*/
114+
// Callback being invoked when the HD map topic is subscribed.
128115
void onMap(const HADMapBin::ConstSharedPtr map_msg);
129116

130-
/**
131-
* @brief Callback being invoked when the Ego's odometry topic is subscribed.
132-
*
133-
* @param ego_msg
134-
*/
117+
// Callback being invoked when the Ego's odometry topic is subscribed.
135118
void onEgo(const Odometry::ConstSharedPtr ego_msg);
136119

137-
/**
138-
* @brief Converts lanelet2 to polylines.
139-
*
140-
* @return true
141-
*/
120+
// Convert Lanelet to `PolylineData`.
142121
bool convertLaneletToPolyline();
143122

144-
/**
145-
* @brief Remove ancient agent histories.
146-
*
147-
* @param current_time
148-
* @param objects_msg
149-
*/
123+
// Remove ancient agent histories.
150124
void removeAncientAgentHistory(
151125
const float current_time, const TrackedObjects::ConstSharedPtr objects_msg);
152126

153-
/**
154-
* @brief Appends new states to history.
155-
*
156-
* @param current_time
157-
* @param objects_msg
158-
*/
127+
// Appends new states to history.
159128
void updateAgentHistory(
160129
const float current_time, const TrackedObjects::ConstSharedPtr objects_msg);
161130

131+
// Extract ego state stored in the buffer which has the nearest timestamp from current timestamp.
162132
AgentState extractNearestEgo(const float current_time) const;
163133

164-
/**
165-
* @brief Extract target agents and return corresponding indices.
166-
*
167-
* NOTE: Extract targets in order of proximity, closest first.
168-
*
169-
* @param histories
170-
* @return std::vector<size_t>
171-
*/
134+
// Extract target agents and return corresponding indices.
135+
// NOTE: Extract targets in order of proximity, closest first.
172136
std::vector<size_t> extractTargetAgent(const std::vector<AgentHistory> & histories);
173137

174-
/**
175-
* @brief Return the timestamps relative from the first element.Return the timestamps relative
176-
* from the first element.
177-
*
178-
* @return std::vector<float>
179-
*/
138+
// Return the timestamps relative from the first element.Return the timestamps relative from the
139+
// first element.
180140
std::vector<float> getRelativeTimestamps() const;
181141

182-
/**
183-
* @brief Generate `PredictedObject` from `PredictedTrajectory`.
184-
*
185-
* @param object
186-
* @param trajectory
187-
* @return PredictedObject
188-
*/
142+
// Generate `PredictedObject` from `PredictedTrajectory`.
189143
PredictedObject generatePredictedObject(
190144
const TrackedObject & object, const PredictedTrajectory & trajectory);
191145

0 commit comments

Comments
 (0)