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  static_resource->shared_threshold_score = score / 100.0;
29  MA_STORAGE_NOSTA_SET_POD(static_resource->device->getStorage(), "ma#score_threshold", static_resource->shared_threshold_score);
30  }
31 
32 exit:
33  auto value = static_cast<uint64_t>(std::round(static_resource->shared_threshold_score * 100));
34  encoder.begin(MA_MSG_TYPE_RESP, ret, argv[0], value);
35  encoder.end();
36  transport.send(reinterpret_cast<const char*>(encoder.data()), encoder.size());
37 }
38 
39 void setNMSThreshold(const std::vector<std::string>& argv, Transport& transport, Encoder& encoder) {
40  ma_err_t ret = MA_OK;
41 
42  if (argv.size() < 2) {
43  ret = MA_EINVAL;
44  goto exit;
45  }
46 
47  {
48  int nms = std::atoi(argv[1].c_str());
49  if (nms <= 0 || nms > 100) {
50  ret = MA_EINVAL;
51  goto exit;
52  }
53  static_resource->shared_threshold_nms = nms / 100.0;
54 
55  MA_STORAGE_NOSTA_SET_POD(static_resource->device->getStorage(), "ma#nms_threshold", static_resource->shared_threshold_nms);
56  }
57 
58 exit:
59  auto value = static_cast<uint64_t>(std::round(static_resource->shared_threshold_nms * 100));
60  encoder.begin(MA_MSG_TYPE_RESP, ret, argv[0], value);
61  encoder.end();
62  transport.send(reinterpret_cast<const char*>(encoder.data()), encoder.size());
63 }
64 
65 void getScoreThreshold(const std::vector<std::string>& argv, Transport& transport, Encoder& encoder) {
66  ma_err_t ret = MA_OK;
67 
68  MA_STORAGE_GET_POD(static_resource->device->getStorage(), "ma#score_threshold", static_resource->shared_threshold_score, static_resource->shared_threshold_score);
69 
70  encoder.begin(MA_MSG_TYPE_RESP, ret, argv[0], static_cast<uint64_t>(std::round(static_resource->shared_threshold_score * 100)));
71  encoder.end();
72  transport.send(reinterpret_cast<const char*>(encoder.data()), encoder.size());
73 }
74 
75 void getNMSThreshold(const std::vector<std::string>& argv, Transport& transport, Encoder& encoder) {
76  ma_err_t ret = MA_OK;
77 
78  MA_STORAGE_GET_POD(static_resource->device->getStorage(), "ma#nms_threshold", static_resource->shared_threshold_nms, static_resource->shared_threshold_nms);
79 
80  encoder.begin(MA_MSG_TYPE_RESP, ret, argv[0], static_cast<uint64_t>(std::round(static_resource->shared_threshold_nms * 100)));
81  encoder.end();
82  transport.send(reinterpret_cast<const char*>(encoder.data()), encoder.size());
83 }
84 
85 } // 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:253
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:39
void getNMSThreshold(const std::vector< std::string > &argv, Transport &transport, Encoder &encoder)
Definition: config.hpp:75
void getScoreThreshold(const std::vector< std::string > &argv, Transport &transport, Encoder &encoder)
Definition: config.hpp:65
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:48
Definition: ma_cv.cpp:7
#define static_resource
Definition: resource.hpp:67