sp500/yolo.h Source File

sp500/yolo.h Source File#

Mobilint REGULUS: sp500/yolo.h Source File
Mobilint REGULUS v4.1
SP500 DSP API
yolo.h
Go to the documentation of this file.
1
69#ifndef SP500_YOLO_H
70#define SP500_YOLO_H
71
72#include <sp500/dsp.h>
73
74#ifdef __cplusplus
75extern "C" {
76#endif
77
79#define SP500_YOLO_LEVELS 3
80
82#define SP500_YOLO_POSE_KEYPOINTS 17
83
85#define SP500_YOLO_DETECT_RECORD_FLOATS 6
86#define SP500_YOLO_SEGMENT_RECORD_FLOATS 11
87#define SP500_YOLO_POSE_RECORD_FLOATS 57
88
92#define SP500_YOLO_MASK_NONE 0xFFFFFFFFu
93
96#define SP500_YOLO_MAX_CANDIDATES 1024
97
99enum
100{
101 SP500_YOLO_HEAD_ANCHORLESS = 0,
102 SP500_YOLO_HEAD_ANCHOR = 1,
103 SP500_YOLO_HEAD_NMSFREE = 2,
104 SP500_YOLO_HEAD_DFLFREE = 3
105};
106
108enum
109{
113};
114
115/* ------------------------------------------------------------- records --- */
116
119{
120 float x1;
121 float y1;
122 float x2;
123 float y2;
124 float score;
125 float class_id;
127
143
146{
147 float x;
148 float y;
149 float score;
151
159
162SP500_API uint32_t sp500_yolo_mask_offset(const sp500_yolo_segmentation* record);
163
164/* ------------------------------------------------------------ parameters -- */
165
173typedef struct sp500_yolo_params
174{
175 int32_t img_w;
176 int32_t img_h;
177 int32_t num_classes;
183
184 /* ---- ::SP500_YOLO_HEAD_ANCHOR only, and only when decoding ---- */
187 const float* anchors;
192 uint32_t anchors_count;
194 uint32_t reserved0;
195
196 /* ---- ::SP500_YOLO_TASK_SEGMENT only; all five are required together ---- */
199 int32_t mask_coeffs;
200 int32_t proto_h;
201 int32_t proto_w;
204
205 uint32_t reserved[6];
207
210
211/* ----------------------------------------------------------- raw tensors -- */
212
232
235
250
253
254/* --------------------------------------------------------------- results -- */
255
268
271
273typedef struct sp500_yolo_result
274{
275 uint32_t count;
278 uint32_t reserved[4];
280
281/* --------------------------------------------------------------- helpers -- */
282
284SP500_API int32_t sp500_yolo_record_floats(int32_t task);
285
288SP500_API uint32_t sp500_yolo_records_bytes(int32_t task, int32_t max_detections);
289
293SP500_API int32_t sp500_yolo_grid_cells(int32_t img_w, int32_t img_h);
294
315SP500_API sp500_status sp500_yolo_head_for_model(const char* model_name, int32_t* head);
316
317/* --------------------------------------------------------- entry points --- */
318
346SP500_API sp500_status sp500_yolo_decode(int32_t head, int32_t task,
347 const sp500_yolo_raw* raw,
348 const sp500_yolo_params* params,
349 sp500_yolo_output* output,
350 sp500_yolo_result* result);
351
367 const sp500_yolo_raw_anchor* raw,
368 const sp500_yolo_params* params,
369 sp500_yolo_output* output,
370 sp500_yolo_result* result);
371
395SP500_API sp500_status sp500_yolo_postprocess(int32_t head, int32_t task,
396 const sp500_buffer* decoded,
397 int32_t num_rows,
398 const sp500_yolo_params* params,
399 sp500_yolo_output* output,
400 sp500_yolo_result* result);
401
402#ifdef __cplusplus
403} /* extern "C" */
404#endif
405
406#endif /* SP500_YOLO_H */
Mobilint SP500 DSP offload - status codes, lifecycle and shared memory.
int32_t sp500_status
Result of every sp500 call.
Definition dsp.h:83
A tensor handed to or received from the DSP.
Definition dsp.h:261
One detection. 6 floats; the layout of a SP500_YOLO_TASK_DETECT record.
Definition yolo.h:119
One keypoint of a pose record.
Definition yolo.h:146
Where the results go.
Definition yolo.h:258
uint32_t reserved[4]
Definition yolo.h:266
sp500_buffer records
Definition yolo.h:261
sp500_buffer mask
Definition yolo.h:265
Model shape and thresholds.
Definition yolo.h:174
int32_t img_h
Definition yolo.h:176
int32_t mask_coeffs
Definition yolo.h:199
int32_t anchors_per_level
Definition yolo.h:185
float mask_threshold
Definition yolo.h:202
uint32_t reserved0
Definition yolo.h:194
sp500_buffer proto
Definition yolo.h:197
int32_t proto_w
Definition yolo.h:201
int32_t num_classes
Definition yolo.h:177
int32_t img_w
Definition yolo.h:175
int32_t proto_h
Definition yolo.h:200
int32_t max_detections
Definition yolo.h:178
const float * anchors
Definition yolo.h:187
uint32_t anchors_count
Definition yolo.h:192
float conf_threshold
Definition yolo.h:180
float iou_threshold
Definition yolo.h:181
uint32_t reserved[6]
Definition yolo.h:205
One pose result. 57 floats; the layout of a SP500_YOLO_TASK_POSE record.
Definition yolo.h:155
sp500_yolo_keypoint keypoints[SP500_YOLO_POSE_KEYPOINTS]
Definition yolo.h:157
sp500_yolo_detection det
Definition yolo.h:156
Raw head tensors as one combined tensor per level. SP500_YOLO_HEAD_ANCHOR only.
Definition yolo.h:246
sp500_buffer plane[SP500_YOLO_LEVELS]
Definition yolo.h:247
uint32_t reserved[4]
Definition yolo.h:248
Raw head tensors as separate planes, one set per feature level.
Definition yolo.h:221
sp500_buffer box[SP500_YOLO_LEVELS]
Definition yolo.h:224
sp500_buffer extra[SP500_YOLO_LEVELS]
Definition yolo.h:229
sp500_buffer cls[SP500_YOLO_LEVELS]
Definition yolo.h:226
uint32_t reserved[4]
Definition yolo.h:230
What a YOLO call produced.
Definition yolo.h:274
int32_t record_floats
Definition yolo.h:276
uint32_t reserved[4]
Definition yolo.h:278
double host_seconds
Definition yolo.h:277
uint32_t count
Definition yolo.h:275
One segmentation result. 11 floats; the layout of a SP500_YOLO_TASK_SEGMENT record.
Definition yolo.h:131
sp500_yolo_detection det
Definition yolo.h:132
void sp500_yolo_raw_anchor_init(sp500_yolo_raw_anchor *raw)
Zero raw so every plane reads as unused.
sp500_status sp500_yolo_decode(int32_t head, int32_t task, const sp500_yolo_raw *raw, const sp500_yolo_params *params, sp500_yolo_output *output, sp500_yolo_result *result)
Decode a split-plane head and remove duplicates, in one DSP call.
uint32_t sp500_yolo_mask_offset(const sp500_yolo_segmentation *record)
Mask offset of a segmentation record, decoded from its float slot. Returns SP500_YOLO_MASK_NONE when ...
@ SP500_YOLO_TASK_DETECT
Definition yolo.h:110
@ SP500_YOLO_TASK_SEGMENT
Definition yolo.h:111
@ SP500_YOLO_TASK_POSE
Definition yolo.h:112
void sp500_yolo_raw_init(sp500_yolo_raw *raw)
Zero raw so every plane reads as unused.
uint32_t sp500_yolo_records_bytes(int32_t task, int32_t max_detections)
Bytes needed by output.records for max_detections records of task, or 0 for invalid arguments.
#define SP500_YOLO_POSE_KEYPOINTS
Keypoints in a pose record; the fixed COCO 17-point layout.
Definition yolo.h:82
void sp500_yolo_params_init(sp500_yolo_params *params)
Fill params with the defaults documented above.
void sp500_yolo_output_init(sp500_yolo_output *output)
Zero output so every buffer reads as unused.
sp500_status sp500_yolo_postprocess(int32_t head, int32_t task, const sp500_buffer *decoded, int32_t num_rows, const sp500_yolo_params *params, sp500_yolo_output *output, sp500_yolo_result *result)
Select detections from an already-decoded anchor table.
sp500_status sp500_yolo_decode_anchor(int32_t task, const sp500_yolo_raw_anchor *raw, const sp500_yolo_params *params, sp500_yolo_output *output, sp500_yolo_result *result)
Decode an anchor head and remove duplicates, in one DSP call. SP500_YOLO_HEAD_ANCHOR only.
sp500_status sp500_yolo_head_for_model(const char *model_name, int32_t *head)
Head family for a model name, so you do not have to memorise the table.
#define SP500_YOLO_LEVELS
Feature levels a YOLO head produces: strides 8, 16 and 32.
Definition yolo.h:79
int32_t sp500_yolo_grid_cells(int32_t img_w, int32_t img_h)
Grid cells summed over the three levels for a img_w x img_h input: the row count of a decoded anchor-...
int32_t sp500_yolo_record_floats(int32_t task)
Floats in one record of task, or 0 for an unknown task.