fig = utility.plot(fake_image) plt.savefig(os.path.join(args.output, 'fake_cgan.png'), bbox_inches='tight') plt.close(fig) elif args.model_net == 'DCGAN': noise_data = np.random.uniform(low=-1.0, high=1.0, size=[args.n_samples, args.noise_size ]).astype('float32') noise_tensor = fluid.LoDTensor() noise_tensor.set(noise_data, place) fake_temp = exe.run(fetch_list=[fake.name], feed={"noise": noise_tensor})[0] fake_image = np.reshape(fake_temp, (args.n_samples, -1)) fig = utility.plot(fake_image) plt.savefig(os.path.join(args.output, 'fake_dcgan.png'), bbox_inches='tight') plt.close(fig) else: raise NotImplementedError("model_net {} is not support".format( args.model_net)) if __name__ == "__main__": args = parser.parse_args() print_arguments(args) check_gpu(args.use_gpu) infer(args)
raise NotImplementedError('CGAN only support mnist now!') model = CGAN(cfg, train_reader) elif cfg.model_net == 'DCGAN': from trainer.DCGAN import DCGAN if cfg.dataset != 'mnist': raise NotImplementedError('DCGAN only support mnist now!') model = DCGAN(cfg, train_reader) elif cfg.model_net == 'CycleGAN': from trainer.CycleGAN import CycleGAN model = CycleGAN(cfg, a_reader, b_reader, a_reader_test, b_reader_test, batch_num) else: pass model.build_model() if __name__ == "__main__": cfg = config.parse_args() config.print_arguments(cfg) assert cfg.load_size >= cfg.crop_size, "Load Size CANNOT less than Crop Size!" if cfg.profile: if cfg.use_gpu: with profiler.profiler('All', 'total', '/tmp/profile') as prof: train(cfg) else: with profiler.profiler("CPU", sorted_key='total') as cpuprof: train(cfg) else: train(cfg)