Skip to content

Commit

Permalink
Fix padding mess. (onnx#268)
Browse files Browse the repository at this point in the history
* Fix padding mess.

* Address feedbacks.
  • Loading branch information
ebarsoum authored and bddppq committed Nov 16, 2017
1 parent b84ea9f commit 316f605
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 60 deletions.
16 changes: 8 additions & 8 deletions docs/Operators.md
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ expect(node, inputs=[x, y], outputs=[x + y],
<dt><tt>kernel_shape</tt> : list of ints</dt>
<dd>The size of the kernel along each axis.</dd>
<dt><tt>pads</tt> : list of ints</dt>
<dd>Padding for lower and upper side along each axis, it can take any value greater than or equal to 0. The value represent the number of pixels added to the lower and upper part of the corresponding axis. So `pads` will have two values per axis, first value corresponding to the number of pixels added to the begining of the axis and the second value corresponding to the number of pixels add at the end of the axis. This attribute cannot be used simultaneously with auto_pad attribute.</dd>
<dd>Padding for the begining and ending along each axis, it can take any value greater than or equal to 0. The value represent the number of pixels added to the begining and end part of the corresponding axis. `pads` format should be as follow [x1_begin, x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels added at the begining of axis `i` and xi_end, the number of pixels added at the end of axis `i`. This attribute cannot be used simultaneously with auto_pad attribute.</dd>
<dt><tt>strides</tt> : list of ints</dt>
<dd>Stride along each axis.</dd>
</dl>
Expand Down Expand Up @@ -689,7 +689,7 @@ expect(node, inputs=[], outputs=[values],
<dt><tt>kernel_shape</tt> : list of ints</dt>
<dd>The shape of the convolution kernel.</dd>
<dt><tt>pads</tt> : list of ints</dt>
<dd>Padding for lower and upper side along each axis, it can take any value greater than or equal to 0. The value represent the number of pixels added to the lower and upper part of the corresponding axis. So `pads` will have two values per axis, first value corresponding to the number of pixels added to the begining of the axis and the second value corresponding to the number of pixels add at the end of the axis. The order should be axis_0_begin, axis_0_end, axis_1_begin, ..., axis_n_begin, axis_n_end, n is kernel's dimension.This attribute cannot be used simultaneously with auto_pad attribute.</dd>
<dd>Padding for the begining and ending along each axis, it can take any value greater than or equal to 0. The value represent the number of pixels added to the begining and end part of the corresponding axis. `pads` format should be as follow [x1_begin, x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels added at the begining of axis `i` and xi_end, the number of pixels added at the end of axis `i`. This attribute cannot be used simultaneously with auto_pad attribute.</dd>
<dt><tt>strides</tt> : list of ints</dt>
<dd>stride along each axis.</dd>
</dl>
Expand Down Expand Up @@ -729,7 +729,7 @@ expect(node, inputs=[], outputs=[values],

<dl>
<dt><tt>auto_pad</tt> : string</dt>
<dd>auto_pad must be either SAME_UPPER, SAME_LOWER or VALID. Where SAME_UPPER or SAME_LOWER mean pad the input so that the ouput size match the input.In case of odd number add the extra padding at the end for SAME_UPPER and at the begining for SAME_LOWER. VALID mean no padding.</dd>
<dd>auto_pad must be either SAME_UPPER, SAME_LOWER or VALID. Where SAME_UPPER or SAME_LOWER mean pad the input so that the ouput size match the input.In case of odd number add the extra padding at the end for SAME_UPPER and at the begining for SAME_LOWER. VALID mean no padding. DEPRECATION NOTE: auto_pad is only intended to support legacy uses, and for framework authors, one is explicitly encouraged to use explicit padding specified in the pads attribute.</dd>
<dt><tt>dilations</tt> : list of ints</dt>
<dd>dilation value along each axis of the filter.</dd>
<dt><tt>group</tt> : int</dt>
Expand All @@ -739,7 +739,7 @@ expect(node, inputs=[], outputs=[values],
<dt><tt>output_shape</tt> : list of ints</dt>
<dd>The shape of the output.</dd>
<dt><tt>pads</tt> : list of ints</dt>
<dd>Padding for lower and upper side along each axis, it can take any value greater than or equal to 0. The value represent the number of pixels added to the lower and upper part of the corresponding axis. So `pads` will have two values per axis, first value corresponding to the number of pixels added to the begining of the axis and the second value corresponding to the number of pixels add at the end of the axis. This attribute cannot be used simultaneously with auto_pad attribute.</dd>
<dd>Padding for the begining and ending along each axis, it can take any value greater than or equal to 0. The value represent the number of pixels added to the begining and end part of the corresponding axis. `pads` format should be as follow [x1_begin, x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels added at the begining of axis `i` and xi_end, the number of pixels added at the end of axis `i`. This attribute cannot be used simultaneously with auto_pad attribute.</dd>
<dt><tt>strides</tt> : list of ints</dt>
<dd>stride along each axis.</dd>
</dl>
Expand Down Expand Up @@ -1958,13 +1958,13 @@ expect(node, inputs=[], outputs=[values],

<dl>
<dt><tt>auto_pad</tt> : string</dt>
<dd>auto_pad must be either SAME_UPPER, SAME_LOWER or VALID. Where SAME_UPPER or SAME_LOWER mean pad the input so that the ouput size match the input.In case of odd number add the extra padding at the end for SAME_UPPER and at the begining for SAME_LOWER. VALID mean no padding, therefore, read the pixel values from the pads attribute. DEPRECATION NOTE: auto_pad is only intended to support legacy uses, and for framework authors, one is explicitly encouraged to use explicit padding specified in the pads attribute.</dd>
<dd>auto_pad must be either SAME_UPPER, SAME_LOWER or VALID. Where SAME_UPPER or SAME_LOWER mean pad the input so that the ouput size match the input.In case of odd number add the extra padding at the end for SAME_UPPER and at the begining for SAME_LOWER. VALID mean no padding. DEPRECATION NOTE: auto_pad is only intended to support legacy uses, and for framework authors, one is explicitly encouraged to use explicit padding specified in the pads attribute.</dd>
<dt><tt>kernel_shape</tt> : list of ints</dt>
<dd>The size of the kernel along each axis.</dd>
<dt><tt>p</tt> : float</dt>
<dd>p value of the Lp norm used to pool over the input data, default is 2.0.</dd>
<dt><tt>pads</tt> : list of ints</dt>
<dd>Padding for lower and upper side along each axis, it can take any value greater than or equal to 0. The value represent the number of pixels added to the lower and upper part of the corresponding axis. So `pads` will have two values per axis, first value corresponding to the number of pixels added to the begining of the axis and the second value corresponding to the number of pixels add at the end of the axis.</dd>
<dd>Padding for the begining and ending along each axis, it can take any value greater than or equal to 0. The value represent the number of pixels added to the begining and end part of the corresponding axis. `pads` format should be as follow [x1_begin, x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels added at the begining of axis `i` and xi_end, the number of pixels added at the end of axis `i`. This attribute cannot be used simultaneously with auto_pad attribute.</dd>
<dt><tt>strides</tt> : list of ints</dt>
<dd>Stride along each axis.</dd>
</dl>
Expand Down Expand Up @@ -2101,7 +2101,7 @@ expect(node, inputs=[a, b], outputs=[c],
<dt><tt>kernel_shape</tt> : list of ints</dt>
<dd>The size of the kernel along each axis.</dd>
<dt><tt>pads</tt> : list of ints</dt>
<dd>Padding for lower and upper side along each axis, it can take any value greater than or equal to 0. The value represent the number of pixels added to the lower and upper part of the corresponding axis. So `pads` will have two values per axis, first value corresponding to the number of pixels added to the begining of the axis and the second value corresponding to the number of pixels add at the end of the axis. This attribute cannot be used simultaneously with auto_pad attribute.</dd>
<dd>Padding for the begining and ending along each axis, it can take any value greater than or equal to 0. The value represent the number of pixels added to the begining and end part of the corresponding axis. `pads` format should be as follow [x1_begin, x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels added at the begining of axis `i` and xi_end, the number of pixels added at the end of axis `i`. This attribute cannot be used simultaneously with auto_pad attribute.</dd>
<dt><tt>strides</tt> : list of ints</dt>
<dd>Stride along each axis.</dd>
</dl>
Expand Down Expand Up @@ -2436,7 +2436,7 @@ expect(node, inputs=[a, b], outputs=[c],
<dt><tt>mode</tt> : string</dt>
<dd>Three modes: constant(default), reflect, edge</dd>
<dt><tt>paddings</tt> : list of ints (required)</dt>
<dd>List of integers indicate the padding sizes, paddings's length should be the double of input's dimension. The order should be axis_0_begin, axis_0_end, axis_1_begin, ..., axis_n_begin, axis_n_end, n is input's dimension.</dd>
<dd>List of integers indicate the padding element count at the begining and end of each axis, for 2D it is the number of pixel. `paddings` rank should be double of the input's rank. `paddings` format should be as follow [x1_begin, x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels added at the begining of axis `i` and xi_end, the number of pixels added at the end of axis `i`.</dd>
<dt><tt>value</tt> : float</dt>
<dd>One float, indicates the value to be filled, default is 0</dd>
</dl>
Expand Down
72 changes: 24 additions & 48 deletions onnx/defs/nn/defs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,22 @@ using namespace onnx;

using AttrType = onnx::OpSchema::AttrType;

namespace onnx {
static std::string pads_doc = "Padding for the begining and ending along each axis, it can take any value greater "
"than or equal to 0. The value represent the number of pixels added to the begining "
"and end part of the corresponding axis. `pads` format should be as follow "
"[x1_begin, x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels "
"added at the begining of axis `i` and xi_end, the number of pixels added at "
"the end of axis `i`. This attribute cannot be used simultaneously with "
"auto_pad attribute.";
static std::string auto_pad_doc = "auto_pad must be either SAME_UPPER, SAME_LOWER or VALID. Where "
"SAME_UPPER or SAME_LOWER mean pad the input so that the ouput size match the input."
"In case of odd number add the extra padding at the end for SAME_UPPER and at the "
"begining for SAME_LOWER. VALID mean no padding. DEPRECATION NOTE: auto_pad is "
"only intended to support legacy uses, and for framework authors, one is explicitly "
"encouraged to use explicit padding specified in the pads attribute.";
}

namespace onnx {
std::function<void(OpSchema&)> PoolOpSchemaGenerator(const char* name, const char* opName) {
return [=](OpSchema& schema) {
Expand All @@ -27,20 +43,10 @@ namespace onnx {
"Stride along each axis.",
AttrType::INTS);
schema.Attr("auto_pad",
"auto_pad must be either SAME_UPPER, SAME_LOWER or VALID. Where "
"SAME_UPPER or SAME_LOWER mean pad the input so that the ouput size match the input."
"In case of odd number add the extra padding at the end for SAME_UPPER and at the "
"begining for SAME_LOWER. VALID mean no padding. DEPRECATION NOTE: auto_pad is "
"only intended to support legacy uses, and for framework authors, one is explicitly "
"encouraged to use explicit padding specified in the pads attribute.",
auto_pad_doc.c_str(),
AttrType::STRING);
schema.Attr("pads",
"Padding for lower and upper side along each axis, it can take any value greater "
"than or equal to 0. The value represent the number of pixels added to the lower "
"and upper part of the corresponding axis. So `pads` will have two values per axis, "
"first value corresponding to the number of pixels added to the begining of the axis "
"and the second value corresponding to the number of pixels add at the end of the axis. "
"This attribute cannot be used simultaneously with auto_pad attribute.",
pads_doc.c_str(),
AttrType::INTS);
schema.Input(0,
"X",
Expand Down Expand Up @@ -90,20 +96,10 @@ namespace onnx {
"Stride along each axis.",
AttrType::INTS);
schema.Attr("auto_pad",
"auto_pad must be either SAME_UPPER, SAME_LOWER or VALID. Where "
"SAME_UPPER or SAME_LOWER mean pad the input so that the ouput size match the input."
"In case of odd number add the extra padding at the end for SAME_UPPER and at the "
"begining for SAME_LOWER. VALID mean no padding, therefore, read the pixel values "
"from the pads attribute. DEPRECATION NOTE: auto_pad is "
"only intended to support legacy uses, and for framework authors, one is explicitly "
"encouraged to use explicit padding specified in the pads attribute.",
auto_pad_doc.c_str(),
AttrType::STRING);
schema.Attr("pads",
"Padding for lower and upper side along each axis, it can take any value greater "
"than or equal to 0. The value represent the number of pixels added to the lower "
"and upper part of the corresponding axis. So `pads` will have two values per axis, "
"first value corresponding to the number of pixels added to the begining of the axis "
"and the second value corresponding to the number of pixels add at the end of the axis.",
pads_doc.c_str(),
AttrType::INTS);
schema.Attr("p",
"p value of the Lp norm used to pool over the input data, default is 2.0.",
Expand Down Expand Up @@ -220,22 +216,10 @@ computes the output.)DOC";
"stride along each axis.",
AttrType::INTS);
schema.Attr("auto_pad",
"auto_pad must be either SAME_UPPER, SAME_LOWER or VALID. Where "
"SAME_UPPER or SAME_LOWER mean pad the input so that the ouput size match the input."
"In case of odd number add the extra padding at the end for SAME_UPPER and at the "
"begining for SAME_LOWER. VALID mean no padding. DEPRECATION NOTE: auto_pad is "
"only intended to support legacy uses, and for framework authors, one is explicitly "
"encouraged to use explicit padding specified in the pads attribute.",
auto_pad_doc.c_str(),
AttrType::STRING);
schema.Attr("pads",
"Padding for lower and upper side along each axis, it can take any value greater "
"than or equal to 0. The value represent the number of pixels added to the lower "
"and upper part of the corresponding axis. So `pads` will have two values per axis, "
"first value corresponding to the number of pixels added to the begining of the axis "
"and the second value corresponding to the number of pixels add at the end of the axis. "
"The order should be axis_0_begin, axis_0_end, axis_1_begin, ..., axis_n_begin, "
"axis_n_end, n is kernel's dimension."
"This attribute cannot be used simultaneously with auto_pad attribute.",
pads_doc.c_str(),
AttrType::INTS);
schema.Attr("group",
"number of groups input channels and output channels are divided into",
Expand Down Expand Up @@ -296,18 +280,10 @@ and computes the output.)DOC";
"stride along each axis.",
AttrType::INTS);
schema.Attr("auto_pad",
"auto_pad must be either SAME_UPPER, SAME_LOWER or VALID. Where "
"SAME_UPPER or SAME_LOWER mean pad the input so that the ouput size match the input."
"In case of odd number add the extra padding at the end for SAME_UPPER and at the "
"begining for SAME_LOWER. VALID mean no padding.",
auto_pad_doc.c_str(),
AttrType::STRING);
schema.Attr("pads",
"Padding for lower and upper side along each axis, it can take any value greater "
"than or equal to 0. The value represent the number of pixels added to the lower "
"and upper part of the corresponding axis. So `pads` will have two values per axis, "
"first value corresponding to the number of pixels added to the begining of the axis "
"and the second value corresponding to the number of pixels add at the end of the axis. "
"This attribute cannot be used simultaneously with auto_pad attribute.",
pads_doc.c_str(),
AttrType::INTS);
schema.Attr("group",
"number of groups input channels and output channels are divided into",
Expand Down
10 changes: 6 additions & 4 deletions onnx/defs/tensor/defs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,12 @@ OPERATOR_SCHEMA(Pad)
.NumInputs(1)
.NumOutputs(1)
.Attr("paddings",
"List of integers indicate the padding sizes, paddings's length"
" should be the double of input's dimension. "
"The order should be axis_0_begin, axis_0_end, axis_1_begin, ...,"
" axis_n_begin, axis_n_end, n is input's dimension.",
"List of integers indicate the padding element count at the "
"begining and end of each axis, for 2D it is the number of pixel. "
"`paddings` rank should be double of the input's rank. `paddings` format should be as follow "
"[x1_begin, x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels "
"added at the begining of axis `i` and xi_end, the number of pixels added at "
"the end of axis `i`.",
AttrType::INTS,
true)
.Attr("mode",
Expand Down

0 comments on commit 316f605

Please sign in to comment.