simoncozens / atokern Goto Github PK
View Code? Open in Web Editor NEWNeural network based font kerning
Neural network based font kerning
And cache it. Massive speed up.
Thanks for your work Simon, such an exciting project!
Upon cloning the repo, installing the requirements and fontTools via pip3 and running .kerncritic, I get the following error:
AttributeError: module 'tensorflow' has no attribute 'logging'
Any pointers please?
I'm trying to run the training script on a group of fonts.
I've dumped the kerning, it's pickled all the fonts, etc. I'm running the script "out of the box" so to speak, with no adjustments to the settings.
When it comes to the "Training" portion I'm getting an error.
Traceback (most recent call last):
File "atokern.keras.py", line 334, in <module>
],shuffle = True, validation_data=(val_tensors, val_kern))
File "/usr/local/lib/python3.6/site-packages/keras/engine/training.py", line 1602, in fit
batch_size=batch_size)
File "/usr/local/lib/python3.6/site-packages/keras/engine/training.py", line 1414, in _standardize_user_data
exception_prefix='input')
File "/usr/local/lib/python3.6/site-packages/keras/engine/training.py", line 141, in _standardize_input_data
str(array.shape))
ValueError: Error when checking input: expected rightofl to have 3 dimensions, but got array with shape (0, 1)
Printing val_tensors
reveals that all my arrays are empty. Any idea of what I am doing wrong?
{'rightofl': array([], shape=(0, 1), dtype=float64),
'leftofr': array([], shape=(0, 1), dtype=float64),
'rightofo': array([], shape=(0, 1), dtype=float64),
'rightofH': array([], shape=(0, 1), dtype=float64),
'mwidth': array([], dtype=float64)}
$ ./kerncritic ~/hb/Roboto-Regular.ttf
Traceback (most recent call last):
File "/home/behdad/kerning/atokern/./kerncritic", line 8, in <module>
from tensorfont import Font
File "/home/behdad/.local/lib/python3.11/site-packages/tensorfont/__init__.py", line 7, in <module>
from skimage.util import pad
ImportError: cannot import name 'pad' from 'skimage.util' (/home/behdad/.local/lib/python3.11/site-packages/skimage/util/__init__.py)
Requirement already satisfied: scikit-image in /home/behdad/.local/lib/python3.11/site-packages (0.21.0)
Looks like this reference no longer exists: http://www.simon-cozens.org/downloads/kernmodel.hdf5
With quite a lot of the font files Iโve tried this on, including the one I want to actually get suggested kerning values for, I get an error:
Font <filename> produced a string that was too wide/high
Looking at the source, it appears I possibly need to increase box_width
and box_height
, but having tried that it also seems that requires retraining the neural network from scratch since it assumes particular values for these variables.
Is there another possible approach to fixing this?
Hi Simon,
Amazing project โ I tried something like this many years ago but the tooling around neural nets was so poor that I didn't get anywhere. In my opinion, you're going about this exactly the right way, so I'm really excited I found this. I want to bring up something that was already mentioned in the Typedrawers thread: the idea of doing letter-fitting in one go, i.e. spacing and kerning at the same time.
You can use a linear programming model to turn the resulting glyph distance pairs into a set of sidebearings plus a kerning table that's minimized by the sum of absolute or squared kerns (i.e. what I did in skosch/fittingroom). You also get around ethical complaints, because your training data is now based on total glyph distances, not raw sidebearing and kerning values, which amounts to learning from printed matter instead of pirated font file data.
If you're worried (as you mentioned in your TD post) about unusual pairs like /t/Q messing up your training data ... maybe you can go through a few big corpora and identify pair frequencies and then drop uncommon pairs from the training data (or put them into low-learning-rate batches), as those are the ones designers would probably ignore.
I'd love to learn what your plans are for this project. Looking forward to your comments.
I had to do this:
diff --git a/kerncritic b/kerncritic
index 9892895..6f9e8f7 100755
--- a/kerncritic
+++ b/kerncritic
@@ -25,7 +25,7 @@ def download_url(url, output_path):
miniters=1, desc=url.split('/')[-1]) as t:
urllib.request.urlretrieve(url, filename=output_path, reporthook=t.update_to)
-tf.logging.set_verbosity(tf.logging.ERROR)
+tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR)
if not os.path.exists("badkerndetector.hdf5"):
print("Downloading bad kern detection model")
And then downloading http://dealer.simon-cozens.org/~simon/badkerndetector.hdf5
fails.
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.