Exemplo n.º 1
0
 def get_current_visuals(self):
     real_A = util.tensor2im(self.real_A.data)
     fake_B = util.tensor2im(self.fake_B.data)
     real_B = util.tensor2im(self.real_B.data)
     real_AA = util.tensor2im(self.real_AA.data)
     fake_BB = util.tensor2im(self.fake_BB.data)
     real_BB = util.tensor2im(self.real_BB.data)
     if self.output_str_indices:
         output_str_indices = torch.LongTensor(self.output_str_indices)
         output_str_data = self.fake_BB.data[:, output_str_indices, :, :]
         real_str_data = self.real_BB.data[:, output_str_indices, :, :]
         img_output_str = util.tensor2im(output_str_data)
         img_real_str = util.tensor2im(real_str_data)
         list = [('Ereal_A', real_A), ('Ereal_B', real_B),
                 ('Efake_B', fake_B), ('real_A', real_AA),
                 ('real_B', real_BB), ('fake_B', fake_BB),
                 ('fake_STR', img_output_str), ('real_STR', img_real_str)]
     else:
         list = [('Ereal_A', real_A), ('Ereal_B', real_B),
                 ('Efake_B', fake_B), ('real_A', real_AA),
                 ('real_B', real_BB), ('fake_B', fake_BB)]
     if self.opt.str_input:
         list = [('real_A', real_AA), ('real_B', real_BB),
                 ('fake_B', fake_BB)]
     return OrderedDict(list)
Exemplo n.º 2
0
    def get_current_visuals(self):
        real_A1 = self.real_A1.data.clone()
        g, c, m, n = real_A1.size()
        fake_B = self.fake_B1.data.clone()
        real_B = self.real_B1.data.clone()

        # if self.opt.isTrain:
        #     real_A_all = real_A1
        #     fake_B_all = fake_B
        # else:
        #     real_A_all = self.Tensor(real_B.size(0), real_B.size(1),
        #                              real_A1.size(2),
        #                              real_A1.size(2) * real_A1.size(
        #                                  0))
        #     fake_B_all = self.Tensor(real_B.size(0), real_B.size(1),
        #                              real_A1.size(2),
        #                              fake_B.size(2) * fake_B.size(0))
        #     for b in range(g):
        #         real_A_all[:, :, :, self.out_id[b] * m:m * (
        #                     self.out_id[b] + 1)] = real_A1[b, :, :, :]
        #         fake_B_all[:, :, :,
        #         self.out_id[b] * m:m * (self.out_id[b] + 1)] = fake_B[
        #                                                        b, :,
        #                                                        :, :]
        real_A_all = self.Tensor(real_B.size(0), real_B.size(1),
                                 real_A1.size(2),
                                 real_A1.size(2) * real_A1.size(0))
        fake_B_all = self.Tensor(real_B.size(0), real_B.size(1),
                                 real_A1.size(2),
                                 fake_B.size(2) * fake_B.size(0))
        for b in range(g):
            real_A_all[:, :, :, b * m:m * (b + 1)] = real_A1[b, :, :, :]
            fake_B_all[:, :, :, b * m:m * (b + 1)] = fake_B[b, :, :, :]

        real_A = util.tensor2im(real_A_all)
        fake_B = util.tensor2im(fake_B_all)
        real_B = util.tensor2im(self.real_B1.data)
        return OrderedDict([('real_A', real_A), ('fake_B', fake_B),
                            ('real_B', real_B)])
Exemplo n.º 3
0
    def forward(self):
        self.real_A = Variable(self.input_A)
        # print('REAL_A size is')
        # print(self.real_A.size())
        if self.opt.conv3d:
            self.real_A_indep = self.netG_3d.forward(self.real_A.unsqueeze(2))
            #            print('REAL_A_INDEP size is')
            #            print(self.real_A_indep.size())
            self.fake_B = self.netG.forward(self.real_A_indep.squeeze(2))
        else:
            self.fake_B = self.netG.forward(self.real_A)

        #        print('FAKE_B size is')
        #        print(self.fake_B.size())

        b, c, m, n = self.fake_B.size()
        self.real_AA = self.real_A.narrow(3, m, m)
        self.fake_BB = self.fake_B.narrow(3, m, m)
        self.real_B = Variable(self.input_B)
        self.real_BB = self.real_B.narrow(3, m, m)
        #        print('REAL_B size is')
        #        print(self.real_B.size())
        real_B = util.tensor2im(self.real_B.data)
        real_A = util.tensor2im(self.real_A.data)
Exemplo n.º 4
0
    def parse(self):
        if not self.initialized:
            self.initialize()
        self.opt = self.parser.parse_args()
        self.opt.isTrain = self.isTrain   # train or test
        self.opt.project_root = self.project_root
        self.opt.computer_name = self.computer_name

        if self.opt.gpu_ids.find(' ') == -1:
            gpu_id_list = self.opt.gpu_ids.split(',')
            self.opt.gpu_ids = []
            if len(gpu_id_list) >= 1:
                for gpu_id in gpu_id_list:
                    gpu_id = int(gpu_id)
                    if gpu_id >= 0:
                        self.opt.gpu_ids.append(gpu_id)
        else:
            self.opt.gpu_ids = []
        args = vars(self.opt)

        if self.opt.dataset == 'SandunLK10k64':
            self.opt.charset = 'ENfull'
        elif self.opt.dataset == 'Capitals64':
            self.opt.charset = 'ENcap'
        else:
            print('Unknown dataset!!!')
            self.opt.charset = 'ENcap'

        if self.opt.charset == 'ENcap':
            self.opt.input_nc = 26
            self.opt.output_nc = 26
            self.opt.grps = 26
            if self.opt.blanks == -1:
                self.opt.blanks = 0.7
        elif self.opt.charset == 'ENfull':
            self.opt.input_nc = 60
            self.opt.output_nc = 60
            self.opt.grps = 60
            if self.opt.blanks == -1:
                self.opt.blanks = 0.85


        # save to the disk
        expr_dir = os.path.join(".", self.opt.checkpoints_dir,
                                self.opt.experiment_dir)
        XIutil.mkdirs(expr_dir)
        file_name = os.path.join(expr_dir, 'opt.txt')

        if self.opt.isTrain:
            self.opt.str_input_indices = []
        else:
            self.opt.str_input_indices = str2index(
                self.opt.str_input, self.opt.charset)
        self.opt.str_output_indices = str2index(self.opt.str_input, self.opt.charset)

        if self.opt.zip_results == -1:
            if self.opt.isTrain:
                self.opt.zip_results = 0
            else:
                self.opt.zip_results = 1

        print('------------ Options -------------')
        for k, v in sorted(args.items()):
            print('%s: %s' % (str(k), str(v)))
        print('-------------- End ----------------')

        with open(file_name, 'wt') as opt_file:
            opt_file.write('------------ Options -------------\n')
            for k, v in sorted(args.items()):
                opt_file.write('%s: %s\n' % (str(k), str(v)))
            opt_file.write('-------------- End ----------------\n')
            opt_file.close()
            if self.opt.use_auxiliary:
                auxiliary_expr_dir = os.path.join(self.opt.auxiliary_root,
                                                  self.opt.project_relative,
                                                  self.opt.checkpoints_dir,
                                                  self.opt.experiment_dir)
                print(auxiliary_expr_dir)
                XIutil.mkdir(auxiliary_expr_dir)
                copy2(file_name, auxiliary_expr_dir)
        return self.opt