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:
parent
f960c5030d
commit
bd891a96dd
136 changed files with 14413 additions and 9399 deletions
|
|
@ -1,35 +1,35 @@
|
|||
cmake_minimum_required(VERSION 3.10...3.27)
|
||||
project(resnet_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(resnet_demo
|
||||
main.cpp
|
||||
postprocess.cpp
|
||||
${CMAKE_SOURCE_DIR}/../../../../common/model_loader.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(resnet_demo
|
||||
${OpenCV_LIBS}
|
||||
${AMLNN_LIBRARY}
|
||||
cmake_minimum_required(VERSION 3.10...3.27)
|
||||
project(resnet_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(resnet_demo
|
||||
main.cpp
|
||||
postprocess.cpp
|
||||
${CMAKE_SOURCE_DIR}/../../../../common/model_loader.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(resnet_demo
|
||||
${OpenCV_LIBS}
|
||||
${AMLNN_LIBRARY}
|
||||
)
|
||||
|
|
@ -13,7 +13,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
|
@ -57,7 +57,7 @@ int main(int argc, char** argv) {
|
|||
in.input = (unsigned char*)input_buffer.data();
|
||||
in.size = input_buffer.size() * sizeof(float);
|
||||
in.info.valid = 1;
|
||||
in.info.input_format = AML_INPUT_MODEL_NHWC;
|
||||
in.info.input_format = AML_INPUT_MODEL_NHWC;
|
||||
in.info.input_data_type = AML_INPUT_FP32;
|
||||
aml_module_input_set(ctx, &in);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,62 +1,62 @@
|
|||
/*
|
||||
* Copyright (C) 2024–2025 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 <iostream>
|
||||
#include <fstream>
|
||||
#include <numeric>
|
||||
#include <algorithm>
|
||||
|
||||
void preprocess(const cv::Mat& src, float* dst) {
|
||||
cv::Mat rgb, resized;
|
||||
cv::cvtColor(src, rgb, cv::COLOR_BGR2RGB);
|
||||
cv::resize(rgb, resized, cv::Size(kInputW, kInputH));
|
||||
|
||||
for (int i = 0; i < kInputH; ++i) {
|
||||
for (int j = 0; j < kInputW; ++j) {
|
||||
cv::Vec3f pixel = resized.at<cv::Vec3b>(i, j);
|
||||
int idx = (i * kInputW + j) * 3;
|
||||
dst[idx + 0] = (pixel[0] - MEAN[0]) / STD[0];
|
||||
dst[idx + 1] = (pixel[1] - MEAN[1]) / STD[1];
|
||||
dst[idx + 2] = (pixel[2] - MEAN[2]) / STD[2];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void postprocess_topk(float* logits, int size, const std::vector<std::string>& labels, int k) {
|
||||
std::vector<int> indices(size);
|
||||
std::iota(indices.begin(), indices.end(), 0);
|
||||
|
||||
std::partial_sort(indices.begin(), indices.begin() + k, indices.end(),
|
||||
[&](int a, int b) { return logits[a] > logits[b]; });
|
||||
|
||||
std::cout << "\nTop-" << k << " Results:" << std::endl;
|
||||
for (int i = 0; i < k; ++i) {
|
||||
int idx = indices[i];
|
||||
std::string name = (idx < (int)labels.size()) ? labels[idx] : "N/A";
|
||||
printf("%d: %-20s score=%.6f\n", i + 1, name.c_str(), logits[idx]);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::string> load_labels(const std::string& path) {
|
||||
std::vector<std::string> labels;
|
||||
std::ifstream f(path);
|
||||
std::string line;
|
||||
while (std::getline(f, line)) {
|
||||
if(!line.empty()) labels.push_back(line);
|
||||
}
|
||||
return labels;
|
||||
/*
|
||||
* Copyright (C) 2024–2025 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 <iostream>
|
||||
#include <fstream>
|
||||
#include <numeric>
|
||||
#include <algorithm>
|
||||
|
||||
void preprocess(const cv::Mat& src, float* dst) {
|
||||
cv::Mat rgb, resized;
|
||||
cv::cvtColor(src, rgb, cv::COLOR_BGR2RGB);
|
||||
cv::resize(rgb, resized, cv::Size(kInputW, kInputH));
|
||||
|
||||
for (int i = 0; i < kInputH; ++i) {
|
||||
for (int j = 0; j < kInputW; ++j) {
|
||||
cv::Vec3f pixel = resized.at<cv::Vec3b>(i, j);
|
||||
int idx = (i * kInputW + j) * 3;
|
||||
dst[idx + 0] = (pixel[0] - MEAN[0]) / STD[0];
|
||||
dst[idx + 1] = (pixel[1] - MEAN[1]) / STD[1];
|
||||
dst[idx + 2] = (pixel[2] - MEAN[2]) / STD[2];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void postprocess_topk(float* logits, int size, const std::vector<std::string>& labels, int k) {
|
||||
std::vector<int> indices(size);
|
||||
std::iota(indices.begin(), indices.end(), 0);
|
||||
|
||||
std::partial_sort(indices.begin(), indices.begin() + k, indices.end(),
|
||||
[&](int a, int b) { return logits[a] > logits[b]; });
|
||||
|
||||
std::cout << "\nTop-" << k << " Results:" << std::endl;
|
||||
for (int i = 0; i < k; ++i) {
|
||||
int idx = indices[i];
|
||||
std::string name = (idx < (int)labels.size()) ? labels[idx] : "N/A";
|
||||
printf("%d: %-20s score=%.6f\n", i + 1, name.c_str(), logits[idx]);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::string> load_labels(const std::string& path) {
|
||||
std::vector<std::string> labels;
|
||||
std::ifstream f(path);
|
||||
std::string line;
|
||||
while (std::getline(f, line)) {
|
||||
if (!line.empty()) labels.push_back(line);
|
||||
}
|
||||
return labels;
|
||||
}
|
||||
|
|
@ -1,35 +1,35 @@
|
|||
/*
|
||||
* Copyright (C) 2024–2025 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 RESNET_POSTPROCESS_H
|
||||
#define RESNET_POSTPROCESS_H
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <opencv2/opencv.hpp>
|
||||
|
||||
static const float MEAN[3] = {123.675f, 116.28f, 103.53f};
|
||||
static const float STD[3] = {58.395f, 58.395f, 58.395f};
|
||||
static constexpr int kInputW = 224;
|
||||
static constexpr int kInputH = 224;
|
||||
|
||||
void preprocess(const cv::Mat& src, float* dst);
|
||||
|
||||
void postprocess_topk(float* logits, int size, const std::vector<std::string>& labels, int k = 5);
|
||||
|
||||
std::vector<std::string> load_labels(const std::string& path);
|
||||
|
||||
/*
|
||||
* Copyright (C) 2024–2025 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 RESNET_POSTPROCESS_H
|
||||
#define RESNET_POSTPROCESS_H
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <opencv2/opencv.hpp>
|
||||
|
||||
static const float MEAN[3] = {123.675f, 116.28f, 103.53f};
|
||||
static const float STD[3] = {58.395f, 58.395f, 58.395f};
|
||||
static constexpr int kInputW = 224;
|
||||
static constexpr int kInputH = 224;
|
||||
|
||||
void preprocess(const cv::Mat& src, float* dst);
|
||||
|
||||
void postprocess_topk(float* logits, int size, const std::vector<std::string>& labels, int k = 5);
|
||||
|
||||
std::vector<std::string> load_labels(const std::string& path);
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue