srgan_model.py 1.4 KB
Newer Older
L
LielinJiang 已提交
1 2 3
from collections import OrderedDict
import paddle
import paddle.nn as nn
L
LielinJiang 已提交
4

L
LielinJiang 已提交
5 6 7 8 9
from .generators.builder import build_generator
from .base_model import BaseModel
from .losses import GANLoss
from .builder import MODELS

L
LielinJiang 已提交
10

L
LielinJiang 已提交
11 12 13 14 15
@MODELS.register()
class SRGANModel(BaseModel):
    def __init__(self, cfg):
        super(SRGANModel, self).__init__(cfg)

L
LielinJiang 已提交
16
        # define networks
L
LielinJiang 已提交
17
        self.model_names = ['G']
L
LielinJiang 已提交
18

L
LielinJiang 已提交
19 20 21
        self.netG = build_generator(cfg.model.generator)
        self.visual_names = ['LQ', 'GT', 'fake_H']

L
LielinJiang 已提交
22 23 24
        # TODO: support srgan train.
        if False:
            # self.netD = build_discriminator(cfg.model.discriminator)
L
LielinJiang 已提交
25
            self.netG.train()
L
LielinJiang 已提交
26
            # self.netD.train()
L
LielinJiang 已提交
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49

    def set_input(self, input):
        """Unpack input data from the dataloader and perform necessary pre-processing steps.

        Parameters:
            input (dict): include the data itself and its metadata information.

        The option 'direction' can be used to swap images in domain A and domain B.
        """

        # AtoB = self.opt.dataset.train.direction == 'AtoB'
        if 'A' in input:
            self.LQ = paddle.to_tensor(input['A'])
        if 'B' in input:
            self.GT = paddle.to_tensor(input['B'])
        if 'A_paths' in input:
            self.image_paths = input['A_paths']

    def forward(self):
        self.fake_H = self.netG(self.LQ)

    def optimize_parameters(self, step):
        pass