MCPcopy Create free account
hub / github.com/Smorodov/Multitarget-tracker / Init

Method Init

src/Detector/YoloDarknetDetector.cpp:39–101  ·  view source on GitHub ↗

\brief YoloDarknetDetector::Init \return

Source from the content-addressed store, hash-verified

37/// \return
38///
39bool YoloDarknetDetector::Init(const config_t& config)
40{
41 m_detector.reset();
42
43 auto modelConfiguration = config.find("modelConfiguration");
44 auto modelBinary = config.find("modelBinary");
45 if (modelConfiguration == config.end() || modelBinary == config.end())
46 return false;
47
48 int currGPUID = 0;
49 auto gpuId = config.find("gpuId");
50 if (gpuId != config.end())
51 currGPUID = std::max(0, std::stoi(gpuId->second));
52
53 auto maxBatch = config.find("maxBatch");
54 if (maxBatch != config.end())
55 m_batchSize = std::max(1, std::stoi(maxBatch->second));
56
57 m_detector = std::make_unique<Detector>(modelConfiguration->second, modelBinary->second, currGPUID, static_cast<int>(m_batchSize));
58 m_detector->nms = 0.2f;
59
60 auto classNames = config.find("classNames");
61 if (classNames != config.end())
62 {
63 std::ifstream classNamesFile(classNames->second);
64 if (classNamesFile.is_open())
65 {
66 m_classNames.clear();
67 std::string className;
68 for (; std::getline(classNamesFile, className); )
69 {
70 className.erase(className.find_last_not_of(" \t\n\r\f\v") + 1);
71 m_classNames.push_back(className);
72 }
73 if (!FillTypesMap(m_classNames))
74 {
75 std::cout << "Unknown types in class names!" << std::endl;
76 assert(0);
77 }
78 }
79 }
80
81 auto confidenceThreshold = config.find("confidenceThreshold");
82 if (confidenceThreshold != config.end())
83 m_confidenceThreshold = std::stof(confidenceThreshold->second);
84
85 auto maxCropRatio = config.find("maxCropRatio");
86 if (maxCropRatio != config.end())
87 m_maxCropRatio = std::stof(maxCropRatio->second);
88
89 m_classesWhiteList.clear();
90 auto whiteRange = config.equal_range("white_list");
91 for (auto it = whiteRange.first; it != whiteRange.second; ++it)
92 {
93 m_classesWhiteList.insert(TypeConverter::Str2Type(it->second));
94 }
95
96 bool correct = m_detector.get() != nullptr;

Callers

nothing calls this directly

Calls 9

endMethod · 0.80
eraseMethod · 0.80
insertMethod · 0.80
get_net_widthMethod · 0.80
get_net_heightMethod · 0.80
resetMethod · 0.45
clearMethod · 0.45
push_backMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected