• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2015 The TensorFlow Authors. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7     http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations 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 
28 namespace tensorflow {
29 
30 class 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. Two 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_padding
40 //             attribute.
41 // The padded area is zero-filled.
42 enum Padding {
43   VALID = 1,     // No padding.
44   SAME = 2,      // Input and output layers have the same size.
45   EXPLICIT = 3,  // Padding is explicitly specified
46 };
47 
48 // Returns an error if the padding attributes are invalid.
49 Status CheckValidPadding(Padding padding_type,
50                          const std::vector<int64>& explicit_paddings,
51                          int num_dims, TensorFormat data_format);
52 
53 // Return the string containing the list of valid padding types, that can be
54 // used as an Attr() in REGISTER_OP.
55 string GetPaddingAttrString();
56 
57 // Like GetPaddingAttrString(), but also includes EXPLICIT.
58 string GetPaddingAttrStringWithExplicit();
59 
60 string GetExplicitPaddingsAttrString();
61 
62 // Specialization to parse an attribute directly into a Padding enum.
63 Status GetNodeAttr(const NodeDef& node_def, StringPiece attr_name,
64                    Padding* value);
65 
66 }  // end namespace tensorflow
67 
68 #endif  // TENSORFLOW_CORE_UTIL_PADDING_H_
69