diff --git a/configs/sample_person_shoe_two_stage.json b/configs/sample_person_shoe_two_stage.json index 98bc00c..80a8cf3 100644 --- a/configs/sample_person_shoe_two_stage.json +++ b/configs/sample_person_shoe_two_stage.json @@ -37,6 +37,9 @@ "type": "ai_yolo", "role": "filter", "enable": true, + "use_rga": true, + "rga_gate": "person_shoe_two_stage", + "rga_max_inflight": 4, "infer_fps": 2, "model_path": "./models/yolov8n-640.rknn", "model_version": "v8", diff --git a/configs/sample_person_shoe_two_stage_balanced.json b/configs/sample_person_shoe_two_stage_balanced.json index e4627ad..158f59d 100644 --- a/configs/sample_person_shoe_two_stage_balanced.json +++ b/configs/sample_person_shoe_two_stage_balanced.json @@ -37,6 +37,9 @@ "type": "ai_yolo", "role": "filter", "enable": true, + "use_rga": true, + "rga_gate": "person_shoe_two_stage_balanced", + "rga_max_inflight": 4, "infer_fps": 2, "model_path": "./models/yolov8n-640.rknn", "model_version": "v8", diff --git a/configs/sample_person_shoe_two_stage_recall.json b/configs/sample_person_shoe_two_stage_recall.json index bf58c30..020520c 100644 --- a/configs/sample_person_shoe_two_stage_recall.json +++ b/configs/sample_person_shoe_two_stage_recall.json @@ -37,6 +37,9 @@ "type": "ai_yolo", "role": "filter", "enable": true, + "use_rga": true, + "rga_gate": "person_shoe_two_stage_recall", + "rga_max_inflight": 4, "infer_fps": 3, "model_path": "./models/yolov8n-640.rknn", "model_version": "v8", diff --git a/plugins/ai_yolo/ai_yolo_node.cpp b/plugins/ai_yolo/ai_yolo_node.cpp index f1fb476..ab57e26 100644 --- a/plugins/ai_yolo/ai_yolo_node.cpp +++ b/plugins/ai_yolo/ai_yolo_node.cpp @@ -10,6 +10,7 @@ #include #include +#include "hw/i_image_processor.h" #include "hw/i_infer_backend.h" #include "node.h" #include "utils/dma_alloc.h" @@ -732,6 +733,7 @@ public: LogError("[ai_yolo] no infer backend for node " + id_); return false; } + image_processor_ = ctx.image_processor; #if defined(RK3588_ENABLE_RKNN) if (model_path_.empty()) { @@ -895,7 +897,6 @@ private: return; } - if (frame->DmaFd() >= 0) frame->SyncStart(); const size_t input_row = static_cast(model_input_w_) * 3; const size_t input_size = input_row * static_cast(model_input_h_); resized_input_.resize(input_size); @@ -906,12 +907,49 @@ private: src + static_cast(y) * static_cast(src_stride), input_row); } + } else if (image_processor_ && w > 0 && h > 0) { + Frame src_frame; + src_frame.width = w; + src_frame.height = h; + src_frame.format = PixelFormat::RGB; + src_frame.stride = src_stride; + src_frame.data = const_cast(src); + src_frame.data_size = frame->data_size; + src_frame.plane_count = 1; + src_frame.planes[0] = {src_frame.data, src_stride, static_cast(frame->data_size), 0}; + + Frame resized_frame; + resized_frame.width = model_input_w_; + resized_frame.height = model_input_h_; + resized_frame.format = PixelFormat::RGB; + + Status st = image_processor_->Resize(src_frame, resized_frame); + if (st.Ok()) { + const uint8_t* resized_data = resized_frame.planes[0].data ? resized_frame.planes[0].data : resized_frame.data; + const int resized_stride = resized_frame.planes[0].stride > 0 + ? resized_frame.planes[0].stride + : (resized_frame.stride > 0 ? resized_frame.stride : static_cast(input_row)); + if (resized_data && resized_stride > 0) { + for (int y = 0; y < model_input_h_; ++y) { + memcpy(resized_input_.data() + static_cast(y) * input_row, + resized_data + static_cast(y) * static_cast(resized_stride), + input_row); + } + } else { + ResizeRgbBilinear(src, w, h, src_stride, + resized_input_.data(), model_input_w_, model_input_h_, + static_cast(input_row)); + } + } else { + ResizeRgbBilinear(src, w, h, src_stride, + resized_input_.data(), model_input_w_, model_input_h_, + static_cast(input_row)); + } } else { ResizeRgbBilinear(src, w, h, src_stride, resized_input_.data(), model_input_w_, model_input_h_, static_cast(input_row)); } - if (frame->DmaFd() >= 0) frame->SyncEnd(); input.data = resized_input_.data(); input.size = input_size; input.width = model_input_w_; @@ -1252,6 +1290,7 @@ private: std::shared_ptr> input_queue_; std::vector>> output_queues_; + std::shared_ptr image_processor_; std::shared_ptr infer_backend_; uint64_t processed_ = 0; diff --git a/src/graph_manager.cpp b/src/graph_manager.cpp index 6b81ef6..0de6f06 100644 --- a/src/graph_manager.cpp +++ b/src/graph_manager.cpp @@ -495,7 +495,7 @@ bool Graph::Build(const SimpleJson& graph_cfg, PluginLoader& loader, size_t defa entry.enabled = node_val.ValueOr("enable", true); entry.metrics = std::make_shared(); entry.context.infer_backend = infer_backend_; - if (entry.type == "preprocess" || entry.type == "ai_shoe_det") { + if (entry.type == "preprocess" || entry.type == "ai_shoe_det" || entry.type == "ai_yolo") { entry.context.image_processor = HwFactory::CreateImageProcessor(entry.config); }