Ejemplo n.º 1
0
    def construct(self, lr, hr, stu_width_mult, tea_width_mult):
        sr = self.net(lr, stu_width_mult)
        tea_sr = self.net(lr, tea_width_mult)
        loss = self.l1_loss(sr, hr) + self.l1_loss(tea_sr, hr)

        resize = nn.ResizeBilinear()
        bic = resize(lr, size=(lr.shape[-2] * 4, lr.shape[-1] * 4))
        neg = numpy.flip(bic, 0)
        neg = neg[:self.neg_num, :, :, :]
        loss += self.contrast_w * self.contrast_loss(tea_sr, sr, neg)
        return loss
Ejemplo n.º 2
0
    def __init__(self, n, dims, modules, **kwargs):
        super(Kp_module, self).__init__()
        self.n = n
        curr_mod = modules[0]
        next_mod = modules[1]
        curr_dim = dims[0]
        next_dim = dims[1]
        self.up1 = make_layer(curr_dim, curr_dim, 3, curr_mod, **kwargs)

        self.low1 = make_hg_layer(curr_dim, next_dim, 3, curr_mod, **kwargs)

        if self.n > 1:
            self.low2 = Kp_module(n - 1, dims[1:], modules[1:], **kwargs)
        else:
            self.low2 = make_layer(next_dim, next_dim, 3, next_mod, **kwargs)

        self.low3 = make_layer_revr(next_dim, curr_dim, 3, curr_mod, **kwargs)

        self.up2 = nn.ResizeBilinear()
Ejemplo n.º 3
0
    def forward(self, z, img=None):
        x_list = []
        x_first = self.sub_generators[0](z[0])
        x_list.append(x_first)

        if img is not None:
            x_inter = img
        else:
            x_inter = x_first

        for i in range(1, self.current_scale + 1):
            x_inter = nn.ResizeBilinear()(
                x_inter, (self.size_list[i], self.size_list[i]), mode='bilinear', align_corners=True)
            x_prev = x_inter
            x_inter = mindspore.ops.Pad(x_inter, [5, 5, 5, 5], value=0)
            x_inter = x_inter + z[i]
            x_inter = self.sub_generators[i](x_inter) + x_prev
            x_list.append(x_inter)

        return x_list
Ejemplo n.º 4
0
 def construct(self):
     interpolate = nn.ResizeBilinear()
     return interpolate(self.value)
Ejemplo n.º 5
0
 def construct(self, x):
     interpolate = nn.ResizeBilinear()
     return interpolate(x, scale_factor=2)
Ejemplo n.º 6
0
 def construct(self, x):
     interpolate = nn.ResizeBilinear()
     return interpolate(x, size=(5, 5))
Ejemplo n.º 7
0
 def construct(self):
     interpolate = nn.ResizeBilinear()
     return interpolate(self.value, scale_factor=2)