본문 바로가기

Deep Learning

[Pytorch] 2D Conv using F.conv2d (2d conv with a pre-defined filter)

반응형

import torch

import torch.nn as nn

import torch.nn.functional as F

from torch.autograd

import Variable

import numpy as np

 

input = torch.Tensor(np.array([[[ [1,1,1,0,0], [0,1,1,1,0], [0,0,1,1,1], [0,0,1,1,0], [0,1,1,0,0] ]]]))

filter = torch.Tensor(np.array([[[ [1,0,1], [0,1,0], [1,0,1] ]]]))

 

input = Variable(input, requires\_grad=True)

filter = Variable(filter)

out = F.conv2d(input, filter)

print(out)