ν¨λ© κΈ°λ₯μ νλ ν¨μ
μμλ‘ μ΄ν΄ν΄λ³΄μ.
# μΌλ¨ κΈ°λ³Έ λ°μ΄ν°μμ±
import torch
import torch.nn.functional as F
temp = torch.randn(3,3)
print(temp)
> tensor([[-0.8379, -0.1674, 0.2919],
[-0.7246, 0.3931, 0.1963],
[ 0.6709, 0.2197, -0.6927]])
out = F.pad(temp,(1,1,1,1),'constant',10)
print(out)
> tensor([[10.0000, 10.0000, 10.0000, 10.0000, 10.0000],
[10.0000, -0.8379, -0.1674, 0.2919, 10.0000],
[10.0000, -0.7246, 0.3931, 0.1963, 10.0000],
[10.0000, 0.6709, 0.2197, -0.6927, 10.0000],
[10.0000, 10.0000, 10.0000, 10.0000, 10.0000]])
out = F.pad(temp,(2,2),'reflect',0)
print(out)
> tensor([[ 0.2919, -0.1674, -0.8379, -0.1674, 0.2919, -0.1674, -0.8379],
[ 0.1963, 0.3931, -0.7246, 0.3931, 0.1963, 0.3931, -0.7246],
[-0.6927, 0.2197, 0.6709, 0.2197, -0.6927, 0.2197, 0.6709]])
out = F.pad(temp,(2,2),'reflicate',0)
print(out)
> tensor([[-0.8379, -0.8379, -0.8379, -0.1674, 0.2919, 0.2919, 0.2919],
[-0.7246, -0.7246, -0.7246, 0.3931, 0.1963, 0.1963, 0.1963],
[ 0.6709, 0.6709, 0.6709, 0.2197, -0.6927, -0.6927, -0.6927]])
out = F.pad(temp,(1,1,1,1),'circular',10)
print(out)
> tensor([[10.0000, 10.0000, 10.0000, 10.0000, 10.0000],
[10.0000, -0.8379, -0.1674, 0.2919, 10.0000],
[10.0000, -0.7246, 0.3931, 0.1963, 10.0000],
[10.0000, 0.6709, 0.2197, -0.6927, 10.0000],
[10.0000, 10.0000, 10.0000, 10.0000, 10.0000]])
https://pytorch.org/docs/stable/generated/torch.nn.functional.pad.html