modified error message and API doc for channel_last supported Op (#21002)

* modified error message for conv and conv_transpose, test=develop

* modified doc of conv and conv_transpose op, test=develop

* modified the expression for error message, test=develop

* modified error message for group_norm op, test=develop

* modified detail of Attr(data_format) or Attr(data_layout)

* add ValueError in API doc for maxout op, test=develop
revert-21172-masked_select_api
Zhang Ting 6 years ago committed by Aurelius84
parent 9247528252
commit 9cbe7bccba

@ -50,30 +50,28 @@ void ConvOp::InferShape(framework::InferShapeContext* ctx) const {
const std::string data_format = ctx->Attrs().Get<std::string>("data_format");
const bool channel_last = (data_format == "NHWC" || data_format == "NDHWC");
PADDLE_ENFORCE_EQ(in_dims.size() == 4 || in_dims.size() == 5, true,
"ShapeError: Conv input should be 4-D or 5-D tensor. But "
"received: %u-D Tensor,"
"the shape of Conv input is [%s]",
in_dims.size(), in_dims);
PADDLE_ENFORCE_EQ(
in_dims.size() == 4 || in_dims.size() == 5, true,
"ShapeError: the input of Op(conv) should be 4-D or 5-D Tensor. But "
"received: %u-D Tensor, the shape of input is [%s].",
in_dims.size(), in_dims);
PADDLE_ENFORCE_EQ(
in_dims.size(), filter_dims.size(),
"ShapeError: Conv input dimension and filter dimension should be the "
"equal."
"But received: the shape of Conv input is [%s], input dimension of Conv "
"input is [%d],"
"the shape of filter is [%s], the filter dimension of Conv is [%d]",
"ShapeError: the input's dimension size and filter's dimension size of "
"Op(conv) should be equal. But received: the shape of input is [%s], "
"the dimension size of input is [%d], the shape of filter is [%s], "
"the dimension size of filter is [%d].",
in_dims, in_dims.size(), filter_dims, filter_dims.size());
int in_sub_stride_size = in_dims.size() - strides.size();
PADDLE_ENFORCE_EQ(in_dims.size() - strides.size() == 2U, true,
"ShapeError: the dimension of input minus the dimension of "
"stride must be euqal to 2."
"But received: the dimension of input minus the dimension "
"of stride is [%d], the"
"input dimension of Conv is [%d], the shape of Conv input "
"is [%s], the stride"
"dimension of Conv is [%d]",
"ShapeError: the dimension size of input minus the size of "
"Attr(stride) must be euqal to 2 for Op(conv)."
"But received: the dimension size of input minus the size "
"of Attr(stride) is [%d], the "
"input's dimension size is [%d], the shape of input "
"is [%s], the Attr(stride)'s size is [%d].",
in_sub_stride_size, in_dims.size(), in_dims,
strides.size());
@ -83,16 +81,19 @@ void ConvOp::InferShape(framework::InferShapeContext* ctx) const {
PADDLE_ENFORCE_EQ(
input_channels, filter_dims[1] * groups,
"ShapeError: The number of input channels should be equal to filter "
"channels * groups. But received: the input channels is [%d], the shape"
"of input is [%s], the filter channel is [%d], the shape of filter is "
"[%s],"
"the groups is [%d]",
in_dims[1], in_dims, filter_dims[1], filter_dims, groups);
"channels * groups for Op(conv). But received: the input's channels is "
"[%d], the shape "
"of input is [%s], the filter's channel is [%d], the shape of filter is "
"[%s], the groups is [%d], the data_format is %s. The error may come "
"from wrong data_format setting.",
input_channels, in_dims, filter_dims[1], filter_dims, groups,
data_format);
PADDLE_ENFORCE_EQ(
filter_dims[0] % groups, 0,
"ShapeError: The number of output channels should be divided by groups."
"But received: the output channels is [%d], the shape of filter is [%s]"
"(the first dimension of filter is output channel), the groups is [%d]",
"ShapeError: The number of output channels of Op(conv) should be divided "
"by groups. "
"But received: the output channels is [%d], the shape of filter is [%s] "
"(the first dimension of filter is output channel), the groups is [%d].",
filter_dims[0], filter_dims, groups);
framework::DDim in_data_dims;

@ -46,30 +46,48 @@ void ConvTransposeOp::InferShape(framework::InferShapeContext* ctx) const {
int groups = ctx->Attrs().Get<int>("groups");
std::string padding_algorithm =
ctx->Attrs().Get<std::string>("padding_algorithm");
const DataLayout data_layout = framework::StringToDataLayout(
ctx->Attrs().Get<std::string>("data_format"));
const std::string data_layout_str =
ctx->Attrs().Get<std::string>("data_format");
const framework::DataLayout data_layout =
framework::StringToDataLayout(data_layout_str);
PADDLE_ENFORCE_EQ(in_dims.size() == 4 || in_dims.size() == 5, true,
"ConvTransposeOp intput should be 4-D or 5-D tensor.");
PADDLE_ENFORCE_EQ(in_dims.size(), filter_dims.size(),
"ConvTransposeOp input dimension and filter dimension "
"should be the same.");
"ShapeError: input of Op(conv_transpose) should be 4-D or "
"5-D Tensor. But received: %u-D Tensor, "
"the shape of input is [%s]",
in_dims.size(), in_dims);
PADDLE_ENFORCE_EQ(
in_dims.size(), filter_dims.size(),
"ShapeError: the input's dimension size and filter's dimension size of "
"Op (conv_transpose) should be equal. But received: the shape of input "
"is [%s], the dimension size of input is [%d], the shape of filter is "
"[%s], the dimension size of filter is [%d]. ",
in_dims, in_dims.size(), filter_dims, filter_dims.size());
int in_sub_stride_size = in_dims.size() - strides.size();
PADDLE_ENFORCE_EQ(
in_dims.size() - strides.size(), 2U,
"ConvTransposeOp input dimension and strides dimension should "
"be consistent.");
"ShapeError: the input's dimension size minus Attr(stride)'s size must "
"be euqal to 2 for Op(conv_transpose). But received: [%d], the "
"input's dimension size is [%d], the shape of input "
"is [%s], the Attr(stride)'s size is [%d].",
in_sub_stride_size, in_dims.size(), in_dims, strides.size());
if (output_size.size())
PADDLE_ENFORCE_EQ(output_size.size(), strides.size(),
"ConvTransposeOp output_size dimension and strides "
"dimension should be the same.");
PADDLE_ENFORCE_EQ(
output_size.size(), strides.size(),
"The Attr(output_size) and Attr(stride) of Op(conv_transpose) "
"should be the same.");
const int64_t C =
(data_layout != DataLayout::kNHWC ? in_dims[1]
: in_dims[in_dims.size() - 1]);
PADDLE_ENFORCE_EQ(
C, filter_dims[0],
"The number of input channels of Op(ConvTransposeOp) should "
"be equal to the number of filter's channels.");
"ShapeError: The number of input channels should be equal to filter "
"channels for Op(conv_transpose). But received: the input's channels is "
"[%d], the shape of input is [%s], the filter's channels is [%d], the "
"shape of filter is [%s]. The data_format is %s."
"The error may come from wrong data_format setting.",
C, in_dims, filter_dims[0], filter_dims, data_layout_str);
framework::DDim in_data_dims;
if (data_layout != DataLayout::kNHWC) {

@ -39,24 +39,57 @@ class GroupNormOp : public framework::OperatorWithKernel {
PADDLE_ENFORCE(ctx->HasOutput("Variance"),
"Output(Variance) of GroupNormOp should not be null.");
auto x_dim = ctx->GetInputDim("X");
const DataLayout data_layout = framework::StringToDataLayout(
ctx->Attrs().Get<std::string>("data_layout"));
const std::string data_layout_str =
ctx->Attrs().Get<std::string>("data_layout");
const framework::DataLayout data_layout =
framework::StringToDataLayout(data_layout_str);
const int64_t channel_num =
(data_layout == DataLayout::kNCHW ? x_dim[1] : x_dim[x_dim.size() - 1]);
auto batch_size = x_dim[0];
auto groups = ctx->Attrs().Get<int>("groups");
PADDLE_ENFORCE_LE(
groups, channel_num,
"'groups' must be less equal than the number of channels.");
PADDLE_ENFORCE_GE(groups, 1, "'groups' must be greater equal than 1.");
"ValueError: the Attr(groups) of Op(group_norm) must be less than or "
"equal to the number of channels. "
"But received: groups is [%s], channels is [%s], the Attr(data_layout) "
"is [%s]. The error may come from wrong data_layout setting.",
groups, channel_num, data_layout_str);
PADDLE_ENFORCE_GE(
groups, 1,
"ValueError: the Attr(groups) of Op(group_norm) must be "
"greater than or equal to 1. But received: groups is [%s].",
groups);
if (ctx->HasInput("Scale")) {
PADDLE_ENFORCE_EQ(ctx->GetInputDim("Scale").size(), 1UL);
PADDLE_ENFORCE_EQ(ctx->GetInputDim("Scale")[0], channel_num);
PADDLE_ENFORCE_EQ(
ctx->GetInputDim("Scale").size(), 1UL,
"ShapeError: the Input(Scale) of Op(group_norm) should be 1-D "
"Tensor. "
"But received: %u-D Tensor, the shape of Input(Scale) is [%s].",
ctx->GetInputDim("Scale").size(), ctx->GetInputDim("Scale"));
PADDLE_ENFORCE_EQ(
ctx->GetInputDim("Scale")[0], channel_num,
"ShapeError: the Input(Scale)'s first dimension size of "
"Op(group_norm) must be equal to the number of channels. "
"But received: the Input(Scale)'s first dimension size is [%s], the "
"channels is [%s], the Attr(data_layout) is [%s]. The error may come "
"from wrong data_layout setting.",
ctx->GetInputDim("Scale")[0], channel_num, data_layout_str);
}
if (ctx->HasInput("Bias")) {
PADDLE_ENFORCE_EQ(ctx->GetInputDim("Bias").size(), 1UL);
PADDLE_ENFORCE_EQ(ctx->GetInputDim("Bias")[0], channel_num);
PADDLE_ENFORCE_EQ(
ctx->GetInputDim("Bias").size(), 1UL,
"ShapeError: the Input(Bias) of Op(group_norm) should be 1-D Tensor. "
"But received: %u-D Tensor, the shape of Input(Bias) is [%s].",
ctx->GetInputDim("Bias").size(), ctx->GetInputDim("Bias"));
PADDLE_ENFORCE_EQ(
ctx->GetInputDim("Bias")[0], channel_num,
"ShapeError: the Input(Bias)'s first dimension size of "
"Op(group_norm) must be equal to the number of channels. "
"But received: the Input(Bias)'s first dimension size is [%s], the "
"channels is [%s], the Attr(data_layout) is [%s]. The error may come "
"from wrong data_layout setting.",
ctx->GetInputDim("Bias")[0], channel_num, data_layout_str);
}
ctx->SetOutputDim("Y", ctx->GetInputDim("X"));

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save