Skip to content

MaxUnpool2d segfaults for some configurations #67

@fmassa

Description

@fmassa

Having the output of MaxUnpool2d to be computed as follows is error-prone.

out_height = (input.size(2) - 1) * self.dh + self.kh - 2*self.padh
out_width = (input.size(3) - 1) * self.dw + self.kw - 2*self.padw

For some configurations of input size and stride/kernel size, there are pixel loss in the boundaries due to integer division, so when unpooling we might end up by having accesses which are out of the output size defined by the above equation, or giving completely wrong results.
Here is a test case:

import torch
import torch.nn as nn
import torch.autograd as autograd

m = nn.MaxPool2d(3, stride=2, return_indices = True)
mu = nn.MaxUnpool2d(3, stride=2)
input_tensor = torch.rand(1, 1, 6, 6)
input_tensor[0][0][5][5] = 2
input = autograd.Variable(input_tensor)
output, indices = m.forward(input)
unpooled_output = mu.forward(output, indices)

Curiously, the segfault is doesn't happen all the time, but instead it just raises an out-of-range error, or the outputs max are not in the right position.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions