Skip to content

Commit afa3b88

Browse files
[Bug Fix] fixed labels setting of YOLOv5 (#1213)
修复自己训练的yolov5无法指定label个数的错误
1 parent a711f99 commit afa3b88

File tree

5 files changed

+24
-96
lines changed

5 files changed

+24
-96
lines changed

docs/cn/faq/rknpu2/build.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ cmake .. -DCMAKE_C_COMPILER=/home/zbc/opt/gcc-linaro-6.3.1-2017.05-x86_64_aarch
4747
-DENABLE_ORT_BACKEND=OFF \
4848
-DENABLE_RKNPU2_BACKEND=ON \
4949
-DENABLE_VISION=ON \
50-
-DRKNN2_TARGET_SOC=RK3588 \
51-
-DENABLE_FLYCV=ON \
50+
-DRKNN2_TARGET_SOC=RK356X \
5251
-DCMAKE_INSTALL_PREFIX=${PWD}/fastdeploy-0.0.0
5352
make -j8
5453
make install

examples/vision/detection/rkyolo/cpp/CMakeLists.txt

+5-30
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,9 @@ project(rknpu2_test)
44
set(CMAKE_CXX_STANDARD 14)
55

66
# 指定下载解压后的fastdeploy库路径
7-
set(FASTDEPLOY_INSTALL_DIR "thirdpartys/fastdeploy-0.0.3")
8-
9-
include(${FASTDEPLOY_INSTALL_DIR}/FastDeployConfig.cmake)
10-
include_directories(${FastDeploy_INCLUDE_DIRS})
11-
7+
option(FASTDEPLOY_INSTALL_DIR "Path of downloaded fastdeploy sdk.")
8+
include(${FASTDEPLOY_INSTALL_DIR}/FastDeploy.cmake)
9+
# 添加FastDeploy依赖头文件
10+
include_directories(${FASTDEPLOY_INCS})
1211
add_executable(infer_rkyolo infer_rkyolo.cc)
13-
target_link_libraries(infer_rkyolo ${FastDeploy_LIBS})
14-
15-
16-
17-
set(CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR}/build/install)
18-
19-
install(TARGETS infer_rkyolo DESTINATION ./)
20-
21-
install(DIRECTORY model DESTINATION ./)
22-
install(DIRECTORY images DESTINATION ./)
23-
24-
file(GLOB FASTDEPLOY_LIBS ${FASTDEPLOY_INSTALL_DIR}/lib/*)
25-
message("${FASTDEPLOY_LIBS}")
26-
install(PROGRAMS ${FASTDEPLOY_LIBS} DESTINATION lib)
27-
28-
file(GLOB ONNXRUNTIME_LIBS ${FASTDEPLOY_INSTALL_DIR}/third_libs/install/onnxruntime/lib/*)
29-
install(PROGRAMS ${ONNXRUNTIME_LIBS} DESTINATION lib)
30-
31-
install(DIRECTORY ${FASTDEPLOY_INSTALL_DIR}/third_libs/install/opencv/lib DESTINATION ./)
32-
33-
file(GLOB PADDLETOONNX_LIBS ${FASTDEPLOY_INSTALL_DIR}/third_libs/install/paddle2onnx/lib/*)
34-
install(PROGRAMS ${PADDLETOONNX_LIBS} DESTINATION lib)
35-
36-
file(GLOB RKNPU2_LIBS ${FASTDEPLOY_INSTALL_DIR}/third_libs/install/rknpu2_runtime/${RKNN2_TARGET_SOC}/lib/*)
37-
install(PROGRAMS ${RKNPU2_LIBS} DESTINATION lib)
12+
target_link_libraries(infer_rkyolo ${FASTDEPLOY_LIBS})

examples/vision/detection/rkyolo/cpp/README_CN.md

+2-48
Original file line numberDiff line numberDiff line change
@@ -10,58 +10,12 @@
1010

1111
以上步骤请参考[RK2代NPU部署库编译](../../../../../docs/cn/build_and_install/rknpu2.md)实现
1212

13-
## 生成基本目录文件
14-
15-
该例程由以下几个部分组成
16-
```text
17-
.
18-
├── CMakeLists.txt
19-
├── build # 编译文件夹
20-
├── image # 存放图片的文件夹
21-
├── infer_rkyolo.cc
22-
├── model # 存放模型文件的文件夹
23-
└── thirdpartys # 存放sdk的文件夹
24-
```
25-
26-
首先需要先生成目录结构
27-
```bash
28-
mkdir build
29-
mkdir images
30-
mkdir model
31-
mkdir thirdpartys
32-
```
33-
34-
## 编译
35-
36-
### 编译并拷贝SDK到thirdpartys文件夹
37-
38-
请参考[RK2代NPU部署库编译](../../../../../docs/cn/build_and_install/rknpu2.md)仓库编译SDK,编译完成后,将在build目录下生成
39-
fastdeploy-0.0.3目录,请移动它至thirdpartys目录下.
40-
41-
### 拷贝模型文件,以及配置文件至model文件夹
42-
在Paddle动态图模型 -> Paddle静态图模型 -> ONNX模型的过程中,将生成ONNX文件以及对应的yaml配置文件,请将配置文件存放到model文件夹内。
43-
转换为RKNN后的模型文件也需要拷贝至model。
44-
45-
### 准备测试图片至image文件夹
4613
```bash
4714
wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg
48-
cp 000000014439.jpg ./images
49-
```
50-
51-
### 编译example
52-
53-
```bash
5415
cd build
55-
cmake ..
16+
cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x
5617
make -j8
57-
make install
58-
```
59-
60-
## 运行例程
61-
62-
```bash
63-
cd ./build/install
64-
./infer_picodet model/ images/000000014439.jpg
18+
./infer_rkyolo /path/to/model 000000014439.jpg
6519
```
6620

6721

fastdeploy/vision/detection/contrib/rknpu2/postprocessor.cc

-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ int RKYOLOPostprocessor::ProcessFP16(float* input, int* anchor, int grid_h,
141141
} else {
142142
limit_score = box_conf_f32 * class_prob_f32;
143143
}
144-
// printf("limit score: %f", limit_score);
145144
if (limit_score > conf_threshold_) {
146145
float box_x, box_y, box_w, box_h;
147146
if (anchor_per_branch_ == 1) {

fastdeploy/vision/detection/contrib/rknpu2/postprocessor.h

+16-15
Original file line numberDiff line numberDiff line change
@@ -55,26 +55,30 @@ class FASTDEPLOY_DECL RKYOLOPostprocessor {
5555
/// Get nms_threshold, default 0.45
5656
float GetNMSThreshold() const { return nms_threshold_; }
5757

58-
// Set height and weight
58+
/// Set height and weight
5959
void SetHeightAndWeight(int& height, int& width) {
6060
height_ = height;
6161
width_ = width;
6262
}
6363

64-
// Set pad_hw_values
64+
/// Set pad_hw_values
6565
void SetPadHWValues(std::vector<std::vector<int>> pad_hw_values) {
6666
pad_hw_values_ = pad_hw_values;
6767
}
6868

69-
// Set scale
70-
void SetScale(std::vector<float> scale) {
71-
scale_ = scale;
72-
}
69+
/// Set scale
70+
void SetScale(std::vector<float> scale) { scale_ = scale; }
7371

74-
// Set Anchor
72+
/// Set Anchor
7573
void SetAnchor(std::vector<int> anchors, int anchor_per_branch) {
76-
anchors_ = anchors;
77-
anchor_per_branch_ = anchor_per_branch;
74+
anchors_ = anchors;
75+
anchor_per_branch_ = anchor_per_branch;
76+
}
77+
78+
/// Set the number of class
79+
void SetClassNum(int num) {
80+
obj_class_num_ = num;
81+
prob_box_size_ = obj_class_num_ + 5;
7882
}
7983

8084
private:
@@ -85,12 +89,9 @@ class FASTDEPLOY_DECL RKYOLOPostprocessor {
8589
int width_ = 0;
8690
int anchor_per_branch_ = 0;
8791

88-
int ProcessFP16(float *input, int *anchor, int grid_h,
89-
int grid_w, int stride,
90-
std::vector<float> &boxes,
91-
std::vector<float> &boxScores,
92-
std::vector<int> &classId,
93-
float threshold);
92+
int ProcessFP16(float* input, int* anchor, int grid_h, int grid_w, int stride,
93+
std::vector<float>& boxes, std::vector<float>& boxScores,
94+
std::vector<int>& classId, float threshold);
9495
// Model
9596
int QuickSortIndiceInverse(std::vector<float>& input, int left, int right,
9697
std::vector<int>& indices);

0 commit comments

Comments
 (0)