| 24 | |
| 25 | |
| 26 | class Laplacian(nn.Module): |
| 27 | def __init__(self): |
| 28 | super().__init__() |
| 29 | self.filter = nn.Conv2d(in_channels=3, out_channels=3, kernel_size=3, stride=1, padding=1, bias=False, groups=3) |
| 30 | G = torch.tensor([[-1, -1, -1], [-1, 8, -1], [-1, -1, -1]]).float() |
| 31 | G = G.unsqueeze(0).unsqueeze(0) |
| 32 | G = torch.cat([G, G, G], 0) |
| 33 | self.filter.weight = nn.Parameter(G, requires_grad=False) |
| 34 | |
| 35 | def forward(self, img): |
| 36 | x = self.filter(img) |
| 37 | return x |
| 38 | |
| 39 | if __name__ == "__main__": |
| 40 | laplacian = Laplacian() |