-
Notifications
You must be signed in to change notification settings - Fork 0
/
DownForward_.py
48 lines (35 loc) · 1.91 KB
/
DownForward_.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import torch
from torch import nn as nn
import torch.nn.functional as F
import numpy as np
import time
from Down_ import FouriDown, CutDown, BlurDown, unPixelShuffle
class DownSample(nn.Module):
def __init__(self, in_channels, base_channel, downsampling):
super(DownSample, self).__init__()
if downsampling == 'Bilinear':
self.down = nn.Sequential(nn.Upsample(scale_factor=0.5, mode='bilinear', align_corners=False),
nn.Conv2d(in_channels, base_channel, 1, 1, 0, bias=False))
elif downsampling == 'Bicubic':
self.down = nn.Sequential(nn.Upsample(scale_factor=0.5, mode='bilinear', align_corners=False),
nn.Conv2d(in_channels, base_channel, 1, 1, 0, bias=False))
elif downsampling == 'StrideConv22':
self.down = nn.Conv2d(in_channels, base_channel, 2, 2, 0, bias=False)
elif downsampling == 'MaxPooling':
self.down = nn.Sequential(nn.MaxPool2d(kernel_size=2, stride=2),
nn.Conv2d(in_channels, base_channel, 1, 1, 0, bias=False))
elif downsampling == 'AverPooling':
self.down = nn.Sequential(nn.AvgPool2d(kernel_size=2, stride=2),
nn.Conv2d(in_channels, base_channel, 1, 1, 0, bias=False))
elif downsampling == 'PixelShuffle':
self.down = nn.Sequential(unPixelShuffle(downscale_factor=2),
nn.Conv2d(in_channels*4, base_channel, 1, 1, 0, bias=False))
elif downsampling == 'FouriDown':
self.down = FouriDown(in_channels, base_channel)
elif downsampling == 'CutDown':
self.down = CutDown(in_channels, base_channel)
elif downsampling == 'BlurDown':
self.down = BlurDown(in_channels, base_channel)
def forward(self, x):
x = self.down(x)
return x