Learning Chinese Character style with conditional GAN

Overview

zi2zi: Master Chinese Calligraphy with Conditional Adversarial Networks

animation

Introduction

Learning eastern asian language typefaces with GAN. zi2zi(字到字, meaning from character to character) is an application and extension of the recent popular pix2pix model to Chinese characters.

Details could be found in this blog post.

Network Structure

Original Model

alt network

The network structure is based off pix2pix with the addition of category embedding and two other losses, category loss and constant loss, from AC-GAN and DTN respectively.

Updated Model with Label Shuffling

alt network

After sufficient training, d_loss will drop to near zero, and the model's performance plateaued. Label Shuffling mitigate this problem by presenting new challenges to the model.

Specifically, within a given minibatch, for the same set of source characters, we generate two sets of target characters: one with correct embedding labels, the other with the shuffled labels. The shuffled set likely will not have the corresponding target images to compute L1_Loss, but can be used as a good source for all other losses, forcing the model to further generalize beyond the limited set of provided examples. Empirically, label shuffling improves the model's generalization on unseen data with better details, and decrease the required number of characters.

You can enable label shuffling by setting flip_labels=1 option in train.py script. It is recommended that you enable this after d_loss flatlines around zero, for further tuning.

Gallery

Compare with Ground Truth

compare

Brush Writing Fonts

brush

Cursive Script (Requested by SNS audience)

cursive

Mingchao Style (宋体/明朝体)

gaussian

Korean

korean

Interpolation

animation

Animation

animation animation

easter egg

How to Use

Step Zero

Download tons of fonts as you please

Requirement

  • Python 2.7
  • CUDA
  • cudnn
  • Tensorflow >= 1.0.1
  • Pillow(PIL)
  • numpy >= 1.12.1
  • scipy >= 0.18.1
  • imageio

Preprocess

To avoid IO bottleneck, preprocessing is necessary to pickle your data into binary and persist in memory during training.

First run the below command to get the font images:

python font2img.py --src_font=src.ttf
                   --dst_font=tgt.otf
                   --charset=CN 
                   --sample_count=1000
                   --sample_dir=dir
                   --label=0
                   --filter=1
                   --shuffle=1

Four default charsets are offered: CN, CN_T(traditional), JP, KR. You can also point it to a one line file, it will generate the images of the characters in it. Note, filter option is highly recommended, it will pre sample some characters and filter all the images that have the same hash, usually indicating that character is missing. label indicating index in the category embeddings that this font associated with, default to 0.

After obtaining all images, run package.py to pickle the images and their corresponding labels into binary format:

python package.py --dir=image_directories
                  --save_dir=binary_save_directory
                  --split_ratio=[0,1]

After running this, you will find two objects train.obj and val.obj under the save_dir for training and validation, respectively.

Experiment Layout

experiment/
└── data
    ├── train.obj
    └── val.obj

Create a experiment directory under the root of the project, and a data directory within it to place the two binaries. Assuming a directory layout enforce bettet data isolation, especially if you have multiple experiments running.

Train

To start training run the following command

python train.py --experiment_dir=experiment 
                --experiment_id=0
                --batch_size=16 
                --lr=0.001
                --epoch=40 
                --sample_steps=50 
                --schedule=20 
                --L1_penalty=100 
                --Lconst_penalty=15

schedule here means in between how many epochs, the learning rate will decay by half. The train command will create sample,logs,checkpoint directory under experiment_dir if non-existed, where you can check and manage the progress of your training.

Infer and Interpolate

After training is done, run the below command to infer test data:

python infer.py --model_dir=checkpoint_dir/ 
                --batch_size=16 
                --source_obj=binary_obj_path 
                --embedding_ids=label[s] of the font, separate by comma
                --save_dir=save_dir/

Also you can do interpolation with this command:

python infer.py --model_dir= checkpoint_dir/ 
                --batch_size=10
                --source_obj=obj_path 
                --embedding_ids=label[s] of the font, separate by comma
                --save_dir=frames/ 
                --output_gif=gif_path 
                --interpolate=1 
                --steps=10
                --uroboros=1

It will run through all the pairs of fonts specified in embedding_ids and interpolate the number of steps as specified.

Pretrained Model

Pretained model can be downloaded here which is trained with 27 fonts, only generator is saved to reduce the model size. You can use encoder in the this pretrained model to accelerate the training process.

Acknowledgements

Code derived and rehashed from:

License

Apache 2.0

Comments
  • how to transfer my handwriting font into other style

    how to transfer my handwriting font into other style

    when doing this step : python font2img.py --src_font=src.ttf --dst_font=tgt.otf it generated 1000 random font image ,can i use my expected font to generate image? can i use my handwriting font image and transfer it into my expect style? thank you !

    运行font2img.py 时,使用的是下载的两个ttf字体和otf字体,生成的1000张图片中的字都是随机的,能不能选用我想要生成的字?此外,这个模型能不能把我自己手写的字拍成的图片转变为我期待的风格? 另外,我在运行train.py时,总是出错如下: 2017-05-08 14:20:19.059104: I tensorflow/core/common_runtime/bfc_allocator.cc:700] Sum Total of in-use chunks: 1.41GiB 2017-05-08 14:20:19.059115: I tensorflow/core/common_runtime/bfc_allocator.cc:702] Stats: Limit: 1605828608 InUse: 1517696256 MaxInUse: 1605828608 NumAllocs: 353 MaxAllocSize: 134217728

    2017-05-08 14:20:19.059144: W tensorflow/core/common_runtime/bfc_allocator.cc:277] xx*****************************************************xx***********************xx 2017-05-08 14:20:19.059163: W tensorflow/core/framework/op_kernel.cc:1152] Resource exhausted: OOM when allocating tensor with shape[5,5,512,1024] Traceback (most recent call last): File "train.py", line 62, in tf.app.run() File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/app.py", line 48, in run _sys.exit(main(_sys.argv[:1] + flags_passthrough)) File "train.py", line 58, in main sample_steps=args.sample_steps, checkpoint_steps=args.checkpoint_steps) File "/home/xsm/zi2zi-master/model/unet.py", line 465, in train tf.global_variables_initializer().run() File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 1552, in run _run_using_default_session(self, feed_dict, self.graph, session) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 3776, in _run_using_default_session session.run(operation, feed_dict) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 778, in run run_metadata_ptr) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 982, in _run feed_dict_string, options, run_metadata) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 1032, in _do_run target_list, options, run_metadata) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 1052, in _do_call raise type(e)(node_def, op, message) tensorflow.python.framework.errors_impl.ResourceExhaustedError: OOM when allocating tensor with shape[512] [[Node: generator/g_d4_deconv/b/Assign = Assign[T=DT_FLOAT, _class=["loc:@generator/g_d4_deconv/b"], use_locking=true, validate_shape=true, _device="/job:localhost/replica:0/task:0/gpu:0"](generator/g_d4_deconv/b, generator/g_d4_deconv/b/Initializer/Const)]]

    Caused by op u'generator/g_d4_deconv/b/Assign', defined at: File "train.py", line 62, in tf.app.run() File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/app.py", line 48, in run _sys.exit(main(_sys.argv[:1] + flags_passthrough)) File "train.py", line 51, in main model.build_model(is_training=True, inst_norm=args.inst_norm) File "/home/xsm/zi2zi-master/model/unet.py", line 167, in build_model inst_norm=inst_norm) File "/home/xsm/zi2zi-master/model/unet.py", line 133, in generator output = self.decoder(embedded, enc_layers, embedding_ids, inst_norm, is_training=is_training, reuse=reuse) File "/home/xsm/zi2zi-master/model/unet.py", line 119, in decoder d4 = decode_layer(d3, s16, self.generator_dim * 8, layer=4, enc_layer=encoding_layers["e4"]) File "/home/xsm/zi2zi-master/model/unet.py", line 98, in decode_layer output_width, output_filters], scope="g_d%d_deconv" % layer) File "/home/xsm/zi2zi-master/model/ops.py", line 35, in deconv2d biases = tf.get_variable('b', [output_shape[-1]], initializer=tf.constant_initializer(0.0)) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/variable_scope.py", line 1049, in get_variable use_resource=use_resource, custom_getter=custom_getter) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/variable_scope.py", line 948, in get_variable use_resource=use_resource, custom_getter=custom_getter) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/variable_scope.py", line 356, in get_variable validate_shape=validate_shape, use_resource=use_resource) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/variable_scope.py", line 341, in _true_getter use_resource=use_resource) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/variable_scope.py", line 714, in _get_single_variable validate_shape=validate_shape) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/variables.py", line 197, in init expected_shape=expected_shape) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/variables.py", line 306, in _init_from_args validate_shape=validate_shape).op File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/state_ops.py", line 270, in assign validate_shape=validate_shape) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gen_state_ops.py", line 47, in assign use_locking=use_locking, name=name) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/op_def_library.py", line 768, in apply_op op_def=op_def) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 2336, in create_op original_op=self._default_original_op, op_def=op_def) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 1228, in init self._traceback = _extract_stack()

    ResourceExhaustedError (see above for traceback): OOM when allocating tensor with shape[512] [[Node: generator/g_d4_deconv/b/Assign = Assign[T=DT_FLOAT, _class=["loc:@generator/g_d4_deconv/b"], use_locking=true, validate_shape=true, _device="/job:localhost/replica:0/task:0/gpu:0"](generator/g_d4_deconv/b, generator/g_d4_deconv/b/Initializer/Const)]]

    opened by xsmxsm 36
  • why the input image of generator contains  target text ?

    why the input image of generator contains target text ?

    the shape of input is (batch_size,256,256,6), the first 3 chanels is image of target font, why?I thought it would make generator cheat... In my test, if set all value of first 3 chanels to zero. the image generated was not the same, although the difference was not big as I thought, that is not what we expect,right?

    opened by ChuangLee 10
  • tensor not exist in the checkpoint pcgreat/zi2zi

    tensor not exist in the checkpoint pcgreat/zi2zi

    Hey guy is me again Sorry about I'm taking pcgreat/zi2zi at here Because I can't found the place to let me discuss As tittle and preamble #64 key generator/g_d1_bn/beta not found in checkpoint So I use tensorflow.python.tools inspect_checkpoint.py to watch my checkpoint And I compared the pcgreat/zi2zi model and kaonashi-tyc/zi2zi model with the checkpoint Screen Shot 2019-04-13 at 2 41 13 AM left is pcgreat/zi2zi right is kaonashi-tyc/zi2zi And you can see some tensor is not exist in the pcgreat/zi2zi checkpoint I was wondering if someone can tell me and fix it

    the same as past I and still try to solve this problem This is my contact information. mail: [email protected] I look forward to discussing with you.

    opened by Henry658 9
  • font2img.py error

    font2img.py error

    :~/zi2zi$ python font2img.py --src_font=src.ttf \

                   --dst_font=tgt.otf \
                   --charset=CN \
                   --sample_count=1000 \
                   --sample_dir=dir \
                   --label=0 \
                   --filter=1 \
                   --shuffle=1
    

    Traceback (most recent call last): File "font2img.py", line 120, in args.sample_count, args.sample_dir, args.label, args.filter) File "font2img.py", line 72, in font2img src_font = ImageFont.truetype(src, size=char_size) File "/Users/Ru/anaconda/envs/gan/lib/python2.7/site-packages/PIL/ImageFont.py", line 238, in truetype return FreeTypeFont(font, size, index, encoding) File "/Users/Ru/anaconda/envs/gan/lib/python2.7/site-packages/PIL/ImageFont.py", line 127, in init self.font = core.getfont(font, size, index, encoding) IOError: cannot open resource

    @kaonashi-tyc thank you!

    opened by Shuolongbj 7
  • I would like to apply the project to Chinese calligraphy. I wonder if it is feasible?

    I would like to apply the project to Chinese calligraphy. I wonder if it is feasible?

    For example: I have 3000 character pictures of a calligrapher, I am now looking for a ttf font as a source, with the calligrapher character pictures as the destination for training. A little bit different from this project, it will appear, the same character, calligrapher will have a variety of writing. Generated images with ttf font when generated. Can you predict whether such training can achieve the desired result? Thank you very much for the project. It was great!

    opened by JianChi8 5
  • cc:184  Key generator/g_d1_bn/beta not found in checkpoint

    cc:184 Key generator/g_d1_bn/beta not found in checkpoint

    when I run pcgreat/zi2zi do the instruction have the error I am not sure that i am get the train model in my Issues problem #59 I suppose that I am success get the model in the correct model_dir but have the error info that cc:184 Key generator/g_d1_bn/beta not found in checkpoint How should I fixed this problem ?

    the following text is my input instruction and the terminal log

    Infer

    PYTHONPATH=. python infer.py --model_dir=experiments/checkpoint/experiment_0
    --batch_size=32
    --source_obj=experiments/data/val.obj
    --embedding_ids=0
    --save_dir=save_dir/

    (py36) sjshyu@sjshyu-titan:~/Desktop/360315$ sh test.sh 2019-03-29 14:10:03.478788: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX AVX2 FMA 2019-03-29 14:10:03.660390: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1356] Found device 0 with properties: name: GeForce GTX TITAN X major: 5 minor: 2 memoryClockRate(GHz): 1.076 pciBusID: 0000:02:00.0 totalMemory: 11.92GiB freeMemory: 11.17GiB 2019-03-29 14:10:03.792179: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1356] Found device 1 with properties: name: GeForce GTX TITAN X major: 5 minor: 2 memoryClockRate(GHz): 1.076 pciBusID: 0000:81:00.0 totalMemory: 11.92GiB freeMemory: 11.80GiB 2019-03-29 14:10:03.792283: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1435] Adding visible gpu devices: 0, 1 2019-03-29 14:10:04.332448: I tensorflow/core/common_runtime/gpu/gpu_device.cc:923] Device interconnect StreamExecutor with strength 1 edge matrix: 2019-03-29 14:10:04.332508: I tensorflow/core/common_runtime/gpu/gpu_device.cc:929] 0 1 2019-03-29 14:10:04.332519: I tensorflow/core/common_runtime/gpu/gpu_device.cc:942] 0: N N 2019-03-29 14:10:04.332524: I tensorflow/core/common_runtime/gpu/gpu_device.cc:942] 1: N N 2019-03-29 14:10:04.333112: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1053] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 10816 MB memory) -> physical GPU (device: 0, name: GeForce GTX TITAN X, pci bus id: 0000:02:00.0, compute capability: 5.2) 2019-03-29 14:10:04.333703: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1053] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:1 with 11430 MB memory) -> physical GPU (device: 1, name: GeForce GTX TITAN X, pci bus id: 0000:81:00.0, compute capability: 5.2) unpickled total 946 examples examples -> 946 2019-03-29 14:10:07.096577: W tensorflow/core/framework/op_kernel.cc:1318] OP_REQUIRES failed at save_restore_v2_ops.cc:184 : Not found: Key generator/g_d1_bn/beta not found in checkpoint Traceback (most recent call last): File "/home/sjshyu/.conda/envs/py36/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1322, in _do_call return fn(*args) File "/home/sjshyu/.conda/envs/py36/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1307, in _run_fn options, feed_dict, fetch_list, target_list, run_metadata) File "/home/sjshyu/.conda/envs/py36/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1409, in _call_tf_sessionrun run_metadata) tensorflow.python.framework.errors_impl.NotFoundError: Key generator/g_d1_bn/beta not found in checkpoint [[Node: save/RestoreV2 = RestoreV2[dtypes=[DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, ..., DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT], _device="/job:localhost/replica:0/task:0/device:CPU:0"](_arg_save/Const_0_0, save/RestoreV2/tensor_names, save/RestoreV2/shape_and_slices)]] [[Node: save/RestoreV2/_149 = _Recvclient_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device_incarnation=1, tensor_name="edge_154_save/RestoreV2", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:GPU:0"]]

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last): File "infer.py", line 67, in tf.app.run() File "/home/sjshyu/.conda/envs/py36/lib/python3.6/site-packages/tensorflow/python/platform/app.py", line 126, in run _sys.exit(main(argv)) File "infer.py", line 47, in main save_dir=args.save_dir) File "/home/sjshyu/Desktop/360315/model/unet.py", line 446, in infer self.load_model(model_dir) File "/home/sjshyu/Desktop/360315/model/unet.py", line 469, in load_model self.restore_model(saver, model_dir) File "/home/sjshyu/Desktop/360315/model/unet.py", line 357, in restore_model saver.restore(self.sess, ckpt.model_checkpoint_path) File "/home/sjshyu/.conda/envs/py36/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 1802, in restore {self.saver_def.filename_tensor_name: save_path}) File "/home/sjshyu/.conda/envs/py36/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 900, in run run_metadata_ptr) File "/home/sjshyu/.conda/envs/py36/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1135, in _run feed_dict_tensor, options, run_metadata) File "/home/sjshyu/.conda/envs/py36/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1316, in _do_run run_metadata) File "/home/sjshyu/.conda/envs/py36/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1335, in _do_call raise type(e)(node_def, op, message) tensorflow.python.framework.errors_impl.NotFoundError: Key generator/g_d1_bn/beta not found in checkpoint [[Node: save/RestoreV2 = RestoreV2[dtypes=[DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, ..., DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT], _device="/job:localhost/replica:0/task:0/device:CPU:0"](_arg_save/Const_0_0, save/RestoreV2/tensor_names, save/RestoreV2/shape_and_slices)]] [[Node: save/RestoreV2/_149 = _Recvclient_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device_incarnation=1, tensor_name="edge_154_save/RestoreV2", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:GPU:0"]]

    Caused by op 'save/RestoreV2', defined at: File "infer.py", line 67, in tf.app.run() File "/home/sjshyu/.conda/envs/py36/lib/python3.6/site-packages/tensorflow/python/platform/app.py", line 126, in run _sys.exit(main(argv)) File "infer.py", line 47, in main save_dir=args.save_dir) File "/home/sjshyu/Desktop/360315/model/unet.py", line 446, in infer self.load_model(model_dir) File "/home/sjshyu/Desktop/360315/model/unet.py", line 468, in load_model saver = tf.train.Saver(var_list=self.retrieve_generator_vars()) File "/home/sjshyu/.conda/envs/py36/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 1338, in init self.build() File "/home/sjshyu/.conda/envs/py36/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 1347, in build self._build(self._filename, build_save=True, build_restore=True) File "/home/sjshyu/.conda/envs/py36/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 1384, in _build build_save=build_save, build_restore=build_restore) File "/home/sjshyu/.conda/envs/py36/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 835, in _build_internal restore_sequentially, reshape) File "/home/sjshyu/.conda/envs/py36/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 472, in _AddRestoreOps restore_sequentially) File "/home/sjshyu/.conda/envs/py36/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 886, in bulk_restore return io_ops.restore_v2(filename_tensor, names, slices, dtypes) File "/home/sjshyu/.conda/envs/py36/lib/python3.6/site-packages/tensorflow/python/ops/gen_io_ops.py", line 1463, in restore_v2 shape_and_slices=shape_and_slices, dtypes=dtypes, name=name) File "/home/sjshyu/.conda/envs/py36/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper op_def=op_def) File "/home/sjshyu/.conda/envs/py36/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 3392, in create_op op_def=op_def) File "/home/sjshyu/.conda/envs/py36/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1718, in init self._traceback = self._graph._extract_stack() # pylint: disable=protected-access

    NotFoundError (see above for traceback): Key generator/g_d1_bn/beta not found in checkpoint [[Node: save/RestoreV2 = RestoreV2[dtypes=[DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, ..., DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT], _device="/job:localhost/replica:0/task:0/device:CPU:0"](_arg_save/Const_0_0, save/RestoreV2/tensor_names, save/RestoreV2/shape_and_slices)]] [[Node: save/RestoreV2/_149 = _Recvclient_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device_incarnation=1, tensor_name="edge_154_save/RestoreV2", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:GPU:0"]]

    This is my contact information. mail: [email protected] I look forward to discussing with you.

    opened by Henry658 4
  • where is

    where is "embedding" being trained?

    Hi, thanks for sharing nice work.

    I guess embedding of each font should be trained somewhere. init_embedding() creates the embedding variable under scope "embedding" but I cannot find it being used in any optimizer. d_optimizer trains variables with prefix "d_" and g_optimizer trains "g_" where none of both includes "embedding" or "E".

    Could you provide some explanation?

    opened by youngjung-obsolete 4
  • ValueError: Could not find a format to write the specified file in mode 'I'

    ValueError: Could not find a format to write the specified file in mode 'I'

    Hi yc, I encountered the following error doing interpolation with running infer.py, I've pip installed imageio and ffmpeg already, how come this error still exists? BTW, actually when i “dpkg -L imageio'' it says imageio is not installed. I'm not quite sure what is the problem:

    Traceback (most recent call last): File "infer.py", line 67, in tf.app.run() File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/app.py", line 48, in run _sys.exit(main(_sys.argv[:1] + flags_passthrough)) File "infer.py", line 62, in main compile_frames_to_gif(args.save_dir, gif_path) File "/home/Downloads/zi2zi-master/model/utils.py", line 76, in compile_frames_to_gif imageio.mimsave(gif_file, images, duration=0.1) File "/usr/local/lib/python2.7/dist-packages/imageio/core/functions.py", line 302, in mimwrite writer = get_writer(uri, format, 'I', **kwargs) File "/usr/local/lib/python2.7/dist-packages/imageio/core/functions.py", line 153, in get_writer 'in mode %r' % mode) ValueError: Could not find a format to write the specified file in mode 'I'

    opened by ALABAMABANANA 4
  • How to use the pretrained model?

    How to use the pretrained model?

    Awesome Project! But i can not figure out how to the pretrained model. Should we put the pretrained model into the directory experiment/checkpoint/? Does it need rename?

    opened by gdshen 4
  • fail to restore model experiment/checkpoint/experimet_0_batch_32

    fail to restore model experiment/checkpoint/experimet_0_batch_32

    Hey guy when I run pcgreat/zi2zi do the instruction //infer PYTHONPATH=. python infer.py --model_dir=experiments/checkpoint/experiment_0_batch_32
    --batch_size=32
    --source_obj=experiments/data/val.obj
    --embedding_ids=0
    --save_dir=save_dir/

    have the error

    2019-01-20 08:44:22.462571: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA 2019-01-20 08:44:22.637878: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1405] Found device 0 with properties: name: GeForce GTX TITAN X major: 5 minor: 2 memoryClockRate(GHz): 1.076 pciBusID: 0000:02:00.0 totalMemory: 11.92GiB freeMemory: 11.32GiB 2019-01-20 08:44:22.787590: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1405] Found device 1 with properties: name: GeForce GTX TITAN X major: 5 minor: 2 memoryClockRate(GHz): 1.076 pciBusID: 0000:81:00.0 totalMemory: 11.92GiB freeMemory: 11.80GiB 2019-01-20 08:44:22.787658: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1484] Adding visible gpu devices: 0, 1 2019-01-20 08:44:23.380931: I tensorflow/core/common_runtime/gpu/gpu_device.cc:965] Device interconnect StreamExecutor with strength 1 edge matrix: 2019-01-20 08:44:23.380980: I tensorflow/core/common_runtime/gpu/gpu_device.cc:971] 0 1 2019-01-20 08:44:23.380988: I tensorflow/core/common_runtime/gpu/gpu_device.cc:984] 0: N N 2019-01-20 08:44:23.380993: I tensorflow/core/common_runtime/gpu/gpu_device.cc:984] 1: N N 2019-01-20 08:44:23.381479: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1097] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 10947 MB memory) -> physical GPU (device: 0, name: GeForce GTX TITAN X, pci bus id: 0000:02:00.0, compute capability: 5.2) 2019-01-20 08:44:23.381966: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1097] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:1 with 11421 MB memory) -> physical GPU (device: 1, name: GeForce GTX TITAN X, pci bus id: 0000:81:00.0, compute capability: 5.2) processed 1000 examples processed 2000 examples unpickled total 2891 examples examples -> 2891 fail to restore model experiments/checkpoint/experiment_0_batch_32

    fail to restore model how to resolve it ? thanks

    opened by Henry658 2
  • package.py: error: argument --split_ratio: invalid float value: '[0,1]'

    package.py: error: argument --split_ratio: invalid float value: '[0,1]'

    Hi, I got the following message when running package.py :

    package.py: error: argument --split_ratio: invalid float value: '[0,1]'

    Any hints I could solve it? thanks!

    opened by chikiuso 2
  • category_loss is always 0

    category_loss is always 0

    category_loss is always 0, when i use font2img to generate images,the label is default 0, and when training the lable of images is,so the loss to compute real_category_loss and fake_category_loss is always 0, i don't know why label is 0?

    opened by cqray1990 0
  • d_loss_real and d_loss_fake near 0 after training for some step.d_loss_real 和d_loss_fake在几次训练后都变成0 不动了

    d_loss_real and d_loss_fake near 0 after training for some step.d_loss_real 和d_loss_fake在几次训练后都变成0 不动了

    我用tensoflow2按1的代码复原了网络,但是训练的时候d_loss_real 和d_loss_fake 很快都下降到0.

    最终的generator只能得到一张空白的图片。

    加载他的预训练的generator参数继续训练也是一样,d_loss接近0。

    不知道是我代码写错了吗。。。检查了好久没发现。。。

    求助!!!

    opened by zongzhimin 3
  • about font2image.py

    about font2image.py

    The existing script can randomly sample 2000 characters to generate images. How to select the type of character to generate, or how to fix the order of character generation instead of random sampling. Where can I modify it in code

    opened by yao269220079 1
Owner
Yuchen Tian
Born in the year of Snake, now stuck with Python.
Yuchen Tian
a pytorch implementation of auto-punctuation learned character by character

Learning Auto-Punctuation by Reading Engadget Articles Link to Other of my work ?? Deep Learning Notes: A collection of my notes going from basic mult

Ge Yang 137 Nov 9, 2022
a pytorch implementation of auto-punctuation learned character by character

Learning Auto-Punctuation by Reading Engadget Articles Link to Other of my work ?? Deep Learning Notes: A collection of my notes going from basic mult

Ge Yang 137 Nov 9, 2022
Transfer style api - An API to use with Tranfer Style App, where you can use two image and transfer the style

Transfer Style API It's an API to use with Tranfer Style App, where you can use

Brian Alejandro 1 Feb 13, 2022
PyTorch 1.5 implementation for paper DECOR-GAN: 3D Shape Detailization by Conditional Refinement.

DECOR-GAN PyTorch 1.5 implementation for paper DECOR-GAN: 3D Shape Detailization by Conditional Refinement, Zhiqin Chen, Vladimir G. Kim, Matthew Fish

Zhiqin Chen 72 Dec 31, 2022
Official implementation of the paper Chunked Autoregressive GAN for Conditional Waveform Synthesis

Chunked Autoregressive GAN (CARGAN) Official implementation of the paper Chunked Autoregressive GAN for Conditional Waveform Synthesis [paper] [compan

Descript 150 Dec 6, 2022
Official pytorch code for SSC-GAN: Semi-Supervised Single-Stage Controllable GANs for Conditional Fine-Grained Image Generation(ICCV 2021)

SSC-GAN_repo Pytorch implementation for 'Semi-Supervised Single-Stage Controllable GANs for Conditional Fine-Grained Image Generation'.PDF SSC-GAN:Sem

tyty 4 Aug 28, 2022
PyTorch implementation for OCT-GAN Neural ODE-based Conditional Tabular GANs (WWW 2021)

OCT-GAN: Neural ODE-based Conditional Tabular GANs (OCT-GAN) Code for reproducing the experiments in the paper: Jayoung Kim*, Jinsung Jeon*, Jaehoon L

BigDyL 7 Dec 27, 2022
Pytorch implementation of the paper "Enhancing Content Preservation in Text Style Transfer Using Reverse Attention and Conditional Layer Normalization"

Pytorch implementation of the paper "Enhancing Content Preservation in Text Style Transfer Using Reverse Attention and Conditional Layer Normalization"

Dongkyu Lee 4 Sep 18, 2022
FuseDream: Training-Free Text-to-Image Generationwith Improved CLIP+GAN Space OptimizationFuseDream: Training-Free Text-to-Image Generationwith Improved CLIP+GAN Space Optimization

FuseDream This repo contains code for our paper (paper link): FuseDream: Training-Free Text-to-Image Generation with Improved CLIP+GAN Space Optimizat

XCL 191 Dec 31, 2022
Simple torch.nn.module implementation of Alias-Free-GAN style filter and resample

Alias-Free-Torch Simple torch module implementation of Alias-Free GAN. This repository including Alias-Free GAN style lowpass sinc filter @filter.py A

이준혁(Junhyeok Lee) 64 Dec 22, 2022
Style-based Neural Drum Synthesis with GAN inversion

Style-based Drum Synthesis with GAN Inversion Demo TensorFlow implementation of a style-based version of the adversarial drum synth (ADS) from the pap

Sound and Music Analysis (SoMA) Group 29 Nov 19, 2022
Only a Matter of Style: Age Transformation Using a Style-Based Regression Model

Only a Matter of Style: Age Transformation Using a Style-Based Regression Model The task of age transformation illustrates the change of an individual

null 444 Dec 30, 2022
Fast Neural Style for Image Style Transform by Pytorch

FastNeuralStyle by Pytorch Fast Neural Style for Image Style Transform by Pytorch This is famous Fast Neural Style of Paper Perceptual Losses for Real

Bengxy 81 Sep 3, 2022
VITS: Conditional Variational Autoencoder with Adversarial Learning for End-to-End Text-to-Speech

VITS: Conditional Variational Autoencoder with Adversarial Learning for End-to-End Text-to-Speech Jaehyeon Kim, Jungil Kong, and Juhee Son In our rece

Jaehyeon Kim 1.7k Jan 8, 2023
Official implementation of the paper DeFlow: Learning Complex Image Degradations from Unpaired Data with Conditional Flows

DeFlow: Learning Complex Image Degradations from Unpaired Data with Conditional Flows Official implementation of the paper DeFlow: Learning Complex Im

Valentin Wolf 86 Nov 16, 2022
CharacterGAN: Few-Shot Keypoint Character Animation and Reposing

CharacterGAN Implementation of the paper "CharacterGAN: Few-Shot Keypoint Character Animation and Reposing" by Tobias Hinz, Matthew Fisher, Oliver Wan

Tobias Hinz 181 Dec 27, 2022
Character Controllers using Motion VAEs

Character Controllers using Motion VAEs This repo is the codebase for the SIGGRAPH 2020 paper with the title above. Please find the paper and demo at

Electronic Arts 165 Jan 3, 2023
Implementation of character based convolutional neural network

Character Based CNN This repo contains a PyTorch implementation of a character-level convolutional neural network for text classification. The model a

Ahmed BESBES 248 Nov 21, 2022
GeneralOCR is open source Optical Character Recognition based on PyTorch.

Introduction GeneralOCR is open source Optical Character Recognition based on PyTorch. It makes a fidelity and useful tool to implement SOTA models on

null 57 Dec 29, 2022