diff --git a/configs/sample_person_shoe_two_stage.json b/configs/sample_person_shoe_two_stage.json index 0f70eea..98bc00c 100644 --- a/configs/sample_person_shoe_two_stage.json +++ b/configs/sample_person_shoe_two_stage.json @@ -74,6 +74,9 @@ "type": "ai_shoe_det", "role": "filter", "enable": true, + "use_rga": true, + "rga_gate": "person_shoe_two_stage", + "rga_max_inflight": 4, "infer_fps": 1, "model_path": "./models/shoe_detector_openimages_ppe_v1.rknn", "model_w": 640, diff --git a/configs/sample_person_shoe_two_stage_balanced.json b/configs/sample_person_shoe_two_stage_balanced.json index fbd0461..bac5023 100644 --- a/configs/sample_person_shoe_two_stage_balanced.json +++ b/configs/sample_person_shoe_two_stage_balanced.json @@ -74,6 +74,9 @@ "type": "ai_shoe_det", "role": "filter", "enable": true, + "use_rga": true, + "rga_gate": "person_shoe_two_stage_balanced", + "rga_max_inflight": 4, "infer_fps": 1, "model_path": "./models/shoe_detector_openimages_ppe_v1.rknn", "model_w": 640, diff --git a/configs/sample_person_shoe_two_stage_recall.json b/configs/sample_person_shoe_two_stage_recall.json index d753d41..bf58c30 100644 --- a/configs/sample_person_shoe_two_stage_recall.json +++ b/configs/sample_person_shoe_two_stage_recall.json @@ -74,6 +74,9 @@ "type": "ai_shoe_det", "role": "filter", "enable": true, + "use_rga": true, + "rga_gate": "person_shoe_two_stage_recall", + "rga_max_inflight": 4, "infer_fps": 2, "model_path": "./models/shoe_detector_openimages_ppe_v1.rknn", "model_w": 640, diff --git a/plugins/ai_shoe_det/ai_shoe_det_node.cpp b/plugins/ai_shoe_det/ai_shoe_det_node.cpp index 3c2064f..3d289ea 100644 --- a/plugins/ai_shoe_det/ai_shoe_det_node.cpp +++ b/plugins/ai_shoe_det/ai_shoe_det_node.cpp @@ -15,6 +15,7 @@ #include "ai_scheduler.h" #include "frame/frame.h" +#include "hw/i_image_processor.h" #include "hw/i_infer_backend.h" #include "node.h" #include "utils/logger.h" @@ -365,6 +366,7 @@ public: LogError("[ai_shoe_det] no infer backend"); return false; } + image_processor_ = ctx.image_processor; #if defined(RK3588_ENABLE_RKNN) std::string err; @@ -562,17 +564,61 @@ private: memcpy(dst_row, src_row, static_cast(win_w) * 3); } - // Resize 到模型输入尺寸 - ResizeRgbBilinear(crop_buf.data(), win_w, win_h, win_w * 3, - input_buf_.data(), model_w_, model_h_, model_w_ * 3); + const uint8_t* model_input_data = nullptr; + size_t model_input_size = 0; + if (image_processor_ && win_w > 0 && win_h > 0) { + Frame crop_frame; + crop_frame.width = win_w; + crop_frame.height = win_h; + crop_frame.format = PixelFormat::RGB; + crop_frame.stride = win_w * 3; + crop_frame.data = crop_buf.data(); + crop_frame.data_size = crop_buf.size(); + crop_frame.plane_count = 1; + crop_frame.planes[0] = {crop_buf.data(), crop_frame.stride, static_cast(crop_buf.size()), 0}; + + Frame resized_frame; + resized_frame.width = model_w_; + resized_frame.height = model_h_; + resized_frame.format = PixelFormat::RGB; + + Status st = image_processor_->Resize(crop_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 : model_w_ * 3); + const size_t packed_size = static_cast(model_w_) * static_cast(model_h_) * 3; + if (resized_data && resized_stride > 0) { + if (packed_size > input_buf_.size()) input_buf_.resize(packed_size); + if (resized_frame.DmaFd() >= 0) resized_frame.SyncStart(); + for (int row = 0; row < model_h_; ++row) { + memcpy(input_buf_.data() + static_cast(row) * static_cast(model_w_) * 3, + resized_data + static_cast(row) * static_cast(resized_stride), + static_cast(model_w_) * 3); + } + if (resized_frame.DmaFd() >= 0) resized_frame.SyncEnd(); + model_input_data = input_buf_.data(); + model_input_size = packed_size; + } + } + } + + if (!model_input_data) { + ResizeRgbBilinear(crop_buf.data(), win_w, win_h, win_w * 3, + input_buf_.data(), model_w_, model_h_, model_w_ * 3); + model_input_data = input_buf_.data(); + model_input_size = input_buf_.size(); + } + // 推理 InferInput input; input.width = model_w_; input.height = model_h_; input.is_nhwc = true; - input.data = input_buf_.data(); - input.size = input_buf_.size(); + input.data = model_input_data; + input.size = model_input_size; input.type = RKNN_TENSOR_UINT8; auto r = infer_backend_->InferBorrowed(model_handle_, input); @@ -766,6 +812,7 @@ private: std::shared_ptr> input_queue_; std::vector>> output_queues_; + std::shared_ptr image_processor_; #if defined(RK3588_ENABLE_RKNN) std::shared_ptr infer_backend_; diff --git a/src/graph_manager.cpp b/src/graph_manager.cpp index f28268a..6b81ef6 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") { + if (entry.type == "preprocess" || entry.type == "ai_shoe_det") { entry.context.image_processor = HwFactory::CreateImageProcessor(entry.config); }