New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how to transfer my handwriting font into other style #12
Comments
2017-05-08 14:38:43.505012: I tensorflow/core/common_runtime/gpu/gpu_device.cc:887] Found device 0 with properties: |
GPU的显存不够,要么换个显卡,要么缩小模型的规模。 |
模型的规模是不是指--sample_count=1000这个的值?作者训练了29000个图片吧?我把值改成500或300还是出现上述问题。。。是这个原因吗?而且运行train.py时很慢,每次都要二十多分钟。 |
|
If you can read Chinese : |
试了一下,调低batch_size和embedding_num对显存占用几乎没有帮助,显存占用是4.3G,我对这个模型不熟,还在研究,帮不了你。 不过infer只需要1.2G的显存,你倒是可以下载作者训练出来的模型去试试infer.py,或者你可以尝试用AWS、Google Cloud的GPU服务来自己训练,花不了多少钱。 至于说手写字转换风格,很有意思的想法,我之前也想到了这个,比如手写楷体可以变成手写草书之类的,要保留原手写体的「某些特征」,问题是要让机器知道要保留的是哪些特征。这个模型貌似目前还做不到。 如果要做的话,你首先需要收集一定量的数据:同一个人手写的各种字体,如草书、楷书、隶书等,然后再考虑模型怎么来调整吧。 |
when I using font2img.py , It generates a lot of images randomly in sample_dir. How can it generate character I want? And when I use infer.py , it generate images character was same as characters in save_dir , right? |
|
Thank you very much. |
I download your Pretrained Model .
Thanks a lot! |
@xsmxsm |
Thank you very much! Thanks a lot . |
@xsmxsm i don't understand your first question, the order should be the same with the order when u are running package.py embedding_ids means the corresponding font id, so each number between [1, 27] is one font style |
I enter "千山鸟飞绝万径人踪灭孤舟蓑笠翁独钓寒江雪" in 1.txt, |
this might be a glob's implementation problem. I will fix it later once i got time. |
|
@xsmxsm @kaonashi-tyc |
@windid I think the "source_obj" refer to the generated train.obj in package.py, it is used to provided the characters that you want to use. |
@windid yes your interpretation is correct. It refers to a single font id. source_obj is a pickled object that produced by package.py, could be either train.obj or val.obj. |
@xsmxsm the source should not be changed once trained. Infer.py is an already trained model, you should stick with the SIMSUN font, otherwise the result won't be optimal, since it is trained on that font. For your second question. Try to use SIMSUN(中易宋体) as the source font. The current algorithm does not generalize beyond its source font. |
@kaonashi-tyc You say , use SIMSUN(中易宋体) as the source font. Does it mean download SIMSUN font as the --src_font in font2img.py ? And then --tgt_font can be any style of ttf or otf that I want ? |
@kaonashi-tyc |
Hi @kaonashi-tyc , nice work!
|
@xsmxsm |
package.py you can modift it and get an right def pickle_examples(paths, train_path, val_path, train_val_split=0.1): you can modifit it and get Correct order |
@wysuperfly |
我把解决方案放在了新的提问上,可以看一下,很容易解决 |
@kaonashi-tyc @wysuperfly @vVVtreasure |
@kaonashi-tyc 我跳过了font2img.py这一步,用拍摄的手写汉字保存成512*256大小放在dir文件夹中,然后执行package.py 在save_dir中生成train.obj 文件,然后执行python infer.py --model_dir=font27 --batch_size=1 --source_obj=save_dir/train.obj --embedding_ids=8 --save_dir=save_dir |
@xsmxsm Infer是用来推导已经训练好的字体的样式的,你的手写字体是你自己的字体,你需要train一个新的model来达到这个目的 |
sorry, what I mean is not transfer source font style to my own , I mean transfer my own handwriting to the pretrained model , use my handwriting replace the source font style , can I do this ? |
No you cannot transfer your style to pretrained model. That model is frozen there is no learning happens during inference. And the pretrained model is trained only on one font style, SIMSUN, if you feed your own handwriting to it, chances are it is probably not going to work and the output is bad quality. |
Yes , you are right. 如果我希望把我手写的字体拍成的图片转换成其他的艺术风格,我虚否需要手写2000字以上来进行训练?但是有时候手写字体可能不会每个字的风格都一样,这会不会影响训练效果?在您的工程项目里,训练之前有两个其他步骤,font2img.py 和 package.py 第一步里面目标汉字书写在一个txt文档里面,我怎么能用我的手写汉字的图片来代替它呢? 希望能收到您详细的建议,非常感谢! |
@xsmxsm 所以,这个模型不是用来把你的手写字体转换成其他的艺术风格。他是帮你把你手写2000字的风格迁移到超过20000个字的整个中文字符集。 然后,你是否需要2000个手写字,理论上不需要,但实际取决于最后能不能达到你理想的效果,增加样本量是改善效果可能的途径之一。你需要的是实验。 同理,如果你2000个字里面风格差异太大,训练出来什么样也是没人知道。你需要的还是实验。 我一路看下来,你好像几乎没有机器学习的基础,也不知道你到底想干嘛。如果你是想好好学习机器学习,这个项目显然是不适合你入门的。 |
我的目的就是想让普通人的手写汉字风格可以具有艺术家的风格。就像 ougishi 软件的效果一样,既保留了原有手写体的内容,又有艺术家的风格。 在图片中这种效果已经实现了,将一个拍摄的图片迁移成艺术家的风格,同时保留了原图的内容。我想在书法这方面如何也能达到这种效果。 我刚接触深度学习不久,没啥基础,问的问题可能都是很低级的,还请您见谅。谢谢! |
@xsmxsm @windid I think we should avoid emotional talks in the issue discussion. But I agree with windid to some degree. Your objective and approach are not consistent in this case. One of the assumption of the model is that the source font is invariant. Via training, the model will learn a mapping to transform the source font to the target font. In that sense the whole network is just a function f(x) = y, where the x is the source font and y being the target font. If you use your own handwriting to substitute the source font here, since the model is not trained on your handwriting, it is likely to fail miserably. In other words, once the model is trained, the source font is fixed and should not be changed, otherwise there is no guarantee what the result would look like. I think this issue have diverged far enough, involving a lot of unnecessary argument, while lacking the substantial solution that will be useful to other people. I will close it for now, if you have any specific follow-up issue, feel free to open new issue. |
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)]]
The text was updated successfully, but these errors were encountered: