[RKNN2] Fix bugs (#851)

* 修复picodet格式

* * 修正错误文档
* 修复rknpu2 backend后端的部分错误
* 更新pphumanseg example格式

* * 更新pphumanseg example格式

* * 更新picodet example格式

* * 更新scrfd example格式

* * 更新ppseg rknpu2 python example中的错误

* * 修复代码格式问题

* * 修复代码格式问题

* * 修复代码格式问题

* * 修复代码格式问题

* * 修复代码格式问题

* * 修复代码格式问题

Co-authored-by: Jason <jiangjiajun@baidu.com>
This commit is contained in:
Zheng_Bicheng
2022-12-12 15:37:31 +08:00
committed by GitHub
parent af4c28d4ae
commit 188dcedc02
14 changed files with 309 additions and 261 deletions

View File

@@ -21,32 +21,8 @@ namespace detection {
RKYOLOPostprocessor::RKYOLOPostprocessor() {}
void RKYOLOPostprocessor::SetModelType(ModelType model_type) {
model_type_ = model_type;
if (model_type == RKYOLOV5) {
anchors_ = {10, 13, 16, 30, 33, 23, 30, 61, 62,
45, 59, 119, 116, 90, 156, 198, 373, 326};
anchor_per_branch_ = 3;
} else if (model_type == RKYOLOX) {
anchors_ = {10, 13, 16, 30, 33, 23, 30, 61, 62,
45, 59, 119, 116, 90, 156, 198, 373, 326};
anchor_per_branch_ = 1;
} else if (model_type == RKYOLOV7) {
anchors_ = {12, 16, 19, 36, 40, 28, 36, 75, 76,
55, 72, 146, 142, 110, 192, 243, 459, 401};
anchor_per_branch_ = 3;
} else {
return;
}
}
bool RKYOLOPostprocessor::Run(const std::vector<FDTensor>& tensors,
std::vector<DetectionResult>* results) {
if (model_type_ == ModelType::UNKNOWN) {
FDERROR << "RKYOLO Only Support YOLOV5,YOLOV7,YOLOX" << std::endl;
return false;
}
results->resize(tensors[0].shape[0]);
for (int num = 0; num < tensors[0].shape[0]; ++num) {
int validCount = 0;
@@ -62,13 +38,15 @@ bool RKYOLOPostprocessor::Run(const std::vector<FDTensor>& tensors,
int grid_h = height_ / stride;
int grid_w = width_ / stride;
int* anchor = &(anchors_.data()[i * 2 * anchor_per_branch_]);
if (tensors[i].dtype == FDDataType::INT8 || tensors[i].dtype == FDDataType::UINT8) {
if (tensors[i].dtype == FDDataType::INT8 ||
tensors[i].dtype == FDDataType::UINT8) {
auto quantization_info = tensors[i].GetQuantizationInfo();
validCount = validCount +
ProcessInt8((int8_t*)tensors[i].Data() + skip_address,
anchor, grid_h, grid_w, stride, filterBoxes,
boxesScore, classId, conf_threshold_,
quantization_info.first, quantization_info.second[0]);
validCount =
validCount + ProcessInt8((int8_t*)tensors[i].Data() + skip_address,
anchor, grid_h, grid_w, stride,
filterBoxes, boxesScore, classId,
conf_threshold_, quantization_info.first,
quantization_info.second[0]);
} else {
FDERROR << "RKYOLO Only Support INT8 Model" << std::endl;
}
@@ -87,10 +65,13 @@ bool RKYOLOPostprocessor::Run(const std::vector<FDTensor>& tensors,
QuickSortIndiceInverse(boxesScore, 0, validCount - 1, indexArray);
if (model_type_ == RKYOLOV5 || model_type_ == RKYOLOV7) {
if (anchor_per_branch_ == 3) {
NMS(validCount, filterBoxes, classId, indexArray, nms_threshold_, false);
} else if (model_type_ == RKYOLOX) {
} else if (anchor_per_branch_ == 1) {
NMS(validCount, filterBoxes, classId, indexArray, nms_threshold_, true);
}else{
FDERROR << "anchor_per_branch_ only support 3 or 1." << std::endl;
return false;
}
int last_count = 0;
@@ -110,19 +91,18 @@ bool RKYOLOPostprocessor::Run(const std::vector<FDTensor>& tensors,
float y2 = y1 + filterBoxes[n * 4 + 3];
int id = classId[n];
(*results)[num].boxes.emplace_back(std::array<float, 4>{
(float)((clamp(x1, 0, width_) - pad_hw_values_[num][1] / 2) /
(float)((Clamp(x1, 0, width_) - pad_hw_values_[num][1] / 2) /
scale_[num]),
(float)((clamp(y1, 0, height_) - pad_hw_values_[num][0] / 2) /
(float)((Clamp(y1, 0, height_) - pad_hw_values_[num][0] / 2) /
scale_[num]),
(float)((clamp(x2, 0, width_) - pad_hw_values_[num][1] / 2) /
(float)((Clamp(x2, 0, width_) - pad_hw_values_[num][1] / 2) /
scale_[num]),
(float)((clamp(y2, 0, height_) - pad_hw_values_[num][0] / 2) /
(float)((Clamp(y2, 0, height_) - pad_hw_values_[num][0] / 2) /
scale_[0])});
(*results)[num].label_ids.push_back(id);
(*results)[num].scores.push_back(boxesScore[i]);
last_count++;
}
std::cout << "last_count" << last_count << std::endl;
}
return true;
}
@@ -159,7 +139,7 @@ int RKYOLOPostprocessor::ProcessInt8(int8_t* input, int* anchor, int grid_h,
float box_conf_f32 = DeqntAffineToF32(box_confidence, zp, scale);
float class_prob_f32 = DeqntAffineToF32(maxClassProbs, zp, scale);
float limit_score = 0;
if (model_type_ == RKYOLOX) {
if (anchor_per_branch_ == 1) {
limit_score = box_conf_f32 * class_prob_f32;
} else {
limit_score = class_prob_f32;
@@ -167,7 +147,7 @@ int RKYOLOPostprocessor::ProcessInt8(int8_t* input, int* anchor, int grid_h,
//printf("limit score: %f\n", limit_score);
if (limit_score > conf_threshold_) {
float box_x, box_y, box_w, box_h;
if (model_type_ == RKYOLOX) {
if (anchor_per_branch_ == 1) {
box_x = DeqntAffineToF32(*in_ptr, zp, scale);
box_y = DeqntAffineToF32(in_ptr[grid_len], zp, scale);
box_w = DeqntAffineToF32(in_ptr[2 * grid_len], zp, scale);
@@ -234,6 +214,6 @@ int RKYOLOPostprocessor::QuickSortIndiceInverse(std::vector<float>& input,
return low;
}
} // namespace detection
} // namespace vision
} // namespace fastdeploy
} // namespace detection
} // namespace vision
} // namespace fastdeploy