Skip to content

Commit

Permalink
bot: fetch update components
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Dec 25, 2024
1 parent f571077 commit 9f42e0c
Show file tree
Hide file tree
Showing 14 changed files with 1,136 additions and 60 deletions.
10 changes: 10 additions & 0 deletions src/components/sscma-micro/sscma/core/engine/ma_engine_hailo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,16 @@ ma_err_t EngineHailo::load(const string& model_path) {
tensor->shape.dims[2] = shape.features;
tensor->shape.dims[3] = shape.width;
break;
case HAILO_FORMAT_ORDER_NC:
if (shape.width != 1 || shape.height != 1) {
tensor->shape.dims[1] = shape.features;
tensor->shape.dims[2] = shape.height;
tensor->shape.dims[3] = shape.width;
break;
}
tensor->shape.dims[1] = shape.features;
tensor->shape.size = 2;
break;
default:
break;
}
Expand Down
2 changes: 2 additions & 0 deletions src/components/sscma-micro/sscma/core/ma_definations.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@

#define MA_STORAGE_KEY_TRIGGER_RULES "trigger#rules"

#define MA_STORAGE_KEY_WS_PORT "ws#port"


#define MA_AT_CMD_PREFIX "AT+"
#define MA_AT_CMD_QUERY "?"
Expand Down
11 changes: 7 additions & 4 deletions src/components/sscma-micro/sscma/core/ma_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ typedef struct {
} data;
bool is_physical; // For physical tensor
bool is_variable; // For constant tensor
void* external_handler = nullptr;
void* external_handler;
} ma_tensor_t;

typedef enum {
Expand Down Expand Up @@ -241,7 +241,8 @@ typedef enum {
MA_TRANSPORT_MQTT = 5,
MA_TRANSPORT_TCP = 6,
MA_TRANSPORT_UDP = 7,
MA_TRANSPORT_RTSP = 8
MA_TRANSPORT_RTSP = 8,
MA_TRANSPORT_WS = 9
} ma_transport_type_t;

typedef enum {
Expand Down Expand Up @@ -283,7 +284,9 @@ typedef enum {
MA_MODEL_TYPE_YOLO_WORLD = 8u,
MA_MODEL_TYPE_YOLO11 = 9u,
MA_MODEL_TYPE_YOLO11_POSE = 10u,
MA_MODEL_TYPE_YOLO11_SEG = 11u,
MA_MODEL_TYPE_YOLO11_SEG = 11u,
MA_MODEL_TYPE_YOLOV8_SGE = 12u,
MA_MODEL_TYPE_RTMDET = 13u
} ma_model_type_t;

typedef struct {
Expand Down Expand Up @@ -444,4 +447,4 @@ typedef struct in6_info_t {

#endif

#endif // _MA_TYPES_H_
#endif // _MA_TYPES_H_
17 changes: 16 additions & 1 deletion src/components/sscma-micro/sscma/core/math/ma_math_vectors.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
#ifndef _MA_MATH_VECTORS_H_
#define _MA_MATH_VECTORS_H_

#include <cstdint>
#include <cstddef>
#include <cstdint>

#if MA_USE_LIB_XTENSOR
#include <xtensor/xarray.hpp>
#include <xtensor/xmath.hpp>
#include <xtensor/xview.hpp>
#endif

namespace ma::math {

void softmax(float* data, size_t size);

void fastSoftmax(float* data, size_t size);

#if MA_USE_LIB_XTENSOR
template <typename QT>
static void dequantizeValues1D(xt::xarray<float>& dequantized_outputs, int index, const xt::xarray<QT>& quantized_outputs, size_t dim1, float32_t qp_scale, float32_t qp_zp) {
for (size_t i = 0; i < dim1; ++i) {
dequantized_outputs(i) = (float(quantized_outputs(index, i)) - qp_zp) * qp_scale;
}
}
#endif

} // namespace ma::math

#endif
95 changes: 63 additions & 32 deletions src/components/sscma-micro/sscma/core/model/ma_model_classifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ bool Classifier::isValid(Engine* engine) {
return false;
}

const auto& input_shape = engine->getInputShape(0);
const auto& output_shape{engine->getOutputShape(0)};

const auto input_shape = engine->getInputShape(0);
int n = input_shape.dims[0], h = input_shape.dims[1], w = input_shape.dims[2], c = input_shape.dims[3];
bool is_nhwc = c == 3 || c == 1;

Expand All @@ -52,17 +50,17 @@ bool Classifier::isValid(Engine* engine) {
if (n != 1 || h < 32 || h % 32 != 0 || (c != 3 && c != 1))
return false;

const auto output_shape = engine->getOutputShape(0);
if (output_shape.size != 2) {
return false;
}

if (output_shape.dims[0] != 1 || // N = 1
output_shape.dims[1] < 2 // C >= 2
) {
return false;
}

if (output_shape.size >= 3) {
return false;
}

return true;
}

Expand Down Expand Up @@ -91,32 +89,65 @@ ma_err_t Classifier::preprocess() {
ma_err_t Classifier::postprocess() {
results_.clear();

if (output_.type == MA_TENSOR_TYPE_S8) {
auto scale{output_.quant_param.scale};
auto zero_point{output_.quant_param.zero_point};
bool rescale{scale < 0.1f ? true : false};
auto* data = output_.data.s8;
switch (output_.type) {
case MA_TENSOR_TYPE_S8: {
auto scale{output_.quant_param.scale};
auto zero_point{output_.quant_param.zero_point};
bool rescale{scale < 0.1f ? true : false};
auto* data = output_.data.s8;
auto pred_l{output_.shape.dims[1]};

for (decltype(pred_l) i{0}; i < pred_l; ++i) {
auto score{static_cast<decltype(scale)>(data[i] - zero_point) * scale};
score = rescale ? score : score / 100.f;
if (score > threshold_score_)
results_.emplace_front(ma_class_t{score, i});
}
} break;

case MA_TENSOR_TYPE_U8: {
auto scale{output_.quant_param.scale};
auto zero_point{output_.quant_param.zero_point};
bool rescale{scale < 0.1f ? true : false};
auto* data = output_.data.u8;
auto pred_l{output_.shape.dims[1]};

for (decltype(pred_l) i{0}; i < pred_l; ++i) {
auto score{static_cast<decltype(scale)>(data[i] - zero_point) * scale};
score = rescale ? score : score / 100.f;
if (score > threshold_score_)
results_.emplace_front(ma_class_t{score, i});
}
} break;

case MA_TENSOR_TYPE_U16: {
auto scale{output_.quant_param.scale};
auto zero_point{output_.quant_param.zero_point};
bool rescale{scale < 0.1f ? true : false};
auto* data = output_.data.u16;
auto pred_l{output_.shape.dims[1]};

for (decltype(pred_l) i{0}; i < pred_l; ++i) {
auto score{static_cast<decltype(scale)>(data[i] - zero_point) * scale};
score = rescale ? score : score / 100.f;
if (score > threshold_score_)
results_.emplace_front(ma_class_t{score, i});
}
} break;


case MA_TENSOR_TYPE_F32: {
auto* data = output_.data.f32;
auto pred_l{output_.shape.dims[1]};
for (decltype(pred_l) i{0}; i < pred_l; ++i) {
auto score{data[i]};
if (score > threshold_score_)
results_.emplace_front(ma_class_t{score, i});
}
} break;

auto pred_l{output_.shape.dims[1]};

for (decltype(pred_l) i{0}; i < pred_l; ++i) {
auto score{static_cast<decltype(scale)>(data[i] - zero_point) * scale};
score = rescale ? score : score / 100.f;
if (score > threshold_score_)
results_.emplace_front(ma_class_t{score, i});
}
}
if (output_.type == MA_TENSOR_TYPE_F32) {
auto* data = output_.data.f32;
auto pred_l{output_.shape.dims[1]};
for (decltype(pred_l) i{0}; i < pred_l; ++i) {
auto score{data[i]};
if (score > threshold_score_)
results_.emplace_front(ma_class_t{score, i});
}

} else {
return MA_ENOTSUP;
default:
return MA_ENOTSUP;
}

results_.sort([](const ma_class_t& a, const ma_class_t& b) { return a.score > b.score; });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ Model* ModelFactory::create(Engine* engine, size_t algorithm_id) {
if (YoloV8PoseHailo::isValid(engine)) {
return new YoloV8PoseHailo(engine);
}

if (YoloV8SegHailo::isValid(engine)) {
return new YoloV8SegHailo(engine);
}
#endif
if (YoloV8Pose::isValid(engine)) {
return new YoloV8Pose(engine);
Expand All @@ -52,6 +56,11 @@ Model* ModelFactory::create(Engine* engine, size_t algorithm_id) {
return new NvidiaDet(engine);
}

case MA_MODEL_TYPE_RTMDET:
if (RTMDet::isValid(engine)) {
return new RTMDet(engine);
}

case MA_MODEL_TYPE_YOLO_WORLD:
if (YoloWorld::isValid(engine)) {
return new YoloWorld(engine);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include "ma_model_yolov8.h"
#include "ma_model_yolov8_pose.h"
#include "ma_model_yolov8_pose_hailo.h"
#include "ma_model_yolov8_seg_hailo.h"
#include "ma_model_rtmdet.h"

namespace ma {

Expand Down
Loading

0 comments on commit 9f42e0c

Please sign in to comment.