1/* Copyright 2015 The TensorFlow Authors. All Rights Reserved.
2
3Licensed under the Apache License, Version 2.0 (the "License");
4you may not use this file except in compliance with the License.
5You may obtain a copy of the License at
6
7 http://www.apache.org/licenses/LICENSE-2.0
8
9Unless required by applicable law or agreed to in writing, software
10distributed under the License is distributed on an "AS IS" BASIS,
11WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12See the License for the specific language governing permissions and
13limitations under the License.
14==============================================================================*/
15
16#ifndef TENSORFLOW_CORE_UTIL_PADDING_H_
17#define TENSORFLOW_CORE_UTIL_PADDING_H_
18
19// This file contains helper routines to deal with padding in various ops and
20// kernels.
21
22#include <string>
23#include <vector>
24
25#include "tensorflow/core/lib/core/status.h"
26#include "tensorflow/core/util/tensor_format.h"
27
28namespace tensorflow {
29
30class NodeDef;
31
32// Padding: the padding we apply to the input tensor along the rows and columns
33// dimensions. This is usually used to make sure that the spatial dimensions do
34// not shrink when we progress with convolutions. Three types of padding are
35// supported:
36// VALID: No padding is carried out.
37// SAME: The pad value is computed so that the output will have the same
38// dimensions as the input.
39// EXPLICIT: The user specifies the pad values in the explicit_paddings
40// attribute.
41// The padded area is typically zero-filled. For pooling ops, the padded area is
42// instead ignored. For max pool, this is equivalent to padding with -infinity.
43enum Padding {
44 VALID = 1, // No padding.
45 SAME = 2, // Input and output layers have the same size.
46 EXPLICIT = 3, // Padding is explicitly specified
47};
48
49// Returns an error if the padding attributes are invalid.
50Status CheckValidPadding(Padding padding_type,
51 const std::vector<int64_t>& explicit_paddings,
52 int num_dims, TensorFormat data_format);
53
54// Return the string containing the list of valid padding types, that can be
55// used as an Attr() in REGISTER_OP.
56std::string GetPaddingAttrString();
57
58// Like GetPaddingAttrString(), but also includes EXPLICIT.
59std::string GetPaddingAttrStringWithExplicit();
60
61std::string GetExplicitPaddingsAttrString();
62
63// Sets padding value based on the given string padding value.
64Status GetPaddingFromString(StringPiece str_value, Padding* value);
65
66} // end namespace tensorflow
67
68#endif // TENSORFLOW_CORE_UTIL_PADDING_H_
69