|
@@ -22,71 +22,98 @@ void print_mat(const cv::Mat& mat, int max_rows = 10, int max_cols = 10)
|
|
|
if (mat.rows > max_rows) std::cout << "[...]" << std::endl;
|
|
|
}
|
|
|
|
|
|
-void InferNode::work()
|
|
|
+
|
|
|
+void InferNode::handle_data(std::shared_ptr<meta::MetaData>& meta_data)
|
|
|
{
|
|
|
- PLOGI.printf("InferNode : [%s] start", name_.c_str());
|
|
|
- if (!model_)
|
|
|
+ cv::Mat image = meta_data->image;
|
|
|
+ int width = image.cols;
|
|
|
+ int height = image.rows;
|
|
|
+
|
|
|
+ auto det_result = model_->forward(tensor::cvimg(image), image.cols, image.rows, 0.0f, 0.0f);
|
|
|
+
|
|
|
+ if (std::holds_alternative<data::BoxArray>(det_result))
|
|
|
+ {
|
|
|
+ auto result = std::get<data::BoxArray>(det_result);
|
|
|
+ for (auto& r : result)
|
|
|
+ {
|
|
|
+ meta_data->boxes.push_back(r);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if(std::holds_alternative<cv::Mat>(det_result))
|
|
|
{
|
|
|
- PLOGE.printf("InferNode : [%s] model is nullptr", name_.c_str());
|
|
|
- return;
|
|
|
+ auto depth_mat = std::get<cv::Mat>(det_result);
|
|
|
+ // print_mat(depth_mat);
|
|
|
+ meta_data->depth = depth_mat;
|
|
|
+
|
|
|
}
|
|
|
- // 不同线程都需要指定显卡id,默认为0号显卡
|
|
|
- // 在主线程中创建的模型,创建时指定了显卡id
|
|
|
- // 推理的时候创建了另一个线程,需要指定同样的显卡id
|
|
|
- checkRuntime(cudaSetDevice(device_id_));
|
|
|
- while (running_)
|
|
|
+ else
|
|
|
{
|
|
|
- // Timer timer("InferNode");
|
|
|
- bool has_data = false;
|
|
|
- for (auto& input_buffer : input_buffers_)
|
|
|
- {
|
|
|
- std::shared_ptr<meta::MetaData> metaData;
|
|
|
- if (!input_buffer.second->try_pop(metaData))
|
|
|
- {
|
|
|
- continue;
|
|
|
- }
|
|
|
- has_data = true;
|
|
|
- // printf("Node %s get data from %s\n", name_.c_str(), input_buffer.first.c_str());
|
|
|
- cv::Mat image = metaData->image;
|
|
|
- int width = image.cols;
|
|
|
- int height = image.rows;
|
|
|
+ PLOGE.printf("InferNode : [%s] Unexpected result type from model", name_.c_str());
|
|
|
+ throw std::runtime_error("Unexpected result type from model");
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
- auto det_result = model_->forward(tensor::cvimg(image), image.cols, image.rows, 0.0f, 0.0f);
|
|
|
+// void InferNode::work()
|
|
|
+// {
|
|
|
+// PLOGI.printf("InferNode : [%s] start", name_.c_str());
|
|
|
+// if (!model_)
|
|
|
+// {
|
|
|
+// PLOGE.printf("InferNode : [%s] model is nullptr", name_.c_str());
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// // 不同线程都需要指定显卡id,默认为0号显卡
|
|
|
+// // 在主线程中创建的模型,创建时指定了显卡id
|
|
|
+// // 推理的时候创建了另一个线程,需要指定同样的显卡id
|
|
|
+// checkRuntime(cudaSetDevice(device_id_));
|
|
|
+// while (running_)
|
|
|
+// {
|
|
|
+// // Timer timer("InferNode");
|
|
|
+// bool has_data = false;
|
|
|
+// for (auto& input_buffer : input_buffers_)
|
|
|
+// {
|
|
|
+// std::shared_ptr<meta::MetaData> metaData;
|
|
|
+// if (!input_buffer.second->try_pop(metaData))
|
|
|
+// {
|
|
|
+// continue;
|
|
|
+// }
|
|
|
+// has_data = true;
|
|
|
+// // printf("Node %s get data from %s\n", name_.c_str(), input_buffer.first.c_str());
|
|
|
+// cv::Mat image = metaData->image;
|
|
|
+// int width = image.cols;
|
|
|
+// int height = image.rows;
|
|
|
|
|
|
- if (std::holds_alternative<data::BoxArray>(det_result))
|
|
|
- {
|
|
|
- auto result = std::get<data::BoxArray>(det_result);
|
|
|
- for (auto& r : result)
|
|
|
- {
|
|
|
- metaData->boxes.push_back(r);
|
|
|
- }
|
|
|
- }
|
|
|
- else if(std::holds_alternative<cv::Mat>(det_result))
|
|
|
- {
|
|
|
- auto depth_mat = std::get<cv::Mat>(det_result);
|
|
|
- // print_mat(depth_mat);
|
|
|
- metaData->depth = depth_mat;
|
|
|
+// auto det_result = model_->forward(tensor::cvimg(image), image.cols, image.rows, 0.0f, 0.0f);
|
|
|
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- PLOGE.printf("InferNode : [%s] Unexpected result type from model", name_.c_str());
|
|
|
- throw std::runtime_error("Unexpected result type from model");
|
|
|
- }
|
|
|
- for (auto& output_buffer : output_buffers_)
|
|
|
- {
|
|
|
- // printf("Node %s push data to %s\n", name_.c_str(), output_buffer.first.c_str());
|
|
|
- output_buffer.second->push(metaData);
|
|
|
- }
|
|
|
- }
|
|
|
- if (!has_data)
|
|
|
- {
|
|
|
- std::unique_lock<std::mutex> lock(mutex_);
|
|
|
- cond_var_->wait_for(lock, std::chrono::milliseconds(100), [this] {
|
|
|
- return !running_; // 等待时检查退出条件
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
-};
|
|
|
+// if (std::holds_alternative<data::BoxArray>(det_result))
|
|
|
+// {
|
|
|
+// auto result = std::get<data::BoxArray>(det_result);
|
|
|
+// for (auto& r : result)
|
|
|
+// {
|
|
|
+// metaData->boxes.push_back(r);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// else if(std::holds_alternative<cv::Mat>(det_result))
|
|
|
+// {
|
|
|
+// auto depth_mat = std::get<cv::Mat>(det_result);
|
|
|
+// // print_mat(depth_mat);
|
|
|
+// metaData->depth = depth_mat;
|
|
|
+
|
|
|
+// }
|
|
|
+// else
|
|
|
+// {
|
|
|
+// PLOGE.printf("InferNode : [%s] Unexpected result type from model", name_.c_str());
|
|
|
+// throw std::runtime_error("Unexpected result type from model");
|
|
|
+// }
|
|
|
+// send_output_data(metaData);
|
|
|
+// }
|
|
|
+// if (!has_data)
|
|
|
+// {
|
|
|
+// std::unique_lock<std::mutex> lock(mutex_);
|
|
|
+// cond_var_->wait_for(lock, std::chrono::milliseconds(100), [this] {
|
|
|
+// return !running_; // 等待时检查退出条件
|
|
|
+// });
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
|
|
|
} // namespace StreamNode
|