|
|
@@ -10,7 +10,7 @@
|
|
|
#include "../tool/debuglog.h"
|
|
|
|
|
|
YoloFeatureExtractor::YoloFeatureExtractor(const std::string & modelPath, const std::string & classesPath)
|
|
|
- : inputWidth(800), inputHeight(800)
|
|
|
+ : inputWidth(224), inputHeight(224)
|
|
|
{
|
|
|
net = cv::dnn::readNetFromONNX(modelPath);
|
|
|
loadClassNames(classesPath);
|
|
|
@@ -85,21 +85,8 @@ std::vector<float> YoloFeatureExtractor::extractFeatures(const std::string & ima
|
|
|
std::vector<cv::String> layerNames = net.getLayerNames();
|
|
|
std::vector<cv::String> outputNames;
|
|
|
|
|
|
- // 选择合适的特征层(使用倒数第二个卷积层作为特征提取层)
|
|
|
- if (layerNames.size() >= 8)
|
|
|
- {
|
|
|
- // 通常倒数第8层左右是较好的特征层
|
|
|
- outputNames.push_back(layerNames[layerNames.size() - 6]);
|
|
|
- }
|
|
|
- else if (layerNames.size() >= 2)
|
|
|
- {
|
|
|
- outputNames.push_back(layerNames[layerNames.size() - 2]);
|
|
|
- }
|
|
|
-
|
|
|
- else
|
|
|
- {
|
|
|
- outputNames.push_back(layerNames.back());
|
|
|
- }
|
|
|
+ // 选择GAP层(对于yolo2026,通常是倒数第6层)的输出作为特征向量
|
|
|
+ outputNames.push_back(layerNames[layerNames.size() - 6]);
|
|
|
|
|
|
std::vector<cv::Mat> outputs;
|
|
|
net.forward(outputs, outputNames);
|