sjvasquez / handwriting-synthesis Goto Github PK
View Code? Open in Web Editor NEWHandwriting Synthesis with RNNs ✏️
Handwriting Synthesis with RNNs ✏️
Any idea about this error? I get it when running python demo.py
18.04 Ubuntu running stock Python 2.7.15rc1
Have installed:
apt install python-tk
pip install numpy svgwrite matplotlib scipy tensorflow pandas sklearn
Full error:
Traceback (most recent call last): File "demo.py", line 153, in <module> hand = Hand() File "demo.py", line 37, in __init__ attention_mixture_components=10 File "/home/john/handwriting-synthesis/rnn.py", line 85, in __init__ super(rnn, self).__init__(**kwargs) File "/home/john/handwriting-synthesis/tf_base_model.py", line 108, in __init__ self.graph = self.build_graph() File "/home/john/handwriting-synthesis/tf_base_model.py", line 399, in build_graph self.loss = self.calculate_loss() File "/home/john/handwriting-synthesis/rnn.py", line 204, in calculate_loss lambda: self.sample(cell) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/util/deprecation.py", line 432, in new_func return func(*args, **kwargs) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/control_flow_ops.py", line 2063, in cond orig_res_t, res_t = context_t.BuildCondBranch(true_fn) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/control_flow_ops.py", line 1913, in BuildCondBranch original_result = fn() File "/home/john/handwriting-synthesis/rnn.py", line 203, in <lambda> lambda: self.primed_sample(cell), File "/home/john/handwriting-synthesis/rnn.py", line 162, in primed_sample scope='rnn' File "/home/john/handwriting-synthesis/rnn_ops.py", line 246, in rnn_free_run states, outputs, final_state = raw_rnn(cell, loop_fn, scope=scope) File "/home/john/handwriting-synthesis/rnn_ops.py", line 40, in raw_rnn if context.in_graph_mode(): AttributeError: 'module' object has no attribute 'in_graph_mode'
Output is aligned to the center, how do I align it to the left?
Thanks
Hi, in its current form, this repo is unusable without too much hassle.
I have successfully migrated this to tfv2, so you don't need to waste your time
I'm planning to add web GUI and docker image too
System:
Error:
Traceback (most recent call last):
File "test.py", line 1, in <module>
import demo
File "C:\Projects\ml\handwriting-synthesis\demo.py", line 9, in <module>
from rnn import rnn
File "C:\Projects\ml\handwriting-synthesis\rnn.py", line 10, in <module>
from rnn_ops import rnn_free_run
File "C:\Projects\ml\handwriting-synthesis\rnn_ops.py", line 9, in <module>
from tensorflow.python.ops.rnn_cell_impl import _concat, _like_rnncell
ImportError: cannot import name '_like_rnncell'
Solution:
Hacky, but I simply removed the reference to _like_rnncell
on lines 9, 29, and 30 in rnn_ops.py. Seems to run fine afterwards (though this led to encountering Issue #17).
At multiple places int32 is being used for tensorflow computations. As you know, this prevents the code from using GPU. See this StackOverflow.
Could you please elaborate on why using float64 be a bad idea?
How much would the code need to be changed to make this happen?
Is this doable?
The defined alphabet is missing 'Q', 'X' and 'Z' characters. Is there any reason behind this?
EDIT: Answering myself, this is probably due to low number of samples for those characters in the dataset.
I haven't found the version of this repo to work with latest Python 3.8 and TensorFlow 2.4, so working on updating it.
I used the TensorFlow upgrade scripts recommended by TensorFlow to convert the code from 1.X to 2.X. It can be found here https://www.tensorflow.org/guide/upgrade
Haven't completely converted yet, but working on it. Looks like there are some functions that are deprecated. Is anyone else working on upgrading to work with TF 2? Thanks
Something strange happens but only with the few of the consecutive letters like:
HHHHHHHHHHH
EEEEEEEEEEEEEEE
AAAAAAAAAAAA
KKKKKKKKKKKKK
ZZZZZZZZZZZZZ
XXXXXXXXXXXXX
BBBBBBBBBBBBB
Result are unexpected, by having either completely weird output or something unexpected like just single parallel lines
The results are impressive, perhaps you can upgrade to using tf 2.x OR give instructions on how to install using tf 1.x. OR allow us to use calligrapher.ai programmatically.
I'm trying to create a portable windows library of it but tensorflow.contrib must be removed.
I tried to install an older setup and still doesn't work.
Python: 3.5.4
TensorFlow: 1.6.0
Traceback (most recent call last):
File "R:\handwriting-synthesis-master\demo.py", line 9, in <module>
from rnn import rnn
File "R:\handwriting-synthesis-master\rnn.py", line 9, in <module>
from rnn_cell import LSTMAttentionCell
File "R:\handwriting-synthesis-master\rnn_cell.py", line 16, in <module>
class LSTMAttentionCell(tf.compat.v1.nn.rnn_cell.RNNCell):
AttributeError: module 'tensorflow.python.util.compat' has no attribute 'v1'
would you please give us a working environment? which python+tensorflow version would be appropriate?
How can I create a new dataset from images of handwriting? Are the XML files in the IAM set some sort of SVG format that I could interpret my images into? How many writing samples should it take to decently train the model?
I just finished running a re-training session and the results were extremely impressive! However I'm noticing a loss in numbers. What are some ways I could improve the training?
Hi Everyone,
Is anyone aware of a public forum to tackle questions about this information? I believe this part of the forum is for technical bug's more then Q&A.
I would like to add a slight slant to the end of the sentences as most normal handwriting takes this into account as they slide to the end of the paper.
Hi. where did you get the stroke.npy from for each of the styles?
I am trying to train the model. I have prepared the data by running prepare_data.py. When I run the rnn.py I am getting the following error:
Traceback (most recent call last):
File "rnn.py", line 235, in
nn.fit()
File "D:\Data\handwriting-synthesis-master\handwriting-synthesis-master\tf_base_model.py", line 163, in fit
fetches=[self.loss] + self.metrics.values(),
TypeError: can only concatenate list (not "dict_values") to list
Waiting for your reply. Thanks...
Why did you use following code ?
-1*int(point.attrib['y']),
I think it should
int(point.attrib['y']),
handwriting-synthesis/prepare_data.py
Line 19 in 5f58984
Ran across https://www.calligrapher.ai on HN and someone mentioned that this repo appeared to be the source for that (or at least, the tech used). If so, that might be cool to call out in the readme.
There's technically no license in this repo, so depending on where you live this code is all rights reserved despite what's at the bottom of the readme, so if that's just someone who used your code without informing you, I guess you might now know >_>
Hello 👋 I would like to know if it possible to train a model on other languages like Hebrew, if u can help me with that I will be very happy 😊 THX🙏
is there a script that allows us to create our own style files from drawing, or a link to the program that was used to generate them? ^_^
First of all, thanks for this amazing tool! It looks incredible. I'm having a little trouble getting it to run locally with Python3 on my Macbook, but that may because I'm not super familiar with python.
Here's the error when I run python3 demo.py
File "/handwriting-synthesis/rnn_ops.py", line 246, in rnn_free_run
states, outputs, final_state = raw_rnn(cell, loop_fn, scope=scope)
File "/handwriting-synthesis/rnn_ops.py", line 40, in raw_rnn
if context.in_graph_mode():
AttributeError: module 'tensorflow.python.eager.context' has no attribute 'in_graph_mode'
I found tensorflow/tensorflow#14069 which suggested trying
pip install --upgrade --force-reinstall tf-nightly
but they're talking mostly about 1.3 and 1.4 there, while I see you have 1.6 in the requirements.txt.
Can you point me in the right direction?
I would like to use this code for a Project. Could you please create a LICENSE.md file, stating the type of license you are using?
💡 Tip:
MIT License would be great for this project.
Hello, is it posibble add new language ? How i can do it. thanks
Demo 3 is "Rick Astley - Never Gonna Give You Up", not "Leonard Cohen - Hallelujah".
I would like to generate some words with accentuation marks, like those in Spanish, Portuguese or French. I know there is the RHIMES
dataset that includes accents from French, but I am willing to generate spanish-only forms like ñ
or ü
. Take the next .svg
for example:
Is there any way to manually add a -
above the n
during the generation process? Perhaps splitting the word before getting the samples and apply it just to the n
?
is there any pre existing way that anyone has come across to make custom data in the correct format?
Hi,
When I give words with capital Z and Q in them, I get a complaint that the model does not have those letters as its trained letters. However, I noticed that your web demo has not issue with those letter.
Could you please share your model that includes those characters?
Hi @sjvasquez Nice one
Can we do Handwriting Synthesis for other languages.Am interested to implement for Tamil language
Tamil. If possible kindly let us know.
Hi,
I attempted to generate handwritten "@", "+" and "✓" signs, but was unable to.
E.g. the phone number +1234, and the email [email protected] will not generate anything at all.
Within the "write" function of demo.py (line 42) => valid_char_set = set(drawing.alphabet), alphabet is called from drawing.py. Therefore, I modified within drawing.py (see line 10), the list alphabet by adding the new characters. Adding "@" or "+" to the list caused major problems as even regular words such as "John Smith" can no longer be written i.e. no handwriting output at all.
I have identified where within demo.py, the code breaks after adding the new characters to the list. The line strokes = self._sample(lines, biases=biases, styles=styles) (line 61), calls the function _sample. Within _sample, it is from line 94 to line 106, which fails (see below)
[samples] = self.nn.session.run(
[self.nn.sampled_sequence],
feed_dict={
self.nn.prime: styles is not None,
self.nn.x_prime: x_prime,
self.nn.x_prime_len: x_prime_len,
self.nn.num_samples: num_samples,
self.nn.sample_tsteps: max_tsteps,
self.nn.c: chars,
self.nn.c_len: chars_len,
self.nn.bias: biases
}
)
Would anyone be able to provide an explanation and solution for this please? i.e. explanation to why nothing is drawn at all, and why adding an additional character could not solve this. And what the solution would be to generate handwriting for "@", "+" and "✓"?
Many Thanks!
PS: I also attempted on the web demo to create"@", "+" and "✓". Although not drawn properly, at least handwriting can be generated.
When I look at the relevant code for your data preprocessing, I don't quite understand the method used in it. Can you tell me the relevant literature on your method?
I have an issue with the digits. In most of my test cases, digits are not produced very well and they are not readable. is it something that I can fix with re-training?
Hello,
I want to create a new style of handwriting using the same pretrained model.
Thanks
Hey
What changes need to be made to enable training for other languages, other than the training data? I can see some style files being used, does that need to change as well? In which case, could you share how the style.npy files were created.
Is there a non minified version of the js code available?
Hi,
I am working on a project where I need to define text from windows pre-defined font files.
How can styles (strokes and char files) be created for texts generated with .ttf files?
Thank you in advance.
Regards,
Roy.
handwriting-synthesis/rnn_cell.py
Line 110 in 5f58984
no state attrivute is found in call method of the class "tf.keras.layers.LSTMCell"
Why not make an API and let Python or other languages can use it?
My Idea:
- Python post a request to it,it has "text","style" and other keys.
- It recive a key named "text" and do something for it.
- It return a picture and it will named "xx.png"
Maybe.If the idea comes true,I will thanks a lot.
I am having trouble with my installations, and would love to know from one of you who did manage to install and run what are your versions.
I tried:
Python3.7 with tensorflow 1.8/1.6/1.5 - all leading to missing modules such as:
ModuleNotFoundError: No module named '_pywrap_tensorflow_internal'
I followed this thread about it: tensorflow/tensorflow#20690
Python3.6.8 with tensorflow 1.6.0:
tensorflow couldn't be installed due to
protobuf requires Python '>=3.7' but the running Python is 3.6.8
Traceback (most recent call last):
File "demo.py", line 153, in <module>
stroke_widths=stroke_widths
File "demo.py", line 42, in write
strokes = self._sample(lines, biases=biases, styles=styles)
File "demo.py", line 61, in _sample
c_p = drawing.encode_ascii(c_p)
File "~/handwriting-synthesis/drawing.py", line 77, in encode_ascii
return np.array(map(lambda x: alpha_to_num[x], ascii_string) + [0])
TypeError: unsupported operand type(s) for +: 'map' and 'list'
Hello, are there any plans to support the Chinese?
I kept getting this error message when I was running this program. If you also run into this issue the resolution is:
np.ones_like in the rnn_cell.py file with keras.backend.ones_like.
You will also have to import keras as well so add from tensorflow import keras to the top of the rnn_cell.py file as well.
I realize this wasn't originally developed to be released as a project, but it the code has been posted and no license has been declared. This leaves a really weird limbo situation where the worst-faith actors are the most free to take advantage of the situation but honest actors who build systems that stick to licensing terms can't do anything with this at all.
It also inhibits contributions! You state in the readme that you'd be interested in accepting contributions which helped make this into a package and made it more usable. I'd be willing to contribute some towards that, but not until the licensing is clarified.
Issue #16 also broached this topic, but the OP unilaterally decided what they wanted it to be and then closed the issue and ran away. I also think the MIT license would be a good candidate for this project, but the original author(s) need to state their intention in this regard.
I'd be happy to help with advice on what different licenses are good for and how to pick. Once you do pick I'm happy to contribute the proper files to this repo so that it's properly licensed and usable by others. But I can't make the call what that license will be.
What resource are there to mail merge for a list of letters but with minor differences like name or address?
Enter this string "Hawaii lieben leidige Fijii"
Style 6
Speed , legibility and stroke width at default .
After "Fijii" the Ai continues with another ~6 characters of jibber jabber in > 50% of the cases.
That might be an interesting corner case too look at.
Thanks for the great work.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.