MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / Interpolate2DInferShapeCheck

Function Interpolate2DInferShapeCheck

paddle/phi/infermeta/multiary.cc:3396–3547  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3394}
3395
3396static void Interpolate2DInferShapeCheck(
3397 const MetaTensor& x,
3398 const MetaTensor& out_size,
3399 const paddle::optional<std::vector<const MetaTensor*>>& size_tensor,
3400 const MetaTensor& scale_tensor,
3401 const std::string& data_layout_str,
3402 int out_d,
3403 int out_h,
3404 int out_w,
3405 const std::vector<double>& scale,
3406 const std::string& interp_method,
3407 bool align_corners,
3408 int align_mode,
3409 MetaTensor* output,
3410 MetaConfig config) {
3411 auto dim_x = x.dims();
3412
3413 PADDLE_ENFORCE_EQ(
3414 ("bilinear" == interp_method || "nearest" == interp_method ||
3415 "bicubic" == interp_method),
3416 true,
3417 common::errors::InvalidArgument(
3418 "Interpolation method can only be \"bilinear\" or \"nearest\" when "
3419 "Input(X) dimension is 4, but got method = %s.",
3420 interp_method));
3421 const DataLayout data_layout = StringToDataLayout(data_layout_str);
3422
3423 for (int i = 2; i < dim_x.size(); ++i) {
3424 PADDLE_ENFORCE_NE(dim_x[i],
3425 0,
3426 common::errors::InvalidArgument(
3427 "The shape of input(x) should be larger "
3428 "than 0, but received shape[%d] is %d ",
3429 i,
3430 dim_x[i]));
3431 }
3432
3433 if (size_tensor && !size_tensor->empty()) {
3434 // top priority size
3435 auto inputs_name = size_tensor.get();
3436 PADDLE_ENFORCE_EQ(
3437 inputs_name.size(),
3438 2,
3439 common::errors::InvalidArgument(
3440 "Input(SizeTensor)'size of Op(interpolate) must be 2. "
3441 "Attr(out_shape)'s length must be 2 for 4-D input "
3442 "tensor, but got size = %d .",
3443 inputs_name.size()));
3444 DDim dim_out;
3445 if (data_layout == DataLayout::NCHW) {
3446 dim_out = {dim_x[0], dim_x[1], out_h, out_w};
3447 } else {
3448 dim_out = {dim_x[0], out_h, out_w, dim_x[3]};
3449 }
3450 output->set_dims(dim_out);
3451 output->set_dtype(x.dtype());
3452
3453 return;

Callers 1

InterpolateInferMetaFunction · 0.85

Calls 9

StringToDataLayoutFunction · 0.85
dimsMethod · 0.45
sizeMethod · 0.45
emptyMethod · 0.45
getMethod · 0.45
set_dimsMethod · 0.45
set_dtypeMethod · 0.45
dtypeMethod · 0.45
share_lodMethod · 0.45

Tested by

no test coverage detected