Skip to content

Commit 3314d51

Browse files
chsasanksoumith
authored andcommitted
Add __repr__ to Avgpool and maxunpool layers (pytorch#2047)
1 parent 1ef1dd9 commit 3314d51

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

torch/nn/modules/pooling.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,12 @@ def forward(self, input, indices, output_size=None):
228228
return F.max_unpool1d(input, indices, self.kernel_size, self.stride,
229229
self.padding, output_size)
230230

231+
def __repr__(self):
232+
return self.__class__.__name__ + ' (' \
233+
+ 'size=' + str(self.kernel_size) \
234+
+ ', stride=' + str(self.stride) \
235+
+ ', padding=' + str(self.padding) + ')'
236+
231237

232238
class MaxUnpool2d(Module):
233239
r"""Computes a partial inverse of :class:`MaxPool2d`.
@@ -303,6 +309,12 @@ def forward(self, input, indices, output_size=None):
303309
return F.max_unpool2d(input, indices, self.kernel_size, self.stride,
304310
self.padding, output_size)
305311

312+
def __repr__(self):
313+
return self.__class__.__name__ + ' (' \
314+
+ 'size=' + str(self.kernel_size) \
315+
+ ', stride=' + str(self.stride) \
316+
+ ', padding=' + str(self.padding) + ')'
317+
306318

307319
class MaxUnpool3d(Module):
308320
r"""Computes a partial inverse of :class:`MaxPool3d`.
@@ -358,6 +370,12 @@ def forward(self, input, indices, output_size=None):
358370
return F.max_unpool3d(input, indices, self.kernel_size, self.stride,
359371
self.padding, output_size)
360372

373+
def __repr__(self):
374+
return self.__class__.__name__ + ' (' \
375+
+ 'size=' + str(self.kernel_size) \
376+
+ ', stride=' + str(self.stride) \
377+
+ ', padding=' + str(self.padding) + ')'
378+
361379

362380
class AvgPool1d(Module):
363381
r"""Applies a 1D average pooling over an input signal composed of several
@@ -417,6 +435,14 @@ def forward(self, input):
417435
input, self.kernel_size, self.stride, self.padding, self.ceil_mode,
418436
self.count_include_pad)
419437

438+
def __repr__(self):
439+
return self.__class__.__name__ + ' (' \
440+
+ 'size=' + str(self.kernel_size) \
441+
+ ', stride=' + str(self.stride) \
442+
+ ', padding=' + str(self.padding) \
443+
+ ', ceil_mode=' + str(self.ceil_mode) \
444+
+ ', count_include_pad=' + str(self.count_include_pad) + ')'
445+
420446

421447
class AvgPool2d(Module):
422448
r"""Applies a 2D average pooling over an input signal composed of several input
@@ -478,6 +504,14 @@ def forward(self, input):
478504
return F.avg_pool2d(input, self.kernel_size, self.stride,
479505
self.padding, self.ceil_mode, self.count_include_pad)
480506

507+
def __repr__(self):
508+
return self.__class__.__name__ + ' (' \
509+
+ 'size=' + str(self.kernel_size) \
510+
+ ', stride=' + str(self.stride) \
511+
+ ', padding=' + str(self.padding) \
512+
+ ', ceil_mode=' + str(self.ceil_mode) \
513+
+ ', count_include_pad=' + str(self.count_include_pad) + ')'
514+
481515

482516
class MaxPool3d(Module):
483517
r"""Applies a 3D max pooling over an input signal composed of several input
@@ -608,6 +642,11 @@ def __init__(self, kernel_size, stride=None):
608642
def forward(self, input):
609643
return F.avg_pool3d(input, self.kernel_size, self.stride)
610644

645+
def __repr__(self):
646+
return self.__class__.__name__ + ' (' \
647+
+ 'size=' + str(self.kernel_size) \
648+
+ ', stride=' + str(self.stride) + ')'
649+
611650

612651
class FractionalMaxPool2d(Module):
613652
"""Applies a 2D fractional max pooling over an input signal composed of several input planes.

0 commit comments

Comments
 (0)