Skip to content

Commit

Permalink
Add __repr__ to Avgpool and maxunpool layers (pytorch#2047)
Browse files Browse the repository at this point in the history
  • Loading branch information
chsasank authored and soumith committed Jul 11, 2017
1 parent 1ef1dd9 commit 3314d51
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions torch/nn/modules/pooling.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,12 @@ def forward(self, input, indices, output_size=None):
return F.max_unpool1d(input, indices, self.kernel_size, self.stride,
self.padding, output_size)

def __repr__(self):
return self.__class__.__name__ + ' (' \
+ 'size=' + str(self.kernel_size) \
+ ', stride=' + str(self.stride) \
+ ', padding=' + str(self.padding) + ')'


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

def __repr__(self):
return self.__class__.__name__ + ' (' \
+ 'size=' + str(self.kernel_size) \
+ ', stride=' + str(self.stride) \
+ ', padding=' + str(self.padding) + ')'


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

def __repr__(self):
return self.__class__.__name__ + ' (' \
+ 'size=' + str(self.kernel_size) \
+ ', stride=' + str(self.stride) \
+ ', padding=' + str(self.padding) + ')'


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

def __repr__(self):
return self.__class__.__name__ + ' (' \
+ 'size=' + str(self.kernel_size) \
+ ', stride=' + str(self.stride) \
+ ', padding=' + str(self.padding) \
+ ', ceil_mode=' + str(self.ceil_mode) \
+ ', count_include_pad=' + str(self.count_include_pad) + ')'


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

def __repr__(self):
return self.__class__.__name__ + ' (' \
+ 'size=' + str(self.kernel_size) \
+ ', stride=' + str(self.stride) \
+ ', padding=' + str(self.padding) \
+ ', ceil_mode=' + str(self.ceil_mode) \
+ ', count_include_pad=' + str(self.count_include_pad) + ')'


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

def __repr__(self):
return self.__class__.__name__ + ' (' \
+ 'size=' + str(self.kernel_size) \
+ ', stride=' + str(self.stride) + ')'


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

0 comments on commit 3314d51

Please sign in to comment.