Commit d72c8f44 authored by xin.wang.waytous's avatar xin.wang.waytous

unique-unit-map-for-model

parent 8da6ff45
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
name: CameraModel name: CameraModel
inputNames: [cvVisImage, cvThermalImage] inputNames: [cvVisImage, cvThermalImage]
# outputNames: [fusionedDetections] # outputNames: [fusionedDetections]
outputNames: [trackedDetections] outputNames: [trackedDetections, undistortVisImage]
units: units:
# camera rgb, using TraDes segmentor # camera rgb, using TraDes segmentor
......
...@@ -12,6 +12,15 @@ distortion_coefficients: ...@@ -12,6 +12,15 @@ distortion_coefficients:
rows: 1 rows: 1
cols: 5 cols: 5
data: [-0.308855, 0.080618, -0.000948, -0.000307, 0.000000] data: [-0.308855, 0.080618, -0.000948, -0.000307, 0.000000]
new_image_width: 1920
new_image_height: 1080
new_camera_matrix:
rows: 3
cols: 3
dt: d
data: [ 954.94556, 0. , 959.48891,
0. , 955.72757, 550.42017,
0. , 0. , 1. ]
rectification_matrix: rectification_matrix:
rows: 3 rows: 3
cols: 3 cols: 3
......
...@@ -22,12 +22,24 @@ public: ...@@ -22,12 +22,24 @@ public:
using BaseIOPtr = std::shared_ptr<BaseIO>; using BaseIOPtr = std::shared_ptr<BaseIO>;
typedef std::map<std::string, BaseIOPtr> BaseIOMap;
BaseIOMap &GlobalBaseIOMap();
BaseIOPtr GetIOPtr(std::string& ioName);
void SetIOPtr(std::string& ioName, BaseIOPtr src); class BaseIOMap{
public:
BaseIOMap() = default;
BaseIOPtr GetIOPtr(std::string& ioName);
void SetIOPtr(std::string& ioName, BaseIOPtr src);
private:
std::map<std::string, BaseIOPtr> map;
};
using BaseIOMapPtr = std::shared_ptr<BaseIOMap>;
} // namespace interfaces } // namespace interfaces
......
...@@ -36,6 +36,7 @@ public: ...@@ -36,6 +36,7 @@ public:
public: public:
std::vector<BaseUnitPtr> units_; std::vector<BaseUnitPtr> units_;
BaseIOMapPtr modelUnitMap;
std::vector<std::string> inputNames; std::vector<std::string> inputNames;
std::vector<std::string> outputNames; std::vector<std::string> outputNames;
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/blob.h" #include "base/blob.h"
#include "common/log.h" #include "common/log.h"
#include "common/register.h" #include "common/register.h"
#include "interfaces/base_io.h"
namespace waytous { namespace waytous {
namespace deepinfer { namespace deepinfer {
...@@ -22,7 +23,7 @@ public: ...@@ -22,7 +23,7 @@ public:
BaseUnit() = default; BaseUnit() = default;
virtual ~BaseUnit() = default; virtual ~BaseUnit() = default;
virtual bool Init(YAML::Node& node); virtual bool Init(YAML::Node& node, BaseIOMapPtr pmap);
virtual bool Exec() = 0; virtual bool Exec() = 0;
...@@ -33,6 +34,7 @@ public: ...@@ -33,6 +34,7 @@ public:
public: public:
std::vector<std::string> inputNames; std::vector<std::string> inputNames;
std::vector<std::string> outputNames; std::vector<std::string> outputNames;
BaseIOMapPtr pMap;
}; };
using BaseUnitPtr = std::shared_ptr<BaseUnit>; using BaseUnitPtr = std::shared_ptr<BaseUnit>;
......
...@@ -128,7 +128,7 @@ int main(int argc, char** argv){ ...@@ -128,7 +128,7 @@ int main(int argc, char** argv){
./main TaskBSW image ../configs/tasks/bsw/bsw.yaml ../test/bsw.jpg ../test/bsw_res.jpg ./main TaskBSW image ../configs/tasks/bsw/bsw.yaml ../test/bsw.jpg ../test/bsw_res.jpg
./main TaskMulti image ../configs/tasks/multi/multi_task.yaml ../test/bsw.jpg ../test/multi_res.jpg ./main TaskMulti image ../configs/tasks/multi/multi_task.yaml ../test/multi_test.jpg ../test/multi_res.jpg
*/ */
......
...@@ -6,25 +6,23 @@ namespace deepinfer { ...@@ -6,25 +6,23 @@ namespace deepinfer {
namespace interfaces { namespace interfaces {
// cudafree global variable -> cuda_error 29 // cudafree global variable -> cuda_error 29
BaseIOMap &GlobalBaseIOMap(){ // BaseIOMap &GlobalBaseIOMap(){
static BaseIOMap GlobalIOMap; // static BaseIOMap GlobalIOMap;
return GlobalIOMap; // return GlobalIOMap;
} // }
BaseIOPtr GetIOPtr(std::string& ioName){ BaseIOPtr BaseIOMap::GetIOPtr(std::string& ioName){
auto& gmap = GlobalBaseIOMap(); auto iter = map.find(ioName);
auto iter = gmap.find(ioName); if (iter == map.end()) {
if (iter == gmap.end()) {
return nullptr; return nullptr;
} }
return iter->second; return iter->second;
} }
void SetIOPtr(std::string& ioName, BaseIOPtr src){ void BaseIOMap::SetIOPtr(std::string& ioName, BaseIOPtr src){
auto& gmap = GlobalBaseIOMap(); map[ioName] = src;
gmap[ioName] = src;
} }
......
...@@ -4,9 +4,10 @@ namespace waytous { ...@@ -4,9 +4,10 @@ namespace waytous {
namespace deepinfer { namespace deepinfer {
namespace interfaces { namespace interfaces {
bool BaseUnit::Init(YAML::Node& node){ bool BaseUnit::Init(YAML::Node& node, BaseIOMapPtr pmap){
inputNames = node["inputNames"].as<std::vector<std::string>>(); inputNames = node["inputNames"].as<std::vector<std::string>>();
outputNames = node["outputNames"].as<std::vector<std::string>>(); outputNames = node["outputNames"].as<std::vector<std::string>>();
pMap = pmap;
return true; return true;
}; };
......
...@@ -5,8 +5,8 @@ namespace deepinfer { ...@@ -5,8 +5,8 @@ namespace deepinfer {
namespace fusioner { namespace fusioner {
bool BayesianFusioner::Init(YAML::Node& node) { bool BayesianFusioner::Init(YAML::Node& node, interfaces::BaseIOMapPtr pmap) {
if(!BaseUnit::Init(node)){ if(!BaseUnit::Init(node, pmap)){
LOG_WARN << "Init BayesianFusioner error"; LOG_WARN << "Init BayesianFusioner error";
return false; return false;
}; };
...@@ -26,7 +26,7 @@ bool BayesianFusioner::Exec(){ ...@@ -26,7 +26,7 @@ bool BayesianFusioner::Exec(){
std::vector<ios::Det2DPtr> all_objects; std::vector<ios::Det2DPtr> all_objects;
for(int i=0; i<inputNames.size(); i++){ for(int i=0; i<inputNames.size(); i++){
auto inputName = inputNames[i]; auto inputName = inputNames[i];
auto ptr = std::dynamic_pointer_cast<ios::Detection2Ds>(interfaces::GetIOPtr(inputName)); auto ptr = std::dynamic_pointer_cast<ios::Detection2Ds>(pMap->GetIOPtr(inputName));
if (ptr == nullptr){ if (ptr == nullptr){
LOG_ERROR << "BayesianFusioner input " << inputName << " haven't been init or doesn't exist."; LOG_ERROR << "BayesianFusioner input " << inputName << " haven't been init or doesn't exist.";
return false; return false;
...@@ -47,7 +47,7 @@ bool BayesianFusioner::Exec(){ ...@@ -47,7 +47,7 @@ bool BayesianFusioner::Exec(){
); );
auto fusioned_objects = std::make_shared<ios::Detection2Ds>(); auto fusioned_objects = std::make_shared<ios::Detection2Ds>();
interfaces::SetIOPtr(outputNames[0], fusioned_objects); pMap->SetIOPtr(outputNames[0], fusioned_objects);
for(size_t i=0; i < indices.size(); i++){ for(size_t i=0; i < indices.size(); i++){
if(!deleted[indices[i]]){ if(!deleted[indices[i]]){
std::vector<ios::Det2DPtr> matched_objs; std::vector<ios::Det2DPtr> matched_objs;
......
...@@ -31,7 +31,7 @@ public: ...@@ -31,7 +31,7 @@ public:
{"IOA", BayesianFusionMatchMethod::IOA} {"IOA", BayesianFusionMatchMethod::IOA}
}; };
bool Init(YAML::Node& node) override; bool Init(YAML::Node& node, interfaces::BaseIOMapPtr pmap) override;
bool Exec() override; bool Exec() override;
......
...@@ -28,8 +28,8 @@ TRTInference::~TRTInference(){ ...@@ -28,8 +28,8 @@ TRTInference::~TRTInference(){
} }
bool TRTInference::Init(YAML::Node& configNode){ bool TRTInference::Init(YAML::Node& configNode, interfaces::BaseIOMapPtr pmap){
if(!BaseUnit::Init(configNode)){ if(!BaseUnit::Init(configNode, pmap)){
LOG_WARN << "Init trt engine error"; LOG_WARN << "Init trt engine error";
return false; return false;
}; };
...@@ -79,7 +79,7 @@ bool TRTInference::Init(YAML::Node& configNode){ ...@@ -79,7 +79,7 @@ bool TRTInference::Init(YAML::Node& configNode){
} }
for (auto inputName: inputNames){ for (auto inputName: inputNames){
auto input = std::dynamic_pointer_cast<ios::NormalIO>(interfaces::GetIOPtr(inputName)); auto input = std::dynamic_pointer_cast<ios::NormalIO>(pMap->GetIOPtr(inputName));
if (input == nullptr){ if (input == nullptr){
LOG_ERROR << "inference engine input " << inputName << " haven't been init or doesn't exist."; LOG_ERROR << "inference engine input " << inputName << " haven't been init or doesn't exist.";
return false; return false;
...@@ -108,7 +108,7 @@ bool TRTInference::Init(YAML::Node& configNode){ ...@@ -108,7 +108,7 @@ bool TRTInference::Init(YAML::Node& configNode){
auto blob = std::make_shared<base::Blob<float>>(shape); auto blob = std::make_shared<base::Blob<float>>(shape);
blobs_.insert(std::make_pair(name, blob)); blobs_.insert(std::make_pair(name, blob));
auto output = std::make_shared<ios::NormalIO>(blob); auto output = std::make_shared<ios::NormalIO>(blob);
interfaces::SetIOPtr(name, output); pMap->SetIOPtr(name, output);
auto binding = blob->mutable_gpu_data(); auto binding = blob->mutable_gpu_data();
mBindings.emplace_back(static_cast<void*>(binding)); mBindings.emplace_back(static_cast<void*>(binding));
} }
......
...@@ -32,7 +32,7 @@ class TRTInference: public interfaces::BaseUnit { ...@@ -32,7 +32,7 @@ class TRTInference: public interfaces::BaseUnit {
public: public:
~TRTInference(); ~TRTInference();
bool Init(YAML::Node& node) override; bool Init(YAML::Node& node, interfaces::BaseIOMapPtr pmap) override;
virtual bool BuildEngine(YAML::Node& node); virtual bool BuildEngine(YAML::Node& node);
bool Exec() override; bool Exec() override;
virtual std::string Name() override; virtual std::string Name() override;
......
...@@ -5,8 +5,8 @@ namespace deepinfer { ...@@ -5,8 +5,8 @@ namespace deepinfer {
namespace postprocess { namespace postprocess {
bool HomoProject::Init(YAML::Node& node) { bool HomoProject::Init(YAML::Node& node, interfaces::BaseIOMapPtr pmap) {
if(!BaseUnit::Init(node)){ if(!BaseUnit::Init(node, pmap)){
LOG_WARN << "Init homo project error"; LOG_WARN << "Init homo project error";
return false; return false;
}; };
...@@ -34,7 +34,7 @@ bool HomoProject::Init(YAML::Node& node) { ...@@ -34,7 +34,7 @@ bool HomoProject::Init(YAML::Node& node) {
bool HomoProject::Exec(){ bool HomoProject::Exec(){
auto ptr = std::dynamic_pointer_cast<ios::Detection2Ds>(interfaces::GetIOPtr(inputNames[0])); auto ptr = std::dynamic_pointer_cast<ios::Detection2Ds>(pMap->GetIOPtr(inputNames[0]));
if (ptr == nullptr){ if (ptr == nullptr){
LOG_ERROR << "HomoProject input " << inputNames[0] << " haven't been init or doesn't exist."; LOG_ERROR << "HomoProject input " << inputNames[0] << " haven't been init or doesn't exist.";
return false; return false;
...@@ -68,7 +68,7 @@ bool HomoProject::Exec(){ ...@@ -68,7 +68,7 @@ bool HomoProject::Exec(){
projected_dets->detections.push_back(projected_obj); projected_dets->detections.push_back(projected_obj);
} }
interfaces::SetIOPtr(outputNames[0], projected_dets); pMap->SetIOPtr(outputNames[0], projected_dets);
return true; return true;
} }
......
...@@ -17,7 +17,7 @@ namespace postprocess { ...@@ -17,7 +17,7 @@ namespace postprocess {
class HomoProject: public interfaces::BaseUnit{ class HomoProject: public interfaces::BaseUnit{
public: public:
bool Init(YAML::Node& node) override; bool Init(YAML::Node& node, interfaces::BaseIOMapPtr pmap) override;
bool Exec() override; bool Exec() override;
......
...@@ -5,8 +5,8 @@ namespace deepinfer { ...@@ -5,8 +5,8 @@ namespace deepinfer {
namespace postprocess { namespace postprocess {
bool MobileFaceNetPostProcess::Init(YAML::Node& node) { bool MobileFaceNetPostProcess::Init(YAML::Node& node, interfaces::BaseIOMapPtr pmap) {
if(!BaseUnit::Init(node)){ if(!BaseUnit::Init(node, pmap)){
LOG_WARN << "Init mobilefacenet postprocess error"; LOG_WARN << "Init mobilefacenet postprocess error";
return false; return false;
}; };
...@@ -24,7 +24,7 @@ bool MobileFaceNetPostProcess::Exec(){ ...@@ -24,7 +24,7 @@ bool MobileFaceNetPostProcess::Exec(){
return false; return false;
} }
auto input = std::dynamic_pointer_cast<ios::NormalIO>(interfaces::GetIOPtr(inputNames[0])); auto input = std::dynamic_pointer_cast<ios::NormalIO>(pMap->GetIOPtr(inputNames[0]));
if (input == nullptr){ if (input == nullptr){
LOG_ERROR << "mobilefacenet postprocess input " << inputNames[0] << " haven't been init or doesn't exist."; LOG_ERROR << "mobilefacenet postprocess input " << inputNames[0] << " haven't been init or doesn't exist.";
return false; return false;
...@@ -33,7 +33,7 @@ bool MobileFaceNetPostProcess::Exec(){ ...@@ -33,7 +33,7 @@ bool MobileFaceNetPostProcess::Exec(){
std::vector<base::Image8UPtr> inputImages; std::vector<base::Image8UPtr> inputImages;
for(int j=1; j<inputNames.size(); j++){ for(int j=1; j<inputNames.size(); j++){
auto iName = inputNames[j]; auto iName = inputNames[j];
auto iptr = std::dynamic_pointer_cast<ios::CameraSrcOut>(interfaces::GetIOPtr(iName)); auto iptr = std::dynamic_pointer_cast<ios::CameraSrcOut>(pMap->GetIOPtr(iName));
if (iptr == nullptr){ if (iptr == nullptr){
LOG_ERROR << "mobilefacenet postprocess input " << iName << " haven't been init or doesn't exist."; LOG_ERROR << "mobilefacenet postprocess input " << iName << " haven't been init or doesn't exist.";
return false; return false;
...@@ -58,7 +58,7 @@ bool MobileFaceNetPostProcess::Exec(){ ...@@ -58,7 +58,7 @@ bool MobileFaceNetPostProcess::Exec(){
lptr->y = points[l * 2 + 1] * inputHeight / scaley; lptr->y = points[l * 2 + 1] * inputHeight / scaley;
face_landmarks->landmarks.push_back(lptr); face_landmarks->landmarks.push_back(lptr);
} }
interfaces::SetIOPtr(outputNames[b], face_landmarks); pMap->SetIOPtr(outputNames[b], face_landmarks);
} }
return true; return true;
......
...@@ -17,7 +17,7 @@ namespace postprocess { ...@@ -17,7 +17,7 @@ namespace postprocess {
class MobileFaceNetPostProcess: public interfaces::BaseUnit{ class MobileFaceNetPostProcess: public interfaces::BaseUnit{
public: public:
bool Init(YAML::Node& node) override; bool Init(YAML::Node& node, interfaces::BaseIOMapPtr pmap) override;
bool Exec() override; bool Exec() override;
......
...@@ -5,8 +5,8 @@ namespace deepinfer { ...@@ -5,8 +5,8 @@ namespace deepinfer {
namespace postprocess { namespace postprocess {
bool MultiPostProcess::Init(YAML::Node& node) { bool MultiPostProcess::Init(YAML::Node& node, interfaces::BaseIOMapPtr pmap) {
if(!BaseUnit::Init(node)){ if(!BaseUnit::Init(node, pmap)){
LOG_WARN << "Init multitask postprocess error"; LOG_WARN << "Init multitask postprocess error";
return false; return false;
}; };
...@@ -44,27 +44,27 @@ bool MultiPostProcess::Init(YAML::Node& node) { ...@@ -44,27 +44,27 @@ bool MultiPostProcess::Init(YAML::Node& node) {
bool MultiPostProcess::Exec() { bool MultiPostProcess::Exec() {
auto rawDetections = std::dynamic_pointer_cast<ios::NormalIO>(interfaces::GetIOPtr(inputNames[0])); auto rawDetections = std::dynamic_pointer_cast<ios::NormalIO>(pMap->GetIOPtr(inputNames[0]));
if (rawDetections == nullptr){ if (rawDetections == nullptr){
LOG_ERROR << "multitask postprocess input " << inputNames[0] << " haven't been init or doesn't exist."; LOG_ERROR << "multitask postprocess input " << inputNames[0] << " haven't been init or doesn't exist.";
return false; return false;
} }
auto segProtos = std::dynamic_pointer_cast<ios::NormalIO>(interfaces::GetIOPtr(inputNames[1])); auto segProtos = std::dynamic_pointer_cast<ios::NormalIO>(pMap->GetIOPtr(inputNames[1]));
if (segProtos == nullptr){ if (segProtos == nullptr){
LOG_ERROR << "multitask postprocess input " << inputNames[1] << " haven't been init or doesn't exist."; LOG_ERROR << "multitask postprocess input " << inputNames[1] << " haven't been init or doesn't exist.";
return false; return false;
} }
auto rawDepths = std::dynamic_pointer_cast<ios::NormalIO>(interfaces::GetIOPtr(inputNames[2])); auto rawDepths = std::dynamic_pointer_cast<ios::NormalIO>(pMap->GetIOPtr(inputNames[2]));
if (rawDepths == nullptr){ if (rawDepths == nullptr){
LOG_ERROR << "multitask postprocess input " << inputNames[2] << " haven't been init or doesn't exist."; LOG_ERROR << "multitask postprocess input " << inputNames[2] << " haven't been init or doesn't exist.";
return false; return false;
} }
auto rawSemantics = std::dynamic_pointer_cast<ios::NormalIO>(interfaces::GetIOPtr(inputNames[3])); auto rawSemantics = std::dynamic_pointer_cast<ios::NormalIO>(pMap->GetIOPtr(inputNames[3]));
if (rawSemantics == nullptr){ if (rawSemantics == nullptr){
LOG_ERROR << "multitask postprocess input " << inputNames[3] << " haven't been init or doesn't exist."; LOG_ERROR << "multitask postprocess input " << inputNames[3] << " haven't been init or doesn't exist.";
return false; return false;
} }
auto inputImage = std::dynamic_pointer_cast<ios::CameraSrcOut>(interfaces::GetIOPtr(inputNames[4])); auto inputImage = std::dynamic_pointer_cast<ios::CameraSrcOut>(pMap->GetIOPtr(inputNames[4]));
if (inputImage == nullptr){ if (inputImage == nullptr){
LOG_ERROR << "multitask postprocess input " << inputNames[4] << " haven't been init or doesn't exist."; LOG_ERROR << "multitask postprocess input " << inputNames[4] << " haven't been init or doesn't exist.";
return false; return false;
...@@ -168,7 +168,7 @@ bool MultiPostProcess::Exec() { ...@@ -168,7 +168,7 @@ bool MultiPostProcess::Exec() {
); );
// LOG_INFO << x1 << " " << x2 << " " << y1 << " " << y2 <<", " << det->mask_ptr->rle_string; // LOG_INFO << x1 << " " << x2 << " " << y1 << " " << y2 <<", " << det->mask_ptr->rle_string;
} }
interfaces::SetIOPtr(outputNames[0], dets); pMap->SetIOPtr(outputNames[0], dets);
// Semantic Mask // Semantic Mask
auto semantics = std::make_shared<ios::Semantics>(); auto semantics = std::make_shared<ios::Semantics>();
...@@ -200,7 +200,7 @@ bool MultiPostProcess::Exec() { ...@@ -200,7 +200,7 @@ bool MultiPostProcess::Exec() {
// LOG_INFO << seg->mask_ptr->rle_string; // LOG_INFO << seg->mask_ptr->rle_string;
semantics->semantic_segs.push_back(seg); semantics->semantic_segs.push_back(seg);
} }
interfaces::SetIOPtr(outputNames[1], semantics); pMap->SetIOPtr(outputNames[1], semantics);
// Depth // Depth
auto depth = std::make_shared<ios::Depth>(); auto depth = std::make_shared<ios::Depth>();
...@@ -223,7 +223,7 @@ bool MultiPostProcess::Exec() { ...@@ -223,7 +223,7 @@ bool MultiPostProcess::Exec() {
// cv::resize(mask_mat, mask_res, cv::Size(img_width, img_height)); // cv::resize(mask_mat, mask_res, cv::Size(img_width, img_height));
// } // }
depth->depth = mask_mat; depth->depth = mask_mat;
interfaces::SetIOPtr(outputNames[2], depth); pMap->SetIOPtr(outputNames[2], depth);
return true; return true;
......
...@@ -21,7 +21,7 @@ namespace postprocess { ...@@ -21,7 +21,7 @@ namespace postprocess {
class MultiPostProcess: public interfaces::BaseUnit{ class MultiPostProcess: public interfaces::BaseUnit{
public: public:
bool Init(YAML::Node& node) override; bool Init(YAML::Node& node, interfaces::BaseIOMapPtr pmap) override;
bool Exec() override; bool Exec() override;
......
...@@ -5,8 +5,8 @@ namespace deepinfer { ...@@ -5,8 +5,8 @@ namespace deepinfer {
namespace postprocess { namespace postprocess {
bool TraDesPostProcess::Init(YAML::Node& node) { bool TraDesPostProcess::Init(YAML::Node& node, interfaces::BaseIOMapPtr pmap) {
if(!BaseUnit::Init(node)){ if(!BaseUnit::Init(node, pmap)){
LOG_WARN << "Init trades postprocess error"; LOG_WARN << "Init trades postprocess error";
return false; return false;
}; };
...@@ -45,7 +45,7 @@ bool TraDesPostProcess::Exec() { ...@@ -45,7 +45,7 @@ bool TraDesPostProcess::Exec() {
std::vector<base::BlobPtr<float>> inputs; std::vector<base::BlobPtr<float>> inputs;
for(int i=0; i<5; i++){ for(int i=0; i<5; i++){
auto iName = inputNames[i]; auto iName = inputNames[i];
auto p = std::dynamic_pointer_cast<ios::NormalIO>(interfaces::GetIOPtr(iName)); auto p = std::dynamic_pointer_cast<ios::NormalIO>(pMap->GetIOPtr(iName));
if (p == nullptr){ if (p == nullptr){
LOG_ERROR << "TraDeS postprocess input " << iName << " haven't been init or doesn't exist."; LOG_ERROR << "TraDeS postprocess input " << iName << " haven't been init or doesn't exist.";
return false; return false;
...@@ -56,7 +56,7 @@ bool TraDesPostProcess::Exec() { ...@@ -56,7 +56,7 @@ bool TraDesPostProcess::Exec() {
std::vector<base::Image8UPtr> inputImages; std::vector<base::Image8UPtr> inputImages;
for(int j=5; j<inputNames.size(); j++){ for(int j=5; j<inputNames.size(); j++){
auto iName = inputNames[j]; auto iName = inputNames[j];
auto iptr = std::dynamic_pointer_cast<ios::CameraSrcOut>(interfaces::GetIOPtr(iName)); auto iptr = std::dynamic_pointer_cast<ios::CameraSrcOut>(pMap->GetIOPtr(iName));
if (iptr == nullptr){ if (iptr == nullptr){
LOG_ERROR << "TraDeS postprocess input image " << iName << " haven't been init or doesn't exist."; LOG_ERROR << "TraDeS postprocess input image " << iName << " haven't been init or doesn't exist.";
return false; return false;
...@@ -123,7 +123,7 @@ bool TraDesPostProcess::Exec() { ...@@ -123,7 +123,7 @@ bool TraDesPostProcess::Exec() {
)); ));
dets->detections.push_back(obj); dets->detections.push_back(obj);
} }
interfaces::SetIOPtr(outName, dets); pMap->SetIOPtr(outName, dets);
} }
return true; return true;
......
...@@ -18,7 +18,7 @@ namespace postprocess { ...@@ -18,7 +18,7 @@ namespace postprocess {
class TraDesPostProcess: public interfaces::BaseUnit{ class TraDesPostProcess: public interfaces::BaseUnit{
public: public:
bool Init(YAML::Node& node) override; bool Init(YAML::Node& node, interfaces::BaseIOMapPtr pmap) override;
bool Exec() override; bool Exec() override;
......
...@@ -5,8 +5,8 @@ namespace deepinfer { ...@@ -5,8 +5,8 @@ namespace deepinfer {
namespace postprocess { namespace postprocess {
bool WHENetPostProcess::Init(YAML::Node& node) { bool WHENetPostProcess::Init(YAML::Node& node, interfaces::BaseIOMapPtr pmap) {
if(!BaseUnit::Init(node)){ if(!BaseUnit::Init(node, pmap)){
LOG_WARN << "Init WHENet postprocess error"; LOG_WARN << "Init WHENet postprocess error";
return false; return false;
}; };
...@@ -21,7 +21,7 @@ bool WHENetPostProcess::Exec(){ ...@@ -21,7 +21,7 @@ bool WHENetPostProcess::Exec(){
std::vector<base::BlobPtr<float>> inputs; // model outputs std::vector<base::BlobPtr<float>> inputs; // model outputs
for(int i=0; i<inputNames.size(); i++){ for(int i=0; i<inputNames.size(); i++){
auto inputName = inputNames[i]; auto inputName = inputNames[i];
auto ptr = std::dynamic_pointer_cast<ios::NormalIO>(interfaces::GetIOPtr(inputName)); auto ptr = std::dynamic_pointer_cast<ios::NormalIO>(pMap->GetIOPtr(inputName));
if (ptr == nullptr){ if (ptr == nullptr){
LOG_ERROR << "WHENet postprocess input " << inputName << " haven't been init or doesn't exist."; LOG_ERROR << "WHENet postprocess input " << inputName << " haven't been init or doesn't exist.";
return false; return false;
...@@ -36,7 +36,7 @@ bool WHENetPostProcess::Exec(){ ...@@ -36,7 +36,7 @@ bool WHENetPostProcess::Exec(){
for(int b=0; b<outputNames.size(); b++){ for(int b=0; b<outputNames.size(); b++){
auto headpose = std::make_shared<ios::HeadPose>(); auto headpose = std::make_shared<ios::HeadPose>();
interfaces::SetIOPtr(outputNames[b], headpose); pMap->SetIOPtr(outputNames[b], headpose);
float yawSum = 0, pitchSum=0, rollSum = 0; float yawSum = 0, pitchSum=0, rollSum = 0;
// yaw // yaw
......
...@@ -17,7 +17,7 @@ namespace postprocess { ...@@ -17,7 +17,7 @@ namespace postprocess {
class WHENetPostProcess: public interfaces::BaseUnit{ class WHENetPostProcess: public interfaces::BaseUnit{
public: public:
bool Init(YAML::Node& node) override; bool Init(YAML::Node& node, interfaces::BaseIOMapPtr pmap) override;
bool Exec() override; bool Exec() override;
......
...@@ -5,8 +5,8 @@ namespace deepinfer { ...@@ -5,8 +5,8 @@ namespace deepinfer {
namespace postprocess { namespace postprocess {
bool YoloV5PostProcess::Init(YAML::Node& node) { bool YoloV5PostProcess::Init(YAML::Node& node, interfaces::BaseIOMapPtr pmap) {
if(!BaseUnit::Init(node)){ if(!BaseUnit::Init(node, pmap)){
LOG_WARN << "Init yolov5 postprocess error"; LOG_WARN << "Init yolov5 postprocess error";
return false; return false;
}; };
...@@ -29,7 +29,7 @@ bool YoloV5PostProcess::Exec(){ ...@@ -29,7 +29,7 @@ bool YoloV5PostProcess::Exec(){
std::vector<base::BlobPtr<float>> inputs; // model outputs std::vector<base::BlobPtr<float>> inputs; // model outputs
for(int i=0; i<4; i++){ for(int i=0; i<4; i++){
auto inputName = inputNames[i]; auto inputName = inputNames[i];
auto ptr = std::dynamic_pointer_cast<ios::NormalIO>(interfaces::GetIOPtr(inputName)); auto ptr = std::dynamic_pointer_cast<ios::NormalIO>(pMap->GetIOPtr(inputName));
if (ptr == nullptr){ if (ptr == nullptr){
LOG_ERROR << "YoloV5 postprocess input " << inputName << " haven't been init or doesn't exist."; LOG_ERROR << "YoloV5 postprocess input " << inputName << " haven't been init or doesn't exist.";
return false; return false;
...@@ -40,7 +40,7 @@ bool YoloV5PostProcess::Exec(){ ...@@ -40,7 +40,7 @@ bool YoloV5PostProcess::Exec(){
std::vector<base::Image8UPtr> inputImages; std::vector<base::Image8UPtr> inputImages;
for(int j=4; j<inputNames.size(); j++){ for(int j=4; j<inputNames.size(); j++){
auto iName = inputNames[j]; auto iName = inputNames[j];
auto iptr = std::dynamic_pointer_cast<ios::CameraSrcOut>(interfaces::GetIOPtr(iName)); auto iptr = std::dynamic_pointer_cast<ios::CameraSrcOut>(pMap->GetIOPtr(iName));
if (iptr == nullptr){ if (iptr == nullptr){
LOG_ERROR << "YoloV5 postprocess input " << iName << " haven't been init or doesn't exist."; LOG_ERROR << "YoloV5 postprocess input " << iName << " haven't been init or doesn't exist.";
return false; return false;
...@@ -86,7 +86,7 @@ bool YoloV5PostProcess::Exec(){ ...@@ -86,7 +86,7 @@ bool YoloV5PostProcess::Exec(){
} }
dets->detections.push_back(obj); dets->detections.push_back(obj);
} }
interfaces::SetIOPtr(outName, dets); pMap->SetIOPtr(outName, dets);
} }
return true; return true;
} }
......
...@@ -17,7 +17,7 @@ namespace postprocess { ...@@ -17,7 +17,7 @@ namespace postprocess {
class YoloV5PostProcess: public interfaces::BaseUnit{ class YoloV5PostProcess: public interfaces::BaseUnit{
public: public:
bool Init(YAML::Node& node) override; bool Init(YAML::Node& node, interfaces::BaseIOMapPtr pmap) override;
bool Exec() override; bool Exec() override;
......
...@@ -6,9 +6,9 @@ namespace deepinfer { ...@@ -6,9 +6,9 @@ namespace deepinfer {
namespace preprocess { namespace preprocess {
bool ResizeNorm::Init(YAML::Node& node){ bool ResizeNorm::Init(YAML::Node& node, interfaces::BaseIOMapPtr pmap){
// CUDA_CHECK(cudaStreamCreate(&stream_)); // CUDA_CHECK(cudaStreamCreate(&stream_));
if(!BaseUnit::Init(node)){ if(!BaseUnit::Init(node, pmap)){
LOG_WARN << "Init resize_norm error"; LOG_WARN << "Init resize_norm error";
return false; return false;
}; };
...@@ -28,7 +28,7 @@ bool ResizeNorm::Init(YAML::Node& node){ ...@@ -28,7 +28,7 @@ bool ResizeNorm::Init(YAML::Node& node){
dst.reset(new base::Blob<float>({inferBatchSize, 3, inputHeight, inputWidth})); dst.reset(new base::Blob<float>({inferBatchSize, 3, inputHeight, inputWidth}));
auto dst_ptr = std::make_shared<ios::NormalIO>(dst); auto dst_ptr = std::make_shared<ios::NormalIO>(dst);
interfaces::SetIOPtr(outputNames[0], dst_ptr); pMap->SetIOPtr(outputNames[0], dst_ptr);
mean.reset(new base::Blob<float>({3, 1}, inputMean.data())); mean.reset(new base::Blob<float>({3, 1}, inputMean.data()));
mean->mutable_gpu_data(); mean->mutable_gpu_data();
...@@ -41,7 +41,7 @@ bool ResizeNorm::Init(YAML::Node& node){ ...@@ -41,7 +41,7 @@ bool ResizeNorm::Init(YAML::Node& node){
bool ResizeNorm::Exec(){ bool ResizeNorm::Exec(){
for(int b=0; b < inputNames.size(); b++){ for(int b=0; b < inputNames.size(); b++){
auto inputName = inputNames[b]; auto inputName = inputNames[b];
auto input = std::dynamic_pointer_cast<ios::CameraSrcOut>(interfaces::GetIOPtr(inputName)); auto input = std::dynamic_pointer_cast<ios::CameraSrcOut>(pMap->GetIOPtr(inputName));
if(input == nullptr){ if(input == nullptr){
LOG_ERROR << "resize norm input" << inputName << " haven't init"; LOG_ERROR << "resize norm input" << inputName << " haven't init";
return false; return false;
......
...@@ -18,7 +18,7 @@ namespace preprocess { ...@@ -18,7 +18,7 @@ namespace preprocess {
class ResizeNorm: public interfaces::BaseUnit{ class ResizeNorm: public interfaces::BaseUnit{
public: public:
bool Init(YAML::Node& node) override; bool Init(YAML::Node& node, interfaces::BaseIOMapPtr pmap) override;
bool Exec() override; bool Exec() override;
......
...@@ -5,8 +5,8 @@ namespace deepinfer { ...@@ -5,8 +5,8 @@ namespace deepinfer {
namespace preprocess { namespace preprocess {
bool Undistort::Init(YAML::Node& node) { bool Undistort::Init(YAML::Node& node, interfaces::BaseIOMapPtr pmap) {
if(!BaseUnit::Init(node)){ if(!BaseUnit::Init(node, pmap)){
LOG_WARN << "Init trades postprocess error"; LOG_WARN << "Init trades postprocess error";
return false; return false;
}; };
...@@ -34,7 +34,7 @@ bool Undistort::Init(YAML::Node& node) { ...@@ -34,7 +34,7 @@ bool Undistort::Init(YAML::Node& node) {
dst_img = std::make_shared<base::Image8U>(dst_height_, dst_width_, base::Color::BGR); dst_img = std::make_shared<base::Image8U>(dst_height_, dst_width_, base::Color::BGR);
auto output = std::make_shared<ios::CameraSrcOut>(dst_img); auto output = std::make_shared<ios::CameraSrcOut>(dst_img);
interfaces::SetIOPtr(outputNames[0], output); pMap->SetIOPtr(outputNames[0], output);
inited_ = true; inited_ = true;
return true; return true;
} }
...@@ -162,7 +162,7 @@ void Undistort::InitUndistortRectifyMap( ...@@ -162,7 +162,7 @@ void Undistort::InitUndistortRectifyMap(
bool Undistort::Exec(){ bool Undistort::Exec(){
auto iptr = std::dynamic_pointer_cast<ios::CameraSrcOut>(interfaces::GetIOPtr(inputNames[0])); auto iptr = std::dynamic_pointer_cast<ios::CameraSrcOut>(pMap->GetIOPtr(inputNames[0]));
if (iptr == nullptr){ if (iptr == nullptr){
LOG_ERROR << "Undistort input " << inputNames[0] << " haven't been init or doesn't exist."; LOG_ERROR << "Undistort input " << inputNames[0] << " haven't been init or doesn't exist.";
return false; return false;
......
...@@ -22,7 +22,7 @@ namespace preprocess { ...@@ -22,7 +22,7 @@ namespace preprocess {
class Undistort: public interfaces::BaseUnit{ class Undistort: public interfaces::BaseUnit{
public: public:
bool Init(YAML::Node& node) override; bool Init(YAML::Node& node, interfaces::BaseIOMapPtr pmap) override;
bool Exec() override; bool Exec() override;
......
...@@ -8,7 +8,7 @@ namespace sources { ...@@ -8,7 +8,7 @@ namespace sources {
bool CameraSrc::Exec(){ bool CameraSrc::Exec(){
auto src_input = interfaces::GetIOPtr(inputNames[0]); auto src_input = pMap->GetIOPtr(inputNames[0]);
if(src_input == nullptr){ if(src_input == nullptr){
LOG_ERROR << "CameraSrc input" << inputNames[0] << " haven't init"; LOG_ERROR << "CameraSrc input" << inputNames[0] << " haven't init";
return false; return false;
...@@ -16,7 +16,7 @@ bool CameraSrc::Exec(){ ...@@ -16,7 +16,7 @@ bool CameraSrc::Exec(){
auto src = std::dynamic_pointer_cast<ios::CameraSrcIn>(src_input); auto src = std::dynamic_pointer_cast<ios::CameraSrcIn>(src_input);
auto img = std::make_shared<base::Image8U>(src->cv_img_); auto img = std::make_shared<base::Image8U>(src->cv_img_);
auto dst = std::make_shared<ios::CameraSrcOut>(img); auto dst = std::make_shared<ios::CameraSrcOut>(img);
interfaces::SetIOPtr(outputNames[0], dst); pMap->SetIOPtr(outputNames[0], dst);
return true; return true;
} }
......
...@@ -7,9 +7,9 @@ namespace tracker{ ...@@ -7,9 +7,9 @@ namespace tracker{
bool ByteTracker::Init(YAML::Node& node) bool ByteTracker::Init(YAML::Node& node, interfaces::BaseIOMapPtr pmap)
{ {
if(!BaseUnit::Init(node)){ if(!BaseUnit::Init(node, pmap)){
LOG_WARN << "Init ByteTracker error"; LOG_WARN << "Init ByteTracker error";
return false; return false;
}; };
...@@ -31,7 +31,7 @@ bool ByteTracker::Init(YAML::Node& node) ...@@ -31,7 +31,7 @@ bool ByteTracker::Init(YAML::Node& node)
bool ByteTracker::Exec() bool ByteTracker::Exec()
{ {
auto input = std::dynamic_pointer_cast<ios::Detection2Ds>(interfaces::GetIOPtr(inputNames[0])); auto input = std::dynamic_pointer_cast<ios::Detection2Ds>(pMap->GetIOPtr(inputNames[0]));
if(input == nullptr){ if(input == nullptr){
LOG_ERROR << "ByteTracker input " << inputNames[0] << " haven't init"; LOG_ERROR << "ByteTracker input " << inputNames[0] << " haven't init";
return false; return false;
...@@ -263,7 +263,7 @@ bool ByteTracker::Exec() ...@@ -263,7 +263,7 @@ bool ByteTracker::Exec()
} }
} }
// } // }
interfaces::SetIOPtr(outputNames[0], tracked_bboxes); pMap->SetIOPtr(outputNames[0], tracked_bboxes);
LOG_INFO << "Get " << tracked_bboxes->detections.size() << " tracked objs. Removed track length: " << this->removed_tracks.size(); LOG_INFO << "Get " << tracked_bboxes->detections.size() << " tracked objs. Removed track length: " << this->removed_tracks.size();
return true; return true;
} }
......
...@@ -18,7 +18,7 @@ class ByteTracker: public interfaces::BaseUnit ...@@ -18,7 +18,7 @@ class ByteTracker: public interfaces::BaseUnit
{ {
public: public:
bool Init(YAML::Node& node) override; bool Init(YAML::Node& node, interfaces::BaseIOMapPtr pmap) override;
bool Exec() override; bool Exec() override;
std::string Name() override; std::string Name() override;
......
...@@ -20,6 +20,8 @@ bool CameraModel::Init(std::string& configPath) { ...@@ -20,6 +20,8 @@ bool CameraModel::Init(std::string& configPath) {
inputNames = modelConfigNode["inputNames"].as<std::vector<std::string>>(); inputNames = modelConfigNode["inputNames"].as<std::vector<std::string>>();
outputNames = modelConfigNode["outputNames"].as<std::vector<std::string>>(); outputNames = modelConfigNode["outputNames"].as<std::vector<std::string>>();
modelUnitMap = std::make_shared<interfaces::BaseIOMap>();
// units // units
auto unitNodes = modelConfigNode["units"]; auto unitNodes = modelConfigNode["units"];
for(int i=0; i<unitNodes.size(); i++){ for(int i=0; i<unitNodes.size(); i++){
...@@ -28,7 +30,7 @@ bool CameraModel::Init(std::string& configPath) { ...@@ -28,7 +30,7 @@ bool CameraModel::Init(std::string& configPath) {
LOG_INFO << "Init CameraModel unit: " << unitName; LOG_INFO << "Init CameraModel unit: " << unitName;
interfaces::BaseUnitPtr unitPtr; interfaces::BaseUnitPtr unitPtr;
unitPtr.reset(interfaces::BaseUnitRegisterer::GetInstanceByName(unitName)); unitPtr.reset(interfaces::BaseUnitRegisterer::GetInstanceByName(unitName));
if(!unitPtr->Init(unitNode)){ if(!unitPtr->Init(unitNode, modelUnitMap)){
LOG_WARN << "Init CameraModel unit " << unitName << " failed!"; LOG_WARN << "Init CameraModel unit " << unitName << " failed!";
return false; return false;
}; };
...@@ -45,7 +47,7 @@ bool CameraModel::Exec(std::vector<cv::Mat*> inputs, std::vector<interfaces::Bas ...@@ -45,7 +47,7 @@ bool CameraModel::Exec(std::vector<cv::Mat*> inputs, std::vector<interfaces::Bas
auto inputName = inputNames[i]; auto inputName = inputNames[i];
LOG_INFO << "CameraModel input: " << inputName; LOG_INFO << "CameraModel input: " << inputName;
auto input = std::make_shared<ios::CameraSrcIn>(input_img); auto input = std::make_shared<ios::CameraSrcIn>(input_img);
interfaces::SetIOPtr(inputName, input); modelUnitMap->SetIOPtr(inputName, input);
} }
// infer // infer
for(auto& unit: units_){ for(auto& unit: units_){
...@@ -59,7 +61,7 @@ bool CameraModel::Exec(std::vector<cv::Mat*> inputs, std::vector<interfaces::Bas ...@@ -59,7 +61,7 @@ bool CameraModel::Exec(std::vector<cv::Mat*> inputs, std::vector<interfaces::Bas
// output // output
for(auto outName: outputNames){ for(auto outName: outputNames){
LOG_INFO << "CameraModel output: " << outName; LOG_INFO << "CameraModel output: " << outName;
outputs.push_back(interfaces::GetIOPtr(outName)); outputs.push_back(modelUnitMap->GetIOPtr(outName));
} }
return true; return true;
...@@ -72,7 +74,7 @@ bool CameraModel::Exec(std::vector<base::Image8UPtr> inputs, std::vector<interfa ...@@ -72,7 +74,7 @@ bool CameraModel::Exec(std::vector<base::Image8UPtr> inputs, std::vector<interfa
auto input_img = inputs[i]; auto input_img = inputs[i];
auto inputName = inputNames[i]; auto inputName = inputNames[i];
auto input = std::make_shared<ios::CameraSrcOut>(input_img); auto input = std::make_shared<ios::CameraSrcOut>(input_img);
interfaces::SetIOPtr(inputName, input); modelUnitMap->SetIOPtr(inputName, input);
} }
// infer // infer
...@@ -86,7 +88,7 @@ bool CameraModel::Exec(std::vector<base::Image8UPtr> inputs, std::vector<interfa ...@@ -86,7 +88,7 @@ bool CameraModel::Exec(std::vector<base::Image8UPtr> inputs, std::vector<interfa
// output // output
for(auto outName: outputNames){ for(auto outName: outputNames){
outputs.push_back(interfaces::GetIOPtr(outName)); outputs.push_back(modelUnitMap->GetIOPtr(outName));
} }
return true; return true;
} }
......
...@@ -34,9 +34,13 @@ bool TaskFusion::Exec(std::vector<cv::Mat*> inputs, std::vector<interfaces::Base ...@@ -34,9 +34,13 @@ bool TaskFusion::Exec(std::vector<cv::Mat*> inputs, std::vector<interfaces::Base
void TaskFusion::Visualize(cv::Mat* image, interfaces::BaseIOPtr outs){ void TaskFusion::Visualize(cv::Mat* image, interfaces::BaseIOPtr outs){
auto mainSrc = std::dynamic_pointer_cast<ios::CameraSrcOut>(interfaces::GetIOPtr(mainSrcName));
}
void TaskFusion::Visualize(cv::Mat* image, std::vector<interfaces::BaseIOPtr>& outputs){
auto mainSrc = std::dynamic_pointer_cast<ios::CameraSrcOut>(outputs[outputs.size()-1]);;
auto mainImage = mainSrc->img_ptr_->toCVMat(); auto mainImage = mainSrc->img_ptr_->toCVMat();
auto detections = std::dynamic_pointer_cast<ios::Detection2Ds>(outs)->detections; auto detections = std::dynamic_pointer_cast<ios::Detection2Ds>(outputs[0])->detections;
cv::Mat realInstanceMask, colorInstance; cv::Mat realInstanceMask, colorInstance;
for(auto& obj: detections){ for(auto& obj: detections){
cv::Scalar color = get_color(obj->class_label * 100 + obj->track_id); cv::Scalar color = get_color(obj->class_label * 100 + obj->track_id);
......
...@@ -21,6 +21,7 @@ public: ...@@ -21,6 +21,7 @@ public:
bool Exec(std::vector<cv::Mat*> inputs, std::vector<interfaces::BaseIOPtr>& outputs) override; bool Exec(std::vector<cv::Mat*> inputs, std::vector<interfaces::BaseIOPtr>& outputs) override;
void Visualize(cv::Mat* image, interfaces::BaseIOPtr outs) override; void Visualize(cv::Mat* image, interfaces::BaseIOPtr outs) override;
void Visualize(cv::Mat* image, std::vector<interfaces::BaseIOPtr>& outputs);
std::string Name() override; std::string Name() override;
public: public:
......
test/t_b1_res.jpg

27.8 KB | W: | H:

test/t_b1_res.jpg

27.8 KB | W: | H:

test/t_b1_res.jpg
test/t_b1_res.jpg
test/t_b1_res.jpg
test/t_b1_res.jpg
  • 2-up
  • Swipe
  • Onion skin
test/t_b2_res.jpg

27.8 KB | W: | H:

test/t_b2_res.jpg

27.8 KB | W: | H:

test/t_b2_res.jpg
test/t_b2_res.jpg
test/t_b2_res.jpg
test/t_b2_res.jpg
  • 2-up
  • Swipe
  • Onion skin
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment