Example #1
0
    def loadModels(self, ):
        import aimaker.models.model_factory as mf
        model_factory = mf.ModelFactory(self.setting)
        generator_name = self.setting['controllers']['pix2pix'][
            'generatorModel']
        discriminator_name = self.setting['controllers']['pix2pix'][
            'discriminatorModel']

        try:
            generator_path = util.fcnt_load(self.sheckpoints_dir,
                                            "pix2pix_generator", "pth")
            self.generator = self._loadModel(generator_path, self.gpu_ids[0])
        except:
            import traceback
            traceback.print_exc()
            self.generator = model_factory.create(generator_name).to(
                self.gpu_ids[0])

        try:
            discriminator_path = util.fcnt_load(self.sheckpoints_dir,
                                                "pix2pix_discriminator", "pth")
            self.discriminator = self._loadModel(discriminator_path,
                                                 self.gpu_ids[0])
        except:
            import traceback
            traceback.print_exc()
            self.discriminator = model_factory.create(discriminator_name).to(
                self.gpu_ids[0])

        return True
Example #2
0
    def __init__(self, config):
        import aimaker.models.model_factory as mf
        import aimaker.loss.loss_factory as lf
        import aimaker.optimizers.optimizer_factory as of

        self.config          = config
        ch                   = util.ConfigHandler(config)
        self.gpu_ids         = ch.get_GPU_ID()
        self.checkpoints_dir = ch.get_check_points_dir()

        model_factory        = mf.ModelFactory(config)
        loss_factory         = lf.LossFactory(config)
        optimizer_factory    = of.OptimizerFactory(config)
        self.n_batch         = ch.get_batch_size()

        self.cDim            = len(self.config['starGAN settings']['typeNames'].strip().split(","))

        name                 = config['starGAN settings']['generatorModel']

        if not self.loadModels():
            self.generator       = model_factory.create(name) 
            if config['dataset settings'].getboolean('isTrain'):
                name = config['starGAN settings']['discriminatorModel']
                self.discriminator = model_factory.create(name) 

        self.reconstruct_criterion = loss_factory\
                                       .create(config['starGAN settings']['reconstructCriterion'])
        self.cls_criterion         = loss_factory\
                                       .create(config['starGAN settings']['clsCriterion'])
                                       
        self.lambda_rec = float(config['starGAN settings']['lambdaRec'])
        self.lambda_cls = float(config['starGAN settings']['lambdaCls'])
        self.lambda_gp  = float(config['starGAN settings']['lambdaGp'])

        if len(self.gpu_ids):
            self.generator = self.generator.cuda(self.gpu_ids[0])

        if config['dataset settings'].getboolean('isTrain'):
            if len(self.gpu_ids):
                self.discriminator = self.discriminator.cuda(self.gpu_ids[0])
                
            self.discriminator_criterion = loss_factory.create(config['starGAN settings']['discriminatorCriterion'])
            if len(self.gpu_ids):
                #self.generator_criterion     = self.generator_criterion.cuda(self.gpu_ids[0])   
                self.discriminator_criterion = self.discriminator_criterion.cuda(self.gpu_ids[0])   

            self.generator_optimizer     = optimizer_factory.create(\
                                               config['starGAN settings']['generatorOptimizer'])\
                                               (self.generator.parameters(), config)
            self.discriminator_optimizer = optimizer_factory.create(config['starGAN settings']['discriminatorOptimizer'])\
                                               (self.discriminator.parameters(), config)

        if config['ui settings'].getboolean('isShowModelInfo'):
            self.showModel()
    def __init__(self, config):
        import aimaker.models.model_factory as mf
        import aimaker.loss.loss_factory as lf
        import aimaker.optimizers.optimizer_factory as of

        self.config = config
        self.ch = ch = util.ConfigHandler(config)
        self.gpu_ids = ch.get_GPU_ID()
        self.checkpoints_dir = ch.get_check_points_dir()
        self.pool = util.ImagePool(
            int(ch.settings['controller']['voxcelFlow']['imagePoolSize']))

        self.lambda_1 = float(config['controller']['voxcelFlow']['lambda1'])
        self.lambda_2 = float(config['controller']['voxcelFlow']['lambda2'])

        model_factory = mf.ModelFactory(config)
        loss_factory = lf.LossFactory(config)
        optimizer_factory = of.OptimizerFactory(config)

        name = config['controller']['voxcelFlow']['generatorModel']
        self.generator = model_factory.create(name)
        self.generator_criterion  = loss_factory.create(\
                                       config['controller']['voxcelFlow']['generatorCriterion'])

        if len(self.gpu_ids):
            self.generator = self.generator.cuda(self.gpu_ids[0])

        if config['data']['isTrain']:
            name = config['controller']['voxcelFlow']['discriminatorModel']
            self.discriminator = model_factory.create(name)
            if len(self.gpu_ids):
                self.discriminator = self.discriminator.cuda(self.gpu_ids[0])

        self.loadModels()

        if config['data']['isTrain']:

            self.discriminator_criterion = loss_factory.create(\
                                               config['controller']['voxcelFlow']\
                                                     ['discriminatorCriterion'])
            if len(self.gpu_ids):
                self.generator_criterion = self.generator_criterion.cuda(
                    self.gpu_ids[0])
                self.discriminator_criterion = self.discriminator_criterion.cuda(
                    self.gpu_ids[0])

            self.generator_optimizer     = optimizer_factory.create(\
                                               config['controller']['voxcelFlow']['generatorOptimizer'])\
                                               (self.generator.parameters(), config)
            self.discriminator_optimizer = optimizer_factory.create(config['controller']['voxcelFlow']['discriminatorOptimizer'])\
                                               (self.discriminator.parameters(), config)

        if config['ui settings']['isShowModelInfo']:
            self.showModel()
    def __init__(self, settings: EasyDict):
        import aimaker.models.model_factory as mf
        import aimaker.loss.loss_factory as lf
        import aimaker.optimizers.optimizer_factory as of

        self.settings = settings
        ch = util.ConfigHandler(settings)
        self.gpu_ids = ch.get_GPU_ID()
        self.checkpoints_dir = ch.get_check_points_dir()
        self.pool = util.ImagePool(
            int(ch.settings['annotation']['imagePoolSize']))

        model_factory = mf.ModelFactory(settings)
        loss_factory = lf.LossFactory(settings)
        optimizer_factory = of.OptimizerFactory(settings)

        name = settings['annotation']['generatorModel']

        self.downsampler = nn.AvgPool2d(8)
        self.upsampler = nn.Upsample(scale_factor=8)

        if not self.load_models():
            self.generator = model_factory.create(name)
            if settings['dataset'].getboolean('isTrain'):
                name = settings['annotation']['discriminatorModel']
                self.discriminator = model_factory.create(name)

        self.generator_criterion = loss_factory \
            .create(settings['annotation']['generatorCriterion'])

        if len(self.gpu_ids):
            self.generator = self.generator.cuda(self.gpu_ids[0])

        if settings['dataset'].getboolean('isTrain'):
            if len(self.gpu_ids):
                self.discriminator = self.discriminator.cuda(self.gpu_ids[0])

            self.discriminator_criterion = loss_factory.create(
                settings['annotation']['discriminatorCriterion'])
            if len(self.gpu_ids):
                self.generator_criterion = self.generator_criterion.cuda(
                    self.gpu_ids[0])
                self.discriminator_criterion = self.discriminator_criterion.cuda(
                    self.gpu_ids[0])

            self.generator_optimizer = optimizer_factory.create( \
                settings['annotation']['generatorOptimizer']) \
                (self.generator.parameters(), settings)
            self.discriminator_optimizer = optimizer_factory.create(settings['annotation']['discriminatorOptimizer']) \
                (self.discriminator.parameters(), settings)

        if settings['ui'].getboolean('isShowModelInfo'):
            self.show_model()
Example #5
0
    def __init__(self, setting):
        import aimaker.models.model_factory as mf
        import aimaker.loss.loss_factory as lf
        import aimaker.optimizers.optimizer_factory as of

        self.setting = setting
        ch = util.SettingHandler(setting)
        self.gpu_ids = ch.get_GPU_ID()
        self.sheckpoints_dir = ch.get_check_points_dir()
        self.pool = util.ImagePool(
            int(ch.setting['controllers']['pix2pix']['imagePoolSize']))

        model_factory = mf.ModelFactory(setting)
        loss_factory = lf.LossFactory(setting)
        optimizer_factory = of.OptimizerFactory(setting)

        name = setting['controllers']['pix2pix']['generatorModel']
        self.is_feature = setting['controllers']['pix2pix']['isFeature']

        if not self.loadModels():
            self.generator = model_factory.create(name)
            if setting['data']['base']['isTrain']:
                name = setting['controllers']['pix2pix']['discriminatorModel']
                self.discriminator = model_factory.create(name)

        self.generator_criterion  = loss_factory\
                                        .create(setting['controllers']['pix2pix']['generatorCriterion'])

        if len(self.gpu_ids):
            self.generator = self.generator.to(self.gpu_ids[1])

        if setting['data']['base']['isTrain']:
            if len(self.gpu_ids):
                self.discriminator = self.discriminator.to(self.gpu_ids[0])

            self.discriminator_criterion = loss_factory.create(
                setting['controllers']['pix2pix']['discriminatorCriterion'])
            if len(self.gpu_ids):
                self.generator_criterion = self.generator_criterion.to(
                    self.gpu_ids[1])
                self.discriminator_criterion = self.discriminator_criterion.to(
                    self.gpu_ids[1])

            self.feature_criterion = loss_factory.create('TF')

            self.generator_optimizer     = optimizer_factory.create(\
                                               setting['controllers']['pix2pix']['generatorOptimizer'])\
                                               (self.generator.parameters(), setting)
            self.discriminator_optimizer = optimizer_factory.create(setting['controllers']['pix2pix']['discriminatorOptimizer'])\
                                               (self.discriminator.parameters(), setting)

        if setting['ui']['base']['isShowModelInfo']:
            self.showModel()
Example #6
0
    def load_models(self, ):
        import aimaker.models.model_factory as mf
        model_factory = mf.ModelFactory(self.settings)

        try:
            model_path = fcnt_load(self.checkpoints_dir, "simple", "pth")
            self.model = self._load_model(model_path, self.gpu_ids[0])
        except:
            import traceback
            traceback.print_exc()
            self.model = model_factory.create(self.model_name).to(
                self.gpu_ids[0])
        self._set_predict_model(self.model)
        self.show_model_lst += [self.model]
        return True
Example #7
0
    def __init__(self, settings):
        import aimaker.models.model_factory as mf
        import aimaker.loss.loss_factory as lf
        import aimaker.optimizers.optimizer_factory as of

        self.settings = settings
        ch = SettingHandler(settings)

        self.gpu_ids = ch.get_GPU_ID()
        self.checkpoints_dir = ch.get_check_points_dir()
        model_factory = mf.ModelFactory(settings)
        loss_factory = lf.LossFactory(settings)
        optimizer_factory = of.OptimizerFactory(settings)

        # for discriminator regularization
        self.pool_fake_A = ImagePool(
            int(settings['controllers']['cycleGAN']['imagePoolSize']))
        self.pool_fake_B = ImagePool(
            int(settings['controllers']['cycleGAN']['imagePoolSize']))

        name = settings['controllers']['cycleGAN']['generatorModel']
        self.netG_A = model_factory.create(name)
        self.netG_B = model_factory.create(name)
        if len(self.gpu_ids):
            self.netG_A = self.netG_A.cuda(self.gpu_ids[0])
            self.netG_B = self.netG_B.cuda(self.gpu_ids[0])

            name = settings['controllers']['cycleGAN']['discriminatorModel']
            self.netD_A = model_factory.create(name)
            self.netD_B = model_factory.create(name)
            if len(self.gpu_ids):
                self.netD_A = self.netD_A.cuda(self.gpu_ids[0])
                self.netD_B = self.netD_B.cuda(self.gpu_ids[0])

        self.loadModels()

        self.criterionGAN = loss_factory.create("GANLoss")
        self.criterionCycle = loss_factory.create(
            settings['controllers']['cycleGAN']['cycleLoss'])
        self.criterionIdt = loss_factory.create(
            settings['controllers']['cycleGAN']['idtLoss'])
        if len(self.gpu_ids):
            self.criterionGAN = self.criterionGAN.cuda(self.gpu_ids[0])
            self.criterionCycle = self.criterionCycle.cuda(self.gpu_ids[0])
            self.criterionIdt = self.criterionIdt.cuda(self.gpu_ids[0])

            # initialize optimizers
        self.optimizer_G = optimizer_factory.create(
            settings['controllers']['cycleGAN']['generatorOptimizer'])(
                it.chain(self.netG_A.parameters(),
                         self.netG_B.parameters()), settings)

        if settings['data']['base']['isTrain']:
            self.optimizer_D_A = optimizer_factory.create(
                settings['controllers']['cycleGAN']['D_AOptimizer'])(
                    self.netD_A.parameters(), settings)
            self.optimizer_D_B = optimizer_factory.create(
                settings['controllers']['cycleGAN']['D_BOptimizer'])(
                    self.netD_B.parameters(), settings)

        if settings['ui']['base']['isShowModelInfo']:
            self.showModel()