|
|
@ -41,7 +41,7 @@ class SDYNetx1(nn.Module):
|
|
|
|
y = y.view(rb*rc, 1, rh, rw, self.scale, self.scale).permute(0,1,2,4,3,5).reshape(rb*rc, 1, rh*self.scale, rw*self.scale)
|
|
|
|
y = y.view(rb*rc, 1, rh, rw, self.scale, self.scale).permute(0,1,2,4,3,5).reshape(rb*rc, 1, rh*self.scale, rw*self.scale)
|
|
|
|
y = torch.rot90(y, k=-rotations_count, dims=[-2, -1])
|
|
|
|
y = torch.rot90(y, k=-rotations_count, dims=[-2, -1])
|
|
|
|
output += y
|
|
|
|
output += y
|
|
|
|
|
|
|
|
|
|
|
|
output /= 4*3
|
|
|
|
output /= 4*3
|
|
|
|
output = output.view(b, c, h*self.scale, w*self.scale)
|
|
|
|
output = output.view(b, c, h*self.scale, w*self.scale)
|
|
|
|
return output
|
|
|
|
return output
|
|
|
@ -61,12 +61,12 @@ class SDYNetx2(nn.Module):
|
|
|
|
self._extract_pattern_S = PercievePattern(receptive_field_idxes=[[0,0],[0,1],[1,0],[1,1]], center=[0,0], window_size=3)
|
|
|
|
self._extract_pattern_S = PercievePattern(receptive_field_idxes=[[0,0],[0,1],[1,0],[1,1]], center=[0,0], window_size=3)
|
|
|
|
self._extract_pattern_D = PercievePattern(receptive_field_idxes=[[0,0],[2,0],[0,2],[2,2]], center=[0,0], window_size=3)
|
|
|
|
self._extract_pattern_D = PercievePattern(receptive_field_idxes=[[0,0],[2,0],[0,2],[2,2]], center=[0,0], window_size=3)
|
|
|
|
self._extract_pattern_Y = PercievePattern(receptive_field_idxes=[[0,0],[1,1],[1,2],[2,1]], center=[0,0], window_size=3)
|
|
|
|
self._extract_pattern_Y = PercievePattern(receptive_field_idxes=[[0,0],[1,1],[1,2],[2,1]], center=[0,0], window_size=3)
|
|
|
|
self.stageS_1 = DenseConvUpscaleBlock(hidden_dim=hidden_dim, layers_count=layers_count, upscale_factor=1)
|
|
|
|
self.stage1_S = DenseConvUpscaleBlock(hidden_dim=hidden_dim, layers_count=layers_count, upscale_factor=1)
|
|
|
|
self.stageD_1 = DenseConvUpscaleBlock(hidden_dim=hidden_dim, layers_count=layers_count, upscale_factor=1)
|
|
|
|
self.stage1_D = DenseConvUpscaleBlock(hidden_dim=hidden_dim, layers_count=layers_count, upscale_factor=1)
|
|
|
|
self.stageY_1 = DenseConvUpscaleBlock(hidden_dim=hidden_dim, layers_count=layers_count, upscale_factor=1)
|
|
|
|
self.stage1_Y = DenseConvUpscaleBlock(hidden_dim=hidden_dim, layers_count=layers_count, upscale_factor=1)
|
|
|
|
self.stageS_2 = DenseConvUpscaleBlock(hidden_dim=hidden_dim, layers_count=layers_count, upscale_factor=scale)
|
|
|
|
self.stage2_S = DenseConvUpscaleBlock(hidden_dim=hidden_dim, layers_count=layers_count, upscale_factor=scale)
|
|
|
|
self.stageD_2 = DenseConvUpscaleBlock(hidden_dim=hidden_dim, layers_count=layers_count, upscale_factor=scale)
|
|
|
|
self.stage2_D = DenseConvUpscaleBlock(hidden_dim=hidden_dim, layers_count=layers_count, upscale_factor=scale)
|
|
|
|
self.stageY_2 = DenseConvUpscaleBlock(hidden_dim=hidden_dim, layers_count=layers_count, upscale_factor=scale)
|
|
|
|
self.stage2_Y = DenseConvUpscaleBlock(hidden_dim=hidden_dim, layers_count=layers_count, upscale_factor=scale)
|
|
|
|
|
|
|
|
|
|
|
|
def forward(self, x):
|
|
|
|
def forward(self, x):
|
|
|
|
b,c,h,w = x.shape
|
|
|
|
b,c,h,w = x.shape
|
|
|
@ -76,17 +76,17 @@ class SDYNetx2(nn.Module):
|
|
|
|
rotated = torch.rot90(x, k=rotations_count, dims=[-2, -1])
|
|
|
|
rotated = torch.rot90(x, k=rotations_count, dims=[-2, -1])
|
|
|
|
rb,rc,rh,rw = rotated.shape
|
|
|
|
rb,rc,rh,rw = rotated.shape
|
|
|
|
|
|
|
|
|
|
|
|
s = self.stageS_1(self._extract_pattern_S(rotated))
|
|
|
|
s = self.stage1_S(self._extract_pattern_S(rotated))
|
|
|
|
s = s.view(rb*rc, 1, rh, rw, 1, 1).permute(0,1,2,4,3,5).reshape(rb*rc, 1, rh, rw)
|
|
|
|
s = s.view(rb*rc, 1, rh, rw, 1, 1).permute(0,1,2,4,3,5).reshape(rb*rc, 1, rh, rw)
|
|
|
|
s = torch.rot90(s, k=-rotations_count, dims=[-2, -1])
|
|
|
|
s = torch.rot90(s, k=-rotations_count, dims=[-2, -1])
|
|
|
|
output_1 += s
|
|
|
|
output_1 += s
|
|
|
|
|
|
|
|
|
|
|
|
d = self.stageD_1(self._extract_pattern_D(rotated))
|
|
|
|
d = self.stage1_D(self._extract_pattern_D(rotated))
|
|
|
|
d = d.view(rb*rc, 1, rh, rw, 1, 1).permute(0,1,2,4,3,5).reshape(rb*rc, 1, rh, rw)
|
|
|
|
d = d.view(rb*rc, 1, rh, rw, 1, 1).permute(0,1,2,4,3,5).reshape(rb*rc, 1, rh, rw)
|
|
|
|
d = torch.rot90(d, k=-rotations_count, dims=[-2, -1])
|
|
|
|
d = torch.rot90(d, k=-rotations_count, dims=[-2, -1])
|
|
|
|
output_1 += d
|
|
|
|
output_1 += d
|
|
|
|
|
|
|
|
|
|
|
|
y = self.stageY_1(self._extract_pattern_Y(rotated))
|
|
|
|
y = self.stage1_Y(self._extract_pattern_Y(rotated))
|
|
|
|
y = y.view(rb*rc, 1, rh, rw, 1, 1).permute(0,1,2,4,3,5).reshape(rb*rc, 1, rh, rw)
|
|
|
|
y = y.view(rb*rc, 1, rh, rw, 1, 1).permute(0,1,2,4,3,5).reshape(rb*rc, 1, rh, rw)
|
|
|
|
y = torch.rot90(y, k=-rotations_count, dims=[-2, -1])
|
|
|
|
y = torch.rot90(y, k=-rotations_count, dims=[-2, -1])
|
|
|
|
output_1 += y
|
|
|
|
output_1 += y
|
|
|
@ -100,17 +100,17 @@ class SDYNetx2(nn.Module):
|
|
|
|
rotated = torch.rot90(x, k=rotations_count, dims=[-2, -1])
|
|
|
|
rotated = torch.rot90(x, k=rotations_count, dims=[-2, -1])
|
|
|
|
rb,rc,rh,rw = rotated.shape
|
|
|
|
rb,rc,rh,rw = rotated.shape
|
|
|
|
|
|
|
|
|
|
|
|
s = self.stageS_2(self._extract_pattern_S(rotated))
|
|
|
|
s = self.stage2_S(self._extract_pattern_S(rotated))
|
|
|
|
s = s.view(rb*rc, 1, rh, rw, self.scale, self.scale).permute(0,1,2,4,3,5).reshape(rb*rc, 1, rh*self.scale, rw*self.scale)
|
|
|
|
s = s.view(rb*rc, 1, rh, rw, self.scale, self.scale).permute(0,1,2,4,3,5).reshape(rb*rc, 1, rh*self.scale, rw*self.scale)
|
|
|
|
s = torch.rot90(s, k=-rotations_count, dims=[-2, -1])
|
|
|
|
s = torch.rot90(s, k=-rotations_count, dims=[-2, -1])
|
|
|
|
output_2 += s
|
|
|
|
output_2 += s
|
|
|
|
|
|
|
|
|
|
|
|
d = self.stageD_2(self._extract_pattern_D(rotated))
|
|
|
|
d = self.stage2_D(self._extract_pattern_D(rotated))
|
|
|
|
d = d.view(rb*rc, 1, rh, rw, self.scale, self.scale).permute(0,1,2,4,3,5).reshape(rb*rc, 1, rh*self.scale, rw*self.scale)
|
|
|
|
d = d.view(rb*rc, 1, rh, rw, self.scale, self.scale).permute(0,1,2,4,3,5).reshape(rb*rc, 1, rh*self.scale, rw*self.scale)
|
|
|
|
d = torch.rot90(d, k=-rotations_count, dims=[-2, -1])
|
|
|
|
d = torch.rot90(d, k=-rotations_count, dims=[-2, -1])
|
|
|
|
output_2 += d
|
|
|
|
output_2 += d
|
|
|
|
|
|
|
|
|
|
|
|
y = self.stageY_2(self._extract_pattern_Y(rotated))
|
|
|
|
y = self.stage2_Y(self._extract_pattern_Y(rotated))
|
|
|
|
y = y.view(rb*rc, 1, rh, rw, self.scale, self.scale).permute(0,1,2,4,3,5).reshape(rb*rc, 1, rh*self.scale, rw*self.scale)
|
|
|
|
y = y.view(rb*rc, 1, rh, rw, self.scale, self.scale).permute(0,1,2,4,3,5).reshape(rb*rc, 1, rh*self.scale, rw*self.scale)
|
|
|
|
y = torch.rot90(y, k=-rotations_count, dims=[-2, -1])
|
|
|
|
y = torch.rot90(y, k=-rotations_count, dims=[-2, -1])
|
|
|
|
output_2 += y
|
|
|
|
output_2 += y
|
|
|
@ -120,13 +120,13 @@ class SDYNetx2(nn.Module):
|
|
|
|
return output_2
|
|
|
|
return output_2
|
|
|
|
|
|
|
|
|
|
|
|
def get_lut_model(self, quantization_interval=16, batch_size=2**10):
|
|
|
|
def get_lut_model(self, quantization_interval=16, batch_size=2**10):
|
|
|
|
stageS_1 = lut.transfer_2x2_input_SxS_output(self.stageS_1, quantization_interval=quantization_interval, batch_size=batch_size)
|
|
|
|
stage1_S = lut.transfer_2x2_input_SxS_output(self.stage1_S, quantization_interval=quantization_interval, batch_size=batch_size)
|
|
|
|
stageD_1 = lut.transfer_2x2_input_SxS_output(self.stageD_1, quantization_interval=quantization_interval, batch_size=batch_size)
|
|
|
|
stage1_D = lut.transfer_2x2_input_SxS_output(self.stage1_D, quantization_interval=quantization_interval, batch_size=batch_size)
|
|
|
|
stageY_1 = lut.transfer_2x2_input_SxS_output(self.stageY_1, quantization_interval=quantization_interval, batch_size=batch_size)
|
|
|
|
stage1_Y = lut.transfer_2x2_input_SxS_output(self.stage1_Y, quantization_interval=quantization_interval, batch_size=batch_size)
|
|
|
|
stageS_2 = lut.transfer_2x2_input_SxS_output(self.stageS_2, quantization_interval=quantization_interval, batch_size=batch_size)
|
|
|
|
stage2_S = lut.transfer_2x2_input_SxS_output(self.stage2_S, quantization_interval=quantization_interval, batch_size=batch_size)
|
|
|
|
stageD_2 = lut.transfer_2x2_input_SxS_output(self.stageD_2, quantization_interval=quantization_interval, batch_size=batch_size)
|
|
|
|
stage2_D = lut.transfer_2x2_input_SxS_output(self.stage2_D, quantization_interval=quantization_interval, batch_size=batch_size)
|
|
|
|
stageY_2 = lut.transfer_2x2_input_SxS_output(self.stageY_2, quantization_interval=quantization_interval, batch_size=batch_size)
|
|
|
|
stage2_Y = lut.transfer_2x2_input_SxS_output(self.stage2_Y, quantization_interval=quantization_interval, batch_size=batch_size)
|
|
|
|
lut_model = sdylut.SDYLutx2.init_from_lut(stageS_1, stageD_1, stageY_1, stageS_2, stageD_2, stageY_2)
|
|
|
|
lut_model = sdylut.SDYLutx2.init_from_lut(stage1_S, stage1_D, stage1_Y, stage2_S, stage2_D, stage2_Y)
|
|
|
|
return lut_model
|
|
|
|
return lut_model
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|