MCPcopy Create free account
hub / github.com/Royalvice/DocDiff / __init__

Method __init__

src/sobel.py:6–14  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

4
5class Sobel(nn.Module):
6 def __init__(self):
7 super().__init__()
8 self.filter = nn.Conv2d(in_channels=1, out_channels=2, kernel_size=3, stride=1, padding=1, bias=False)
9
10 Gx = torch.tensor([[1.0, 0.0, -1.0], [2.0, 0.0, -2.0], [1.0, 0.0, -1.0]])
11 Gy = torch.tensor([[1.0, 2.0, 1.0], [0.0, 0.0, 0.0], [-1.0, -2.0, -1.0]])
12 G = torch.cat([Gx.unsqueeze(0), Gy.unsqueeze(0)], 0)
13 G = G.unsqueeze(1)
14 self.filter.weight = nn.Parameter(G, requires_grad=False)
15
16 def forward(self, img):
17 if img.shape[1] == 3:

Callers 1

__init__Method · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected