diff --git a/paddle/fluid/inference/tensorrt/convert/scale_op.cc b/paddle/fluid/inference/tensorrt/convert/scale_op.cc index 361ed2239553228545ab70e9b825135e3de62953..a2cf5b487ce73322fd2cec96c5c7c22a606ebc6f 100644 --- a/paddle/fluid/inference/tensorrt/convert/scale_op.cc +++ b/paddle/fluid/inference/tensorrt/convert/scale_op.cc @@ -53,7 +53,8 @@ class ScaleOpConverter : public OpConverter { nvinfer1::ILayer* layer = nullptr; if (engine_->with_dynamic_shape()) { nvinfer1::ITensor* bias_tensor = - is_int ? Add1DConstantLayer(static_cast(bias)) + is_int ? Add1DConstantLayer( + static_cast(bias > 0 ? bias + 0.5 : bias - 0.5)) : Add1DConstantLayer(bias); bool is_bias_0 = (bias < 1e-06 && bias > -1e-06); @@ -75,7 +76,8 @@ class ScaleOpConverter : public OpConverter { is_scale_1 = false; } else { has_scale_tensor = false; - scale_tensor = is_int ? Add1DConstantLayer(static_cast(scale)) + scale_tensor = is_int ? Add1DConstantLayer(static_cast( + scale > 0 ? scale + 0.5 : scale - 0.5)) : Add1DConstantLayer(scale); is_scale_1 = ((scale - 1.0) < 1e-06 && (scale - 1.0) > -1e-06); }