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

support nearest_interp op with old version (v1) #1300

Merged
merged 1 commit into from
Jul 8, 2024
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
20 changes: 15 additions & 5 deletions paddle2onnx/mapper/nn/interpolate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
namespace paddle2onnx {
REGISTER_MAPPER(bilinear_interp, InterpolateMapper)
REGISTER_MAPPER(bilinear_interp_v2, InterpolateMapper)
REGISTER_MAPPER(nearest_interp, InterpolateMapper)
REGISTER_MAPPER(nearest_interp_v2, InterpolateMapper)
REGISTER_MAPPER(bicubic_interp_v2, InterpolateMapper)
REGISTER_MAPPER(linear_interp_v2, InterpolateMapper)
Expand Down Expand Up @@ -95,12 +96,21 @@ void InterpolateMapper::Opset11() {
out_size.push_back(out_w_);
size = helper_->Constant(ONNX_NAMESPACE::TensorProto::INT64, out_size);
} else {
std::vector<float> scale_;
GetAttr("scale", &scale_);
std::vector<float> scale_vector;
float padding = 1.0;
scale_.insert(scale_.begin(), padding);
scale_.insert(scale_.begin(), padding);
scale = helper_->Constant(ONNX_NAMESPACE::TensorProto::FLOAT, scale_);
GetAttr("scale", &scale_vector);
if (scale_vector.size() != 0){
scale_vector.insert(scale_vector.begin(), padding);
scale_vector.insert(scale_vector.begin(), padding);
}else{
float scale;
GetAttr("scale", &scale);
scale_vector.emplace_back(padding);
scale_vector.emplace_back(padding);
scale_vector.emplace_back(scale);
scale_vector.emplace_back(scale);
}
scale = helper_->Constant(ONNX_NAMESPACE::TensorProto::FLOAT, scale_vector);
}
}
std::string roi = helper_->Constant(ONNX_NAMESPACE::TensorProto::FLOAT, std::vector<float>());
Expand Down
2 changes: 1 addition & 1 deletion paddle2onnx/mapper/nn/interpolate.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class InterpolateMapper : public Mapper {

resize_mapper_["bilinear_interp"] = "linear";
resize_mapper_["bilinear_interp_v2"] = "linear";
resize_mapper_["nearest_interp"] = "nearest";
resize_mapper_["nearest_interp_v2"] = "nearest";
resize_mapper_["bicubic_interp_v2"] = "cubic";
resize_mapper_["linear_interp_v2"] = "linear";
Expand All @@ -40,7 +41,6 @@ class InterpolateMapper : public Mapper {

int32_t GetMinOpset(bool verbose = false);
void Opset11();

private:
std::string ComputeOutSize();
std::string ComputeScale();
Expand Down