我们从Python开源项目中,提取了以下9个代码示例,用于说明如何使用torch.nn.MaxUnpool2d()。
def test_MaxUnpool2d_output_size(self): m = nn.MaxPool2d(3, stride=2, return_indices=True) mu = nn.MaxUnpool2d(3, stride=2) big_t = torch.rand(1, 1, 6, 6) big_t[0][0][4][4] = 100 output_big, indices_big = m(Variable(big_t)) self.assertRaises(RuntimeError, lambda: mu(output_big, indices_big)) small_t = torch.rand(1, 1, 5, 5) for i in range(0, 4, 2): for j in range(0, 4, 2): small_t[:,:,i,j] = 100 output_small, indices_small = m(Variable(small_t)) for h in range(3, 10): for w in range(3, 10): if 4 <= h <= 6 and 4 <= w <= 6: size = (h, w) if h == 5: size = torch.LongStorage(size) elif h == 6: size = torch.LongStorage((1, 1) + size) mu(output_small, indices_small, output_size=size) else: self.assertRaises(ValueError, lambda: mu(output_small, indices_small, (h, w)))
def test_MaxUnpool2d_output_size(self): m = nn.MaxPool2d(3, stride=2, return_indices=True) mu = nn.MaxUnpool2d(3, stride=2) big_t = torch.rand(1, 1, 6, 6) big_t[0][0][4][4] = 100 output_big, indices_big = m(Variable(big_t)) self.assertRaises(RuntimeError, lambda: mu(output_big, indices_big)) small_t = torch.rand(1, 1, 5, 5) for i in range(0, 4, 2): for j in range(0, 4, 2): small_t[:, :, i, j] = 100 output_small, indices_small = m(Variable(small_t)) for h in range(3, 10): for w in range(3, 10): if 4 <= h <= 6 and 4 <= w <= 6: size = (h, w) if h == 5: size = torch.LongStorage(size) elif h == 6: size = torch.LongStorage((1, 1) + size) mu(output_small, indices_small, output_size=size) else: self.assertRaises(ValueError, lambda: mu(output_small, indices_small, (h, w)))
def __init__(self, in_size, out_size): super(segnetUp2, self).__init__() self.unpool = nn.MaxUnpool2d(2, 2) self.conv1 = conv2DBatchNormRelu(in_size, in_size, 3, 1, 1) self.conv2 = conv2DBatchNormRelu(in_size, out_size, 3, 1, 1)
def __init__(self, in_size, out_size): super(segnetUp3, self).__init__() self.unpool = nn.MaxUnpool2d(2, 2) self.conv1 = conv2DBatchNormRelu(in_size, in_size, 3, 1, 1) self.conv2 = conv2DBatchNormRelu(in_size, in_size, 3, 1, 1) self.conv3 = conv2DBatchNormRelu(in_size, out_size, 3, 1, 1)
def __init__(self): super(UnpoolingNet2d, self).__init__( pool=nn.MaxPool2d(2, return_indices=True), unpool=nn.MaxUnpool2d(2) )
def __init__(self, input_channels=None, output_channels=None, upsample=None, pooling_module=None): super().__init__() self.__dict__.update(locals()) del self.self if output_channels != input_channels or upsample: self.conv = nn.Conv2d(input_channels, output_channels, 1, stride=1, padding=0, bias=False) self.batch_norm = nn.BatchNorm2d(output_channels, eps=1e-03) if upsample and pooling_module: self.unpool = nn.MaxUnpool2d(2, stride=2, padding=0)