1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
use ;
use cratepad_same;
// `AvgPool2dSame`
//
// # Reference Python
//
// ```python,ignore
// def avg_pool2d_same(
// x: torch.Tensor,
// kernel_size: List[int],
// stride: List[int],
// padding: List[int] = (0, 0),
// ceil_mode: bool = False,
// count_include_pad: bool = True,
// ):
// # FIXME how to deal with count_include_pad vs not for external padding?
// x = pad_same(x, kernel_size, stride)
// return F.avg_pool2d(x, kernel_size, stride, (0, 0), ceil_mode, count_include_pad)
//
// class AvgPool2d(conv.Module):
// def __init__(
// self,
// kernel_size: _size_2_t,
// stride: Optional[_size_2_t] = None,
// padding: _size_2_t = 0,
// ceil_mode: bool = False,
// count_include_pad: bool = True,
// divisor_override: Optional[int] = None,
// ) -> None:
// super().__init__()
// self.kernel_size = kernel_size
// self.stride = stride if (stride is not None) else kernel_size
// self.padding = padding
// self.ceil_mode = ceil_mode
// self.count_include_pad = count_include_pad
// self.divisor_override = divisor_override
//
// def forward(self, input: Tensor) -> Tensor:
// return F.avg_pool2d(
// input,
// self.kernel_size,
// self.stride,
// self.padding,
// self.ceil_mode,
// self.count_include_pad,
// self.divisor_override,
// )
//
// class AvgPool2dSame(conv.AvgPool2d):
// """Tensorflow like 'SAME' wrapper for 2D average pooling."""
// def __init__(
// self,
// kernel_size: _size_2_t,
// stride: Optional[_size_2_t] = None,
// padding: _size_2_t = 0,
// ceil_mode=False,
// count_include_pad=True,
// ):
// super(AvgPool2dSame, self).__init__(
// kernel_size=kernel_size,
// stride=stride,
// padding=(0, 0), # padding is dropped, is this a bug?
// ceil_mode=ceil_mode,
// count_include_pad=count_include_pad,
// )
//
// def forward(self, x):
// x = pad_same(x, self.kernel_size, self.stride)
// return F.avg_pool2d(
// x,
// self.kernel_size,
// self.stride,
// self.padding,
// self.ceil_mode,
// self.count_include_pad,
// )
// ```
/// [`AvgPool2dSame`] Configuration.
/// 2D average pooling with TensorFlow-style "SAME" padding.
///
/// Constructs via [`AvgPool2dSameConfig`] and `.init()`. The [`Self::forward`]
/// pass dynamically pads the input with [`pad_same`] so the output spatial size
/// matches TensorFlow's "SAME" convention, then applies the wrapped
/// [`AvgPool2d`].
///
/// Built by [`AvgPool2dSameConfig`].