SSCMA-Micro CPP SDK  v2.0.0
SSCMA-Micro is a cross-platform machine learning inference framework designed for embedded devices.
config.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <string>
4 
5 #include "core/ma_core.h"
6 #include "porting/ma_porting.h"
7 #include "resource.hpp"
8 
9 namespace ma::server::callback {
10 
11 using namespace ma;
12 
13 void setScoreThreshold(const std::vector<std::string>& argv, Transport& transport, Encoder& encoder) {
14  ma_err_t ret = MA_OK;
15 
16  if (argv.size() < 2) {
17  ret = MA_EINVAL;
18  goto exit;
19  }
20 
21  {
22  int score = std::atoi(argv[1].c_str());
23  if (score <= 0 || score > 100) {
24  ret = MA_EINVAL;
25  goto exit;
26  }
27 
28  MA_STORAGE_SET_POD(ret, static_resource->device->getStorage(), "ma#score_threshold", score);
29  if (ret != MA_OK) {
30  goto exit;
31  }
32 
33  static_resource->shared_threshold_score = score / 100.0;
34  }
35 
36 exit:
37  auto value = static_cast<uint64_t>(std::round(static_resource->shared_threshold_score * 100));
38  encoder.begin(MA_MSG_TYPE_RESP, ret, argv[0], value);
39  encoder.end();
40  transport.send(reinterpret_cast<const char*>(encoder.data()), encoder.size());
41 }
42 
43 void setNMSThreshold(const std::vector<std::string>& argv, Transport& transport, Encoder& encoder) {
44  ma_err_t ret = MA_OK;
45 
46  if (argv.size() < 2) {
47  ret = MA_EINVAL;
48  goto exit;
49  }
50 
51  {
52  int nms = std::atoi(argv[1].c_str());
53  if (nms <= 0 || nms > 100) {
54  ret = MA_EINVAL;
55  goto exit;
56  }
57 
58  MA_STORAGE_SET_POD(ret, static_resource->device->getStorage(), "ma#nms_threshold", nms);
59  if (ret != MA_OK) {
60  goto exit;
61  }
62 
63  static_resource->shared_threshold_nms = nms / 100.0;
64  }
65 
66 exit:
67  auto value = static_cast<uint64_t>(std::round(static_resource->shared_threshold_nms * 100));
68  encoder.begin(MA_MSG_TYPE_RESP, ret, argv[0], value);
69  encoder.end();
70  transport.send(reinterpret_cast<const char*>(encoder.data()), encoder.size());
71 }
72 
73 void getScoreThreshold(const std::vector<std::string>& argv, Transport& transport, Encoder& encoder) {
74  ma_err_t ret = MA_OK;
75 
76  int score = std::round(static_resource->shared_threshold_score * 100);
77  MA_STORAGE_GET_POD(static_resource->device->getStorage(), "ma#score_threshold", score, score);
78 
79  encoder.begin(MA_MSG_TYPE_RESP, ret, argv[0], static_cast<uint64_t>(score));
80  encoder.end();
81  transport.send(reinterpret_cast<const char*>(encoder.data()), encoder.size());
82 }
83 
84 void getNMSThreshold(const std::vector<std::string>& argv, Transport& transport, Encoder& encoder) {
85  ma_err_t ret = MA_OK;
86 
87  int nms = std::round(static_resource->shared_threshold_nms * 100);
88  MA_STORAGE_GET_POD(static_resource->device->getStorage(), "ma#nms_threshold", nms, nms);
89 
90  encoder.begin(MA_MSG_TYPE_RESP, ret, argv[0], static_cast<uint64_t>(nms));
91  encoder.end();
92  transport.send(reinterpret_cast<const char*>(encoder.data()), encoder.size());
93 }
94 
95 } // namespace ma::server::callback
Definition: ma_codec_base.h:14
virtual ma_err_t end()=0
Encoder type for end.
virtual const void * data() const =0
Encoder type for get data.
virtual ma_err_t begin()=0
Encoder type for begin.
virtual const size_t size() const =0
Encoder type for get size.
Definition: ma_transport.h:12
virtual size_t send(const char *data, size_t length) noexcept=0
@ MA_MSG_TYPE_RESP
Definition: ma_types.h:252
ma_err_t
Definition: ma_types.h:21
@ MA_OK
Definition: ma_types.h:23
@ MA_EINVAL
Definition: ma_types.h:28
Definition: algorithm.hpp:11
void setNMSThreshold(const std::vector< std::string > &argv, Transport &transport, Encoder &encoder)
Definition: config.hpp:43
void getNMSThreshold(const std::vector< std::string > &argv, Transport &transport, Encoder &encoder)
Definition: config.hpp:84
void getScoreThreshold(const std::vector< std::string > &argv, Transport &transport, Encoder &encoder)
Definition: config.hpp:73
void setScoreThreshold(const std::vector< std::string > &argv, Transport &transport, Encoder &encoder)
Definition: config.hpp:13
void nms(std::forward_list< ma_bbox_t > &bboxes, float threshold_iou, float threshold_score, bool soft_nms, bool multi_target)
Definition: ma_nms.cpp:62
Definition: ma_cv.cpp:7
#define static_resource
Definition: resource.hpp:64