Skip to content

Commit

Permalink
Removed static enum with types
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuzhny007 committed Aug 29, 2022
1 parent ab93d16 commit 05ec26c
Show file tree
Hide file tree
Showing 12 changed files with 154 additions and 231 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

# Last changes

* Breaking change: removed static enum with types

* Support ONNX with NMS

* YOLOv7 worked with TensorRT! Export pretrained Pytorch models [here (WongKinYiu/yolov7)](https://github.com/WongKinYiu/yolov7) to onnx format and run Multitarget-tracker with -e=6 example
Expand Down
14 changes: 6 additions & 8 deletions async_detector/AsyncDetector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,14 +301,12 @@ void AsyncDetector::CaptureThread(std::string fileName, int startFrame, float* f
detectorConfig.emplace("maxCropRatio", "3.0");

#if 1
detectorConfig.emplace("white_list", std::to_string((objtype_t)ObjectTypes::obj_person));
detectorConfig.emplace("white_list", std::to_string((objtype_t)ObjectTypes::obj_car));
detectorConfig.emplace("white_list", std::to_string((objtype_t)ObjectTypes::obj_bicycle));
detectorConfig.emplace("white_list", std::to_string((objtype_t)ObjectTypes::obj_motorbike));
detectorConfig.emplace("white_list", std::to_string((objtype_t)ObjectTypes::obj_bus));
detectorConfig.emplace("white_list", std::to_string((objtype_t)ObjectTypes::obj_truck));
//detectorConfig.emplace("white_list", std::to_string((objtype_t)ObjectTypes::obj_traffic light));
//detectorConfig.emplace("white_list", std::to_string((objtype_t)ObjectTypes::obj_stop sign));
detectorConfig.emplace("white_list", "person");
detectorConfig.emplace("white_list", "car");
detectorConfig.emplace("white_list", "bicycle");
detectorConfig.emplace("white_list", "motorbike");
detectorConfig.emplace("white_list", "bus");
detectorConfig.emplace("white_list", "truck");
#endif

// Tracker
Expand Down
14 changes: 7 additions & 7 deletions combined/combined.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,13 +344,13 @@ bool CombinedDetector::InitDetector(cv::UMat frame)
configDNN.emplace("classNames", pathToModel + "coco.names");
configDNN.emplace("maxCropRatio", "-1");

configDNN.emplace("white_list", std::to_string((objtype_t)ObjectTypes::obj_person));
configDNN.emplace("white_list", std::to_string((objtype_t)ObjectTypes::obj_car));
configDNN.emplace("white_list", std::to_string((objtype_t)ObjectTypes::obj_bicycle));
configDNN.emplace("white_list", std::to_string((objtype_t)ObjectTypes::obj_motorbike));
configDNN.emplace("white_list", std::to_string((objtype_t)ObjectTypes::obj_bus));
configDNN.emplace("white_list", std::to_string((objtype_t)ObjectTypes::obj_truck));
configDNN.emplace("white_list", std::to_string((objtype_t)ObjectTypes::obj_vehicle));
configDNN.emplace("white_list", "person");
configDNN.emplace("white_list", "car");
configDNN.emplace("white_list", "bicycle");
configDNN.emplace("white_list", "motorbike");
configDNN.emplace("white_list", "bus");
configDNN.emplace("white_list", "truck");
configDNN.emplace("white_list", "vehicle");

m_detectorDNN = BaseDetector::CreateDetector(tracking::Detectors::Yolo_Darknet, configDNN, frame);
if (m_detectorDNN.get())
Expand Down
22 changes: 11 additions & 11 deletions example/CarsCounting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,13 @@ bool CarsCounting::InitDetector(cv::UMat frame)
if (m_batchSize > 1)
config.emplace("maxBatch", std::to_string(m_batchSize));

config.emplace("white_list", std::to_string((objtype_t)ObjectTypes::obj_person));
config.emplace("white_list", std::to_string((objtype_t)ObjectTypes::obj_car));
config.emplace("white_list", std::to_string((objtype_t)ObjectTypes::obj_bicycle));
config.emplace("white_list", std::to_string((objtype_t)ObjectTypes::obj_motorbike));
config.emplace("white_list", std::to_string((objtype_t)ObjectTypes::obj_bus));
config.emplace("white_list", std::to_string((objtype_t)ObjectTypes::obj_truck));
config.emplace("white_list", std::to_string((objtype_t)ObjectTypes::obj_vehicle));
config.emplace("white_list", "person");
config.emplace("white_list", "car");
config.emplace("white_list", "bicycle");
config.emplace("white_list", "motorbike");
config.emplace("white_list", "bus");
config.emplace("white_list", "truck");
config.emplace("white_list", "vehicle");

m_detector = BaseDetector::CreateDetector(m_detectorType, config, frame);

Expand Down Expand Up @@ -246,10 +246,10 @@ bool CarsCounting::InitTracker(cv::UMat frame)
settings.m_minAreaRadiusPix = frame.rows / 20.f;
settings.m_maximumAllowedSkippedFrames = cvRound(2 * m_fps); // Maximum allowed skipped frames

settings.AddNearTypes(ObjectTypes::obj_car, ObjectTypes::obj_bus, false);
settings.AddNearTypes(ObjectTypes::obj_car, ObjectTypes::obj_truck, false);
settings.AddNearTypes(ObjectTypes::obj_person, ObjectTypes::obj_bicycle, true);
settings.AddNearTypes(ObjectTypes::obj_person, ObjectTypes::obj_motorbike, true);
settings.AddNearTypes(TypeConverter::Str2Type("car"), TypeConverter::Str2Type("bus"), false);
settings.AddNearTypes(TypeConverter::Str2Type("car"), TypeConverter::Str2Type("truck"), false);
settings.AddNearTypes(TypeConverter::Str2Type("person"), TypeConverter::Str2Type("bicycle"), true);
settings.AddNearTypes(TypeConverter::Str2Type("person"), TypeConverter::Str2Type("motorbike"), true);

settings.m_useAbandonedDetection = false;
if (settings.m_useAbandonedDetection)
Expand Down
46 changes: 23 additions & 23 deletions example/examples.h
Original file line number Diff line number Diff line change
Expand Up @@ -622,12 +622,12 @@ class YoloDarknetExample final : public VideoExample
config.emplace("classNames", pathToModel + "coco.names");
config.emplace("maxCropRatio", "-1");

config.emplace("white_list", std::to_string((objtype_t)ObjectTypes::obj_person));
config.emplace("white_list", std::to_string((objtype_t)ObjectTypes::obj_car));
config.emplace("white_list", std::to_string((objtype_t)ObjectTypes::obj_bicycle));
config.emplace("white_list", std::to_string((objtype_t)ObjectTypes::obj_motorbike));
config.emplace("white_list", std::to_string((objtype_t)ObjectTypes::obj_bus));
config.emplace("white_list", std::to_string((objtype_t)ObjectTypes::obj_truck));
config.emplace("white_list", "person");
config.emplace("white_list", "car");
config.emplace("white_list", "bicycle");
config.emplace("white_list", "motorbike");
config.emplace("white_list", "bus");
config.emplace("white_list", "truck");
}
else
{
Expand Down Expand Up @@ -673,14 +673,14 @@ class YoloDarknetExample final : public VideoExample
m_trackerSettings.m_embeddings.emplace_back(pathToModel + "open_model_zoo/person-reidentification-retail-0286/FP16-INT8/person-reidentification-retail-0286.xml",
pathToModel + "open_model_zoo/person-reidentification-retail-0286/FP16-INT8/person-reidentification-retail-0286.bin",
cv::Size(128, 256),
std::vector<ObjectTypes>{ ObjectTypes::obj_person });
std::vector<objtype_t>{ TypeConverter::Str2Type("person") });
#endif

#if 0
m_trackerSettings.m_embeddings.emplace_back(pathToModel + "open_model_zoo/vehicle-reid-0001/osnet_ain_x1_0_vehicle_reid.xml",
pathToModel + "open_model_zoo/vehicle-reid-0001/osnet_ain_x1_0_vehicle_reid.bin",
cv::Size(208, 208),
std::vector<ObjectTypes>{ ObjectTypes::obj_car, ObjectTypes::obj_bus, ObjectTypes::obj_truck, ObjectTypes::obj_vehicle });
std::vector<objtype_t>{ TypeConverter::Str2Type("car"), TypeConverter::Str2Type("bus"), TypeConverter::Str2Type("truck"), TypeConverter::Str2Type("vehicle") });
#endif

std::array<track_t, tracking::DistsCount> distType{
Expand Down Expand Up @@ -715,11 +715,11 @@ class YoloDarknetExample final : public VideoExample
m_trackerSettings.m_maximumAllowedSkippedFrames = cvRound(2 * m_fps); // Maximum allowed skipped frames
m_trackerSettings.m_maxTraceLength = cvRound(2 * m_fps); // Maximum trace length
}
m_trackerSettings.AddNearTypes(ObjectTypes::obj_car, ObjectTypes::obj_bus, true);
m_trackerSettings.AddNearTypes(ObjectTypes::obj_car, ObjectTypes::obj_truck, true);
m_trackerSettings.AddNearTypes(ObjectTypes::obj_bus, ObjectTypes::obj_truck, true);
m_trackerSettings.AddNearTypes(ObjectTypes::obj_person, ObjectTypes::obj_bicycle, true);
m_trackerSettings.AddNearTypes(ObjectTypes::obj_person, ObjectTypes::obj_motorbike, true);
m_trackerSettings.AddNearTypes(TypeConverter::Str2Type("car"), TypeConverter::Str2Type("bus"), true);
m_trackerSettings.AddNearTypes(TypeConverter::Str2Type("car"), TypeConverter::Str2Type("truck"), true);
m_trackerSettings.AddNearTypes(TypeConverter::Str2Type("bus"), TypeConverter::Str2Type("truck"), true);
m_trackerSettings.AddNearTypes(TypeConverter::Str2Type("person"), TypeConverter::Str2Type("bicycle"), true);
m_trackerSettings.AddNearTypes(TypeConverter::Str2Type("person"), TypeConverter::Str2Type("motorbike"), true);

m_tracker = BaseTracker::CreateTracker(m_trackerSettings);

Expand Down Expand Up @@ -920,12 +920,12 @@ class YoloTensorRTExample final : public VideoExample
config.emplace("inference_precision", m_trackerSettings.m_inferencePrecision);
}

//config.emplace("white_list", std::to_string((objtype_t)ObjectTypes::obj_person));
//config.emplace("white_list", std::to_string((objtype_t)ObjectTypes::obj_car));
//config.emplace("white_list", std::to_string((objtype_t)ObjectTypes::obj_bicycle));
//config.emplace("white_list", std::to_string((objtype_t)ObjectTypes::obj_motorbike));
//config.emplace("white_list", std::to_string((objtype_t)ObjectTypes::obj_bus));
//config.emplace("white_list", std::to_string((objtype_t)ObjectTypes::obj_truck));
//config.emplace("white_list", "person");
//config.emplace("white_list", "car");
//config.emplace("white_list", "bicycle");
//config.emplace("white_list", "motorbike");
//config.emplace("white_list", "bus");
//config.emplace("white_list", "truck");

m_detector = BaseDetector::CreateDetector(tracking::Detectors::Yolo_TensorRT, config, frame);
if (m_detector.get())
Expand Down Expand Up @@ -957,10 +957,10 @@ class YoloTensorRTExample final : public VideoExample
m_trackerSettings.m_maximumAllowedSkippedFrames = cvRound(2 * m_fps); // Maximum allowed skipped frames
m_trackerSettings.m_maxTraceLength = cvRound(5 * m_fps); // Maximum trace length
}
m_trackerSettings.AddNearTypes(ObjectTypes::obj_car, ObjectTypes::obj_bus, false);
m_trackerSettings.AddNearTypes(ObjectTypes::obj_car, ObjectTypes::obj_truck, false);
m_trackerSettings.AddNearTypes(ObjectTypes::obj_person, ObjectTypes::obj_bicycle, true);
m_trackerSettings.AddNearTypes(ObjectTypes::obj_person, ObjectTypes::obj_motorbike, true);
m_trackerSettings.AddNearTypes(TypeConverter::Str2Type("car"), TypeConverter::Str2Type("bus"), false);
m_trackerSettings.AddNearTypes(TypeConverter::Str2Type("car"), TypeConverter::Str2Type("truck"), false);
m_trackerSettings.AddNearTypes(TypeConverter::Str2Type("person"), TypeConverter::Str2Type("bicycle"), true);
m_trackerSettings.AddNearTypes(TypeConverter::Str2Type("person"), TypeConverter::Str2Type("motorbike"), true);

m_tracker = BaseTracker::CreateTracker(m_trackerSettings);

Expand Down
2 changes: 1 addition & 1 deletion src/Detector/OCVDNNDetector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ bool OCVDNNDetector::Init(const config_t& config)
auto whiteRange = config.equal_range("white_list");
for (auto it = whiteRange.first; it != whiteRange.second; ++it)
{
m_classesWhiteList.insert(std::stoi(it->second));
m_classesWhiteList.insert(TypeConverter::Str2Type(it->second));
}

auto confidenceThreshold = config.find("confidenceThreshold");
Expand Down
2 changes: 1 addition & 1 deletion src/Detector/YoloDarknetDetector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ bool YoloDarknetDetector::Init(const config_t& config)
auto whiteRange = config.equal_range("white_list");
for (auto it = whiteRange.first; it != whiteRange.second; ++it)
{
m_classesWhiteList.insert(std::stoi(it->second));
m_classesWhiteList.insert(TypeConverter::Str2Type(it->second));
}

bool correct = m_detector.get() != nullptr;
Expand Down
2 changes: 1 addition & 1 deletion src/Detector/YoloTensorRTDetector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ bool YoloTensorRTDetector::Init(const config_t& config)
auto whiteRange = config.equal_range("white_list");
for (auto it = whiteRange.first; it != whiteRange.second; ++it)
{
m_classesWhiteList.insert(std::stoi(it->second));
m_classesWhiteList.insert(TypeConverter::Str2Type(it->second));
}

auto maxCropRatio = config.find("maxCropRatio");
Expand Down
2 changes: 1 addition & 1 deletion src/Tracker/Ctracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ CTracker::CTracker(const TrackerSettings& settings)
{
for (auto objType : embParam.m_objectTypes)
{
m_embCalculators.try_emplace((objtype_t)objType, embCalc);
m_embCalculators.try_emplace(objType, embCalc);
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/Tracker/TrackerSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,10 @@ struct TrackerSettings
cv::Size m_inputLayer{128, 256};

///
std::vector<ObjectTypes> m_objectTypes;
std::vector<objtype_t> m_objectTypes;

EmbeddingParams(const std::string& embeddingCfgName, const std::string& embeddingWeightsName,
const cv::Size& inputLayer, const std::vector<ObjectTypes>& objectTypes)
const cv::Size& inputLayer, const std::vector<objtype_t>& objectTypes)
: m_embeddingCfgName(embeddingCfgName),
m_embeddingWeightsName(embeddingWeightsName),
m_inputLayer(inputLayer),
Expand Down Expand Up @@ -242,7 +242,7 @@ struct TrackerSettings
}

///
void AddNearTypes(ObjectTypes type1, ObjectTypes type2, bool sym)
void AddNearTypes(objtype_t type1, objtype_t type2, bool sym)
{
auto AddOne = [&](objtype_t type1, objtype_t type2)
{
Expand All @@ -252,9 +252,9 @@ struct TrackerSettings
else
it->second.insert(type2);
};
AddOne((objtype_t)type1, (objtype_t)type2);
AddOne(type1, type2);
if (sym)
AddOne((objtype_t)type2, (objtype_t)type1);
AddOne(type2, type1);
}

///
Expand Down
Loading

0 comments on commit 05ec26c

Please sign in to comment.