docs: Update README and compilation guides for clarity and consistency, including path corrections and improved formatting. Add copyright notices to source files and adjust file permissions for several scripts and directories.

This commit is contained in:
dian.yuan 2026-02-28 11:06:26 +08:00
parent f960c5030d
commit bd891a96dd
136 changed files with 14413 additions and 9399 deletions

View file

@ -1,35 +1,35 @@
cmake_minimum_required(VERSION 3.10...3.27)
project(yolo11_demo)
set(CMAKE_CXX_STANDARD 17)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/../../../../cmake")
find_package(AMLNN REQUIRED)
include_directories(${AMLNN_INCLUDE_DIR})
link_directories(${AMLNN_LIBRARY_DIR})
include_directories(${CMAKE_SOURCE_DIR}/../../../../common)
# Set dependency path
set(3RDPARTY_DIR "${CMAKE_SOURCE_DIR}/../../../../dependency")
if(CMAKE_SYSTEM_NAME STREQUAL "Android")
# Android needs log
link_libraries(log)
endif()
# Find OpenCV
message(STATUS "OpenCV_DIR: ${OpenCV_DIR}")
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
add_executable(yolo11_demo
main.cpp
postprocess.cpp
${CMAKE_SOURCE_DIR}/../../../../common/model_loader.cpp
)
target_link_libraries(yolo11_demo
${OpenCV_LIBS}
${AMLNN_LIBRARY}
cmake_minimum_required(VERSION 3.10...3.27)
project(yolo11_demo)
set(CMAKE_CXX_STANDARD 17)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/../../../../cmake")
find_package(AMLNN REQUIRED)
include_directories(${AMLNN_INCLUDE_DIR})
link_directories(${AMLNN_LIBRARY_DIR})
include_directories(${CMAKE_SOURCE_DIR}/../../../../common)
# Set dependency path
set(3RDPARTY_DIR "${CMAKE_SOURCE_DIR}/../../../../dependency")
if(CMAKE_SYSTEM_NAME STREQUAL "Android")
# Android needs log
link_libraries(log)
endif()
# Find OpenCV
message(STATUS "OpenCV_DIR: ${OpenCV_DIR}")
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
add_executable(yolo11_demo
main.cpp
postprocess.cpp
${CMAKE_SOURCE_DIR}/../../../../common/model_loader.cpp
)
target_link_libraries(yolo11_demo
${OpenCV_LIBS}
${AMLNN_LIBRARY}
)

View file

@ -58,9 +58,9 @@ int main(int argc, char** argv) {
int nw = img.cols * scale, nh = img.rows * scale;
int px = (kInputW - nw) / 2, py = (kInputH - nh) / 2;
cv::Mat res, canvas = cv::Mat::zeros(kInputH, kInputW, CV_32FC3);
canvas.setTo(cv::Scalar(114.0/255.0, 114.0/255.0, 114.0/255.0));
canvas.setTo(cv::Scalar(114.0/255.0, 114.0/255.0, 114.0/255.0));
cv::resize(img, res, {nw, nh});
res.convertTo(res, CV_32FC3, 1.0 / 255.0);
res.convertTo(res, CV_32FC3, 1.0 / 255.0);
res.copyTo(canvas(cv::Rect(px, py, nw, nh)));
hwc_to_chw(canvas, chw_buffer.data());
@ -108,7 +108,7 @@ int main(int argc, char** argv) {
for (size_t i = 0; i < indices.size(); i++) {
int idx = indices[i];
printf(" %zu. %s (%.2f)\n", i + 1, kClassNames[class_ids[idx]].c_str(), confs[idx]);
cv::rectangle(img, bboxes[idx], {0, 255, 0}, 2);
char text[256]; std::sprintf(text, "%s %.2f", kClassNames[class_ids[idx]].c_str(), confs[idx]);
cv::putText(img, text, {bboxes[idx].x, bboxes[idx].y - 5}, cv::FONT_HERSHEY_SIMPLEX, 0.5, {0, 255, 0}, 1);

View file

@ -1,82 +1,82 @@
/*
* Copyright (C) 20242025 Amlogic, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "postprocess.h"
#include <cmath>
#include <numeric>
#include <algorithm>
#include <float.h>
const std::vector<std::string> kClassNames = {
"person", "bicycle", "car", "motorcycle", "airplane", "bus", "train", "truck", "boat", "traffic light",
"fire hydrant", "stop sign", "parking meter", "bench", "bird", "cat", "dog", "horse", "sheep", "cow",
"elephant", "bear", "zebra", "giraffe", "backpack", "umbrella", "handbag", "tie", "suitcase", "frisbee",
"skis", "snowboard", "sports ball", "kite", "baseball bat", "baseball glove", "skateboard", "surfboard",
"tennis racket", "bottle", "wine glass", "cup", "fork", "knife", "spoon", "bowl", "banana", "apple",
"sandwich", "orange", "broccoli", "carrot", "hot dog", "pizza", "donut", "cake", "chair", "couch",
"potted plant", "bed", "dining table", "toilet", "tv", "laptop", "mouse", "remote", "keyboard",
"cell phone", "microwave", "oven", "toaster", "sink", "refrigerator", "book", "clock", "vase",
"scissors", "teddy bear", "hair drier", "toothbrush"
};
float decode_dfl(const float* dfl_ptr) {
float max_val = -FLT_MAX;
for (int i = 0; i < kDflChannels; i++) {
if (dfl_ptr[i] > max_val) max_val = dfl_ptr[i];
}
float exp_sum = 0;
float exp_vals[kDflChannels];
for (int i = 0; i < kDflChannels; i++) {
exp_vals[i] = std::exp(dfl_ptr[i] - max_val);
exp_sum += exp_vals[i];
}
float res = 0;
for (int i = 0; i < kDflChannels; i++) {
res += (exp_vals[i] / exp_sum) * i;
}
return res;
}
float calculate_iou(const cv::Rect& a, const cv::Rect& b) {
int xx1 = std::max(a.x, b.x);
int yy1 = std::max(a.y, b.y);
int xx2 = std::min(a.x + a.width, b.x + b.width);
int yy2 = std::min(a.y + a.height, b.y + b.height);
int w = std::max(0, xx2 - xx1);
int h = std::max(0, yy2 - yy1);
float inter = (float)w * h;
float areaA = (float)a.width * a.height;
float areaB = (float)b.width * b.height;
return inter / (areaA + areaB - inter);
}
std::vector<int> manual_nms(const std::vector<cv::Rect>& boxes, const std::vector<float>& scores, float thresh) {
std::vector<int> order(boxes.size());
std::iota(order.begin(), order.end(), 0);
std::stable_sort(order.begin(), order.end(), [&](int a, int b) {
return scores[a] > scores[b];
});
std::vector<int> keep;
while (!order.empty()) {
int i = order[0];
keep.push_back(i);
order.erase(order.begin());
order.erase(std::remove_if(order.begin(), order.end(), [&](int j) {
return calculate_iou(boxes[i], boxes[j]) > thresh;
}), order.end());
}
return keep;
/*
* Copyright (C) 20242025 Amlogic, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "postprocess.h"
#include <cmath>
#include <numeric>
#include <algorithm>
#include <float.h>
const std::vector<std::string> kClassNames = {
"person", "bicycle", "car", "motorcycle", "airplane", "bus", "train", "truck", "boat", "traffic light",
"fire hydrant", "stop sign", "parking meter", "bench", "bird", "cat", "dog", "horse", "sheep", "cow",
"elephant", "bear", "zebra", "giraffe", "backpack", "umbrella", "handbag", "tie", "suitcase", "frisbee",
"skis", "snowboard", "sports ball", "kite", "baseball bat", "baseball glove", "skateboard", "surfboard",
"tennis racket", "bottle", "wine glass", "cup", "fork", "knife", "spoon", "bowl", "banana", "apple",
"sandwich", "orange", "broccoli", "carrot", "hot dog", "pizza", "donut", "cake", "chair", "couch",
"potted plant", "bed", "dining table", "toilet", "tv", "laptop", "mouse", "remote", "keyboard",
"cell phone", "microwave", "oven", "toaster", "sink", "refrigerator", "book", "clock", "vase",
"scissors", "teddy bear", "hair drier", "toothbrush"
};
float decode_dfl(const float* dfl_ptr) {
float max_val = -FLT_MAX;
for (int i = 0; i < kDflChannels; i++) {
if (dfl_ptr[i] > max_val) max_val = dfl_ptr[i];
}
float exp_sum = 0;
float exp_vals[kDflChannels];
for (int i = 0; i < kDflChannels; i++) {
exp_vals[i] = std::exp(dfl_ptr[i] - max_val);
exp_sum += exp_vals[i];
}
float res = 0;
for (int i = 0; i < kDflChannels; i++) {
res += (exp_vals[i] / exp_sum) * i;
}
return res;
}
float calculate_iou(const cv::Rect& a, const cv::Rect& b) {
int xx1 = std::max(a.x, b.x);
int yy1 = std::max(a.y, b.y);
int xx2 = std::min(a.x + a.width, b.x + b.width);
int yy2 = std::min(a.y + a.height, b.y + b.height);
int w = std::max(0, xx2 - xx1);
int h = std::max(0, yy2 - yy1);
float inter = (float)w * h;
float areaA = (float)a.width * a.height;
float areaB = (float)b.width * b.height;
return inter / (areaA + areaB - inter);
}
std::vector<int> manual_nms(const std::vector<cv::Rect>& boxes, const std::vector<float>& scores, float thresh) {
std::vector<int> order(boxes.size());
std::iota(order.begin(), order.end(), 0);
std::stable_sort(order.begin(), order.end(), [&](int a, int b) {
return scores[a] > scores[b];
});
std::vector<int> keep;
while (!order.empty()) {
int i = order[0];
keep.push_back(i);
order.erase(order.begin());
order.erase(std::remove_if(order.begin(), order.end(), [&](int j) {
return calculate_iou(boxes[i], boxes[j]) > thresh;
}), order.end());
}
return keep;
}

View file

@ -1,42 +1,42 @@
/*
* Copyright (C) 20242025 Amlogic, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef YOLO11_POSTPROCESS_H
#define YOLO11_POSTPROCESS_H
#include <vector>
#include <string>
#include <opencv2/opencv.hpp>
static constexpr int kInputW = 640;
static constexpr int kInputH = 640;
static constexpr int kNumClasses = 80;
static constexpr int kDflChannels = 16;
static constexpr int kTotalChannels = 144;
extern const std::vector<std::string> kClassNames;
struct Detection {
cv::Rect box;
float confidence;
int class_id;
};
float decode_dfl(const float* dfl_ptr);
float calculate_iou(const cv::Rect& a, const cv::Rect& b);
std::vector<int> manual_nms(const std::vector<cv::Rect>& boxes, const std::vector<float>& scores, float thresh);
/*
* Copyright (C) 20242025 Amlogic, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef YOLO11_POSTPROCESS_H
#define YOLO11_POSTPROCESS_H
#include <vector>
#include <string>
#include <opencv2/opencv.hpp>
static constexpr int kInputW = 640;
static constexpr int kInputH = 640;
static constexpr int kNumClasses = 80;
static constexpr int kDflChannels = 16;
static constexpr int kTotalChannels = 144;
extern const std::vector<std::string> kClassNames;
struct Detection {
cv::Rect box;
float confidence;
int class_id;
};
float decode_dfl(const float* dfl_ptr);
float calculate_iou(const cv::Rect& a, const cv::Rect& b);
std::vector<int> manual_nms(const std::vector<cv::Rect>& boxes, const std::vector<float>& scores, float thresh);
#endif