Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add is_dynamic for YOLO series #22

Merged
merged 1 commit into from
Jul 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions csrcs/fastdeploy/vision/ppogg/yolov5lite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,21 @@ bool YOLOv5Lite::Initialize() {
FDERROR << "Failed to initialize fastdeploy backend." << std::endl;
return false;
}
// Check if the input shape is dynamic after Runtime already initialized,
// Note that, We need to force is_mini_pad 'false' to keep static
// shape after padding (LetterBox) when the is_dynamic_shape is 'false'.
is_dynamic_input_ = false;
auto shape = InputInfoOfRuntime(0).shape;
for (int i = 0; i < shape.size(); ++i) {
// if height or width is dynamic
if (i >= 2 && shape[i] <= 0) {
is_dynamic_input_ = true;
break;
}
}
if (!is_dynamic_input_) {
is_mini_pad = false;
}
return true;
}

Expand Down
10 changes: 10 additions & 0 deletions csrcs/fastdeploy/vision/ppogg/yolov5lite.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,16 @@ class FASTDEPLOY_DECL YOLOv5Lite : public FastDeployModel {
void GenerateAnchors(const std::vector<int>& size,
const std::vector<int>& downsample_strides,
std::vector<Anchor>* anchors, const int num_anchors = 3);

// 查看输入是否为动态维度的 不建议直接使用 不同模型的逻辑可能不一致
bool IsDynamicInput() const { return is_dynamic_input_; }

// whether to inference with dynamic shape (e.g ONNX export with dynamic shape
// or not.)
// while is_dynamic_shape if 'false', is_mini_pad will force 'false'. This
// value will
// auto check by fastdeploy after the internal Runtime already initialized.
bool is_dynamic_input_;
};
} // namespace ppogg
} // namespace vision
Expand Down
15 changes: 15 additions & 0 deletions csrcs/fastdeploy/vision/wongkinyiu/scaledyolov4.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,21 @@ bool ScaledYOLOv4::Initialize() {
FDERROR << "Failed to initialize fastdeploy backend." << std::endl;
return false;
}
// Check if the input shape is dynamic after Runtime already initialized,
// Note that, We need to force is_mini_pad 'false' to keep static
// shape after padding (LetterBox) when the is_dynamic_shape is 'false'.
is_dynamic_input_ = false;
auto shape = InputInfoOfRuntime(0).shape;
for (int i = 0; i < shape.size(); ++i) {
// if height or width is dynamic
if (i >= 2 && shape[i] <= 0) {
is_dynamic_input_ = true;
break;
}
}
if (!is_dynamic_input_) {
is_mini_pad = false;
}
return true;
}

Expand Down
10 changes: 10 additions & 0 deletions csrcs/fastdeploy/vision/wongkinyiu/scaledyolov4.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,16 @@ class FASTDEPLOY_DECL ScaledYOLOv4 : public FastDeployModel {
const std::vector<float>& color, bool _auto,
bool scale_fill = false, bool scale_up = true,
int stride = 32);

// 查看输入是否为动态维度的 不建议直接使用 不同模型的逻辑可能不一致
bool IsDynamicInput() const { return is_dynamic_input_; }

// whether to inference with dynamic shape (e.g ONNX export with dynamic shape
// or not.)
// while is_dynamic_shape if 'false', is_mini_pad will force 'false'. This
// value will
// auto check by fastdeploy after the internal Runtime already initialized.
bool is_dynamic_input_;
};
} // namespace wongkinyiu
} // namespace vision
Expand Down
17 changes: 16 additions & 1 deletion csrcs/fastdeploy/vision/wongkinyiu/yolor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,21 @@ bool YOLOR::Initialize() {
FDERROR << "Failed to initialize fastdeploy backend." << std::endl;
return false;
}
// Check if the input shape is dynamic after Runtime already initialized,
// Note that, We need to force is_mini_pad 'false' to keep static
// shape after padding (LetterBox) when the is_dynamic_shape is 'false'.
is_dynamic_input_ = false;
auto shape = InputInfoOfRuntime(0).shape;
for (int i = 0; i < shape.size(); ++i) {
// if height or width is dynamic
if (i >= 2 && shape[i] <= 0) {
is_dynamic_input_ = true;
break;
}
}
if (!is_dynamic_input_) {
is_mini_pad = false;
}
return true;
}

Expand Down Expand Up @@ -176,7 +191,7 @@ bool YOLOR::Postprocess(
float pad_h = (out_h - ipt_h * scale) / 2.0f;
float pad_w = (out_w - ipt_w * scale) / 2.0f;
if (is_mini_pad) {
// 和 LetterBox中_auto=true的处理逻辑对应
// 和 LetterBox中_auto=true的处理逻辑对应
pad_h = static_cast<float>(static_cast<int>(pad_h) % stride);
pad_w = static_cast<float>(static_cast<int>(pad_w) % stride);
}
Expand Down
10 changes: 10 additions & 0 deletions csrcs/fastdeploy/vision/wongkinyiu/yolor.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@ class FASTDEPLOY_DECL YOLOR : public FastDeployModel {
const std::vector<float>& color, bool _auto,
bool scale_fill = false, bool scale_up = true,
int stride = 32);

// 查看输入是否为动态维度的 不建议直接使用 不同模型的逻辑可能不一致
bool IsDynamicInput() const { return is_dynamic_input_; }

// whether to inference with dynamic shape (e.g ONNX export with dynamic shape
// or not.)
// while is_dynamic_shape if 'false', is_mini_pad will force 'false'. This
// value will
// auto check by fastdeploy after the internal Runtime already initialized.
bool is_dynamic_input_;
};
} // namespace wongkinyiu
} // namespace vision
Expand Down
17 changes: 16 additions & 1 deletion csrcs/fastdeploy/vision/wongkinyiu/yolov7.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,21 @@ bool YOLOv7::Initialize() {
FDERROR << "Failed to initialize fastdeploy backend." << std::endl;
return false;
}
// Check if the input shape is dynamic after Runtime already initialized,
// Note that, We need to force is_mini_pad 'false' to keep static
// shape after padding (LetterBox) when the is_dynamic_shape is 'false'.
is_dynamic_input_ = false;
auto shape = InputInfoOfRuntime(0).shape;
for (int i = 0; i < shape.size(); ++i) {
// if height or width is dynamic
if (i >= 2 && shape[i] <= 0) {
is_dynamic_input_ = true;
break;
}
}
if (!is_dynamic_input_) {
is_mini_pad = false;
}
return true;
}

Expand Down Expand Up @@ -177,7 +192,7 @@ bool YOLOv7::Postprocess(
float pad_h = (out_h - ipt_h * scale) / 2.0f;
float pad_w = (out_w - ipt_w * scale) / 2.0f;
if (is_mini_pad) {
// 和 LetterBox中_auto=true的处理逻辑对应
// 和 LetterBox中_auto=true的处理逻辑对应
pad_h = static_cast<float>(static_cast<int>(pad_h) % stride);
pad_w = static_cast<float>(static_cast<int>(pad_w) % stride);
}
Expand Down
10 changes: 10 additions & 0 deletions csrcs/fastdeploy/vision/wongkinyiu/yolov7.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@ class FASTDEPLOY_DECL YOLOv7 : public FastDeployModel {
const std::vector<float>& color, bool _auto,
bool scale_fill = false, bool scale_up = true,
int stride = 32);

// 查看输入是否为动态维度的 不建议直接使用 不同模型的逻辑可能不一致
bool IsDynamicInput() const { return is_dynamic_input_; }

// whether to inference with dynamic shape (e.g ONNX export with dynamic shape
// or not.)
// while is_dynamic_shape if 'false', is_mini_pad will force 'false'. This
// value will
// auto check by fastdeploy after the internal Runtime already initialized.
bool is_dynamic_input_;
};
} // namespace wongkinyiu
} // namespace vision
Expand Down