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
def mnp_flip(x): a = mnp.flip(x) b = mnp.flip(x, 0) c = mnp.flip(x, 1) d = mnp.flip(x, (-3, -1)) return a, b, c, d