Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from torch.nn.functional import conv_transpose2d
- def specific_size_transpose2d(tensor, size, weight, bias, stride):
- """ Transpose2d with specific size """
- oh, ow = size[-2:]
- ih, iw = tensor.size()[-2:]
- k = weight.size(-1)
- offset_h = -(oh - (ih - 1) * stride[0] - k)
- out_padding_h = offset_h % 2
- padding_h = (offset_h + 1) // 2
- offset_w = -(ow - (iw - 1) * stride[1] - k)
- out_padding_w = offset_w % 2
- padding_w = (offset_w + 1) // 2
- return conv_transpose2d(tensor, weight, bias, stride,
- padding=(padding_h, padding_w),
- output_padding=(out_padding_h, out_padding_w))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement