Gabor Cselle
commited on
Commit
·
12e4f1f
1
Parent(s):
b1e1a65
Fix generator script, add examples to widget sample card
Browse files- README.md +34 -4
- gen_sample_data.py +10 -9
- hf_samples/ArchitectsDaughter-Regular_1.png +0 -0
- hf_samples/Arial Bold_39.png +0 -0
- hf_samples/Courier_28.png +0 -0
- hf_samples/Helvetica_3.png +0 -0
- hf_samples/IBMPlexSans-Regular_25.png +0 -0
- hf_samples/Inter-Regular_43.png +0 -0
- hf_samples/Lobster-Regular_25.png +0 -0
- hf_samples/Lobster-Regular_34.png +0 -0
- hf_samples/Merriweather-Regular_1.png +0 -0
- hf_samples/Merriweather-Regular_12.png +0 -0
- hf_samples/Poppins-Regular_22.png +0 -0
- hf_samples/RobotoMono-Regular_38.png +0 -0
- hf_samples/Times New Roman Bold Italic_26.png +0 -0
- hf_samples/Times New Roman Italic_16.png +0 -0
- hf_samples/TitilliumWeb-Regular_5.png +0 -0
- hf_samples/Trebuchet MS Italic_47.png +0 -0
- hf_samples/Trebuchet MS_11.png +0 -0
- hf_samples/Verdana Bold_43.png +0 -0
README.md
CHANGED
|
@@ -4,6 +4,40 @@ language:
|
|
| 4 |
tags:
|
| 5 |
- font-identification
|
| 6 |
license: mit
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
---
|
| 8 |
|
| 9 |
# Font Identifier Project
|
|
@@ -20,7 +54,3 @@ Generate sample images (note this will work only on Mac): [gen_sample_data.py](g
|
|
| 20 |
Arrange test images into test and train: [arrange_train_test_images.py](arrange_train_test_images.py)
|
| 21 |
|
| 22 |
Train a ResNet18 on the data: [train_font_identifier.py](train_font_identifier.py)
|
| 23 |
-
|
| 24 |
-
License: MIT
|
| 25 |
-
|
| 26 |
-
|
|
|
|
| 4 |
tags:
|
| 5 |
- font-identification
|
| 6 |
license: mit
|
| 7 |
+
widget:
|
| 8 |
+
- text: "What font is this?"
|
| 9 |
+
- src: https://huggingface.co/gaborcselle/font-identify/hf_sample/ArchitectsDaughter-Regular_1.png
|
| 10 |
+
example_title: Architects Daughter
|
| 11 |
+
- src: https://huggingface.co/gaborcselle/font-identify/hf_sample/Arial_Bold_39.png
|
| 12 |
+
example_title: Arial Bold
|
| 13 |
+
- src: https://huggingface.co/gaborcselle/font-identify/hf_sample/Courier_28.png
|
| 14 |
+
example_title: Courier
|
| 15 |
+
- src: https://huggingface.co/gaborcselle/font-identify/hf_sample/Helvetica_3.png
|
| 16 |
+
example_title: Helvetica
|
| 17 |
+
- src: https://huggingface.co/gaborcselle/font-identify/hf_sample/IBMPlexSans-Regular_25.png
|
| 18 |
+
example_title: IBM Plex Sans
|
| 19 |
+
- src: https://huggingface.co/gaborcselle/font-identify/hf_sample/Inter-Regular_43.png
|
| 20 |
+
example_title: Inter
|
| 21 |
+
- src: https://huggingface.co/gaborcselle/font-identify/hf_sample/Lobster-Regular_25.png
|
| 22 |
+
example_title: Lobster
|
| 23 |
+
- src: https://huggingface.co/gaborcselle/font-identify/hf_sample/Merriweather-Regular_1.png
|
| 24 |
+
example_title: Merriweather
|
| 25 |
+
- src: https://huggingface.co/gaborcselle/font-identify/hf_sample/Poppins-Regular_22.png
|
| 26 |
+
example_title: Poppins
|
| 27 |
+
- src: https://huggingface.co/gaborcselle/font-identify/hf_sample/RobotoMono-Regular_38.png
|
| 28 |
+
example_title: Roboto Mono
|
| 29 |
+
- src: https://huggingface.co/gaborcselle/font-identify/hf_sample/Times_New_Roman_Bold Italic_26.png
|
| 30 |
+
example_title: Times New Roman Bold Italic
|
| 31 |
+
- src: https://huggingface.co/gaborcselle/font-identify/hf_sample/Times_New_Roman_Italic_16.png
|
| 32 |
+
example_title: Times New Roman Italic
|
| 33 |
+
- src: https://huggingface.co/gaborcselle/font-identify/hf_sample/TitilliumWeb-Regular_5.png
|
| 34 |
+
example_title: Titillium Web
|
| 35 |
+
- src: https://huggingface.co/gaborcselle/font-identify/hf_sample/Trebuchet_MS_Italic_47.png
|
| 36 |
+
example_title: Trebuchet MS Italic
|
| 37 |
+
- src: https://huggingface.co/gaborcselle/font-identify/hf_sample/Trebuchet_MS_11.png
|
| 38 |
+
example_title: Trebuchet MS
|
| 39 |
+
- src: https://huggingface.co/gaborcselle/font-identify/hf_sample/Verdana Bold_43.png
|
| 40 |
+
example_title: Verdana Bold
|
| 41 |
---
|
| 42 |
|
| 43 |
# Font Identifier Project
|
|
|
|
| 54 |
Arrange test images into test and train: [arrange_train_test_images.py](arrange_train_test_images.py)
|
| 55 |
|
| 56 |
Train a ResNet18 on the data: [train_font_identifier.py](train_font_identifier.py)
|
|
|
|
|
|
|
|
|
|
|
|
gen_sample_data.py
CHANGED
|
@@ -49,19 +49,20 @@ def main():
|
|
| 49 |
# Output the font name so we can see the progress
|
| 50 |
print(font_path, font_name)
|
| 51 |
|
| 52 |
-
# Random font size
|
| 53 |
-
font_size = random.choice(range(18, 72))
|
| 54 |
-
|
| 55 |
-
if font_path.endswith('.ttc'):
|
| 56 |
-
# ttc fonts have multiple fonts in one file, so we need to specify which one we want
|
| 57 |
-
font = ImageFont.truetype(font_path, font_size, index=0)
|
| 58 |
-
else:
|
| 59 |
-
# ttf fonts have only one font in the file
|
| 60 |
-
font = ImageFont.truetype(font_path, font_size)
|
| 61 |
|
| 62 |
# Counter for the image filename
|
| 63 |
j = 0
|
| 64 |
for i in range(IMAGES_PER_FONT): # Generate 50 images per font - reduced to 10 for now to make things faster
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
# Determine the number of words that will fit on a line
|
| 66 |
font_avg_char_width = font.getbbox('x')[2]
|
| 67 |
words_per_line = int(800 / (font_avg_char_width*5))
|
|
|
|
| 49 |
# Output the font name so we can see the progress
|
| 50 |
print(font_path, font_name)
|
| 51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
# Counter for the image filename
|
| 54 |
j = 0
|
| 55 |
for i in range(IMAGES_PER_FONT): # Generate 50 images per font - reduced to 10 for now to make things faster
|
| 56 |
+
# Random font size
|
| 57 |
+
font_size = random.choice(range(18, 72))
|
| 58 |
+
|
| 59 |
+
if font_path.endswith('.ttc'):
|
| 60 |
+
# ttc fonts have multiple fonts in one file, so we need to specify which one we want
|
| 61 |
+
font = ImageFont.truetype(font_path, font_size, index=0)
|
| 62 |
+
else:
|
| 63 |
+
# ttf fonts have only one font in the file
|
| 64 |
+
font = ImageFont.truetype(font_path, font_size)
|
| 65 |
+
|
| 66 |
# Determine the number of words that will fit on a line
|
| 67 |
font_avg_char_width = font.getbbox('x')[2]
|
| 68 |
words_per_line = int(800 / (font_avg_char_width*5))
|
hf_samples/ArchitectsDaughter-Regular_1.png
ADDED
|
hf_samples/Arial Bold_39.png
ADDED
|
hf_samples/Courier_28.png
ADDED
|
hf_samples/Helvetica_3.png
ADDED
|
hf_samples/IBMPlexSans-Regular_25.png
ADDED
|
hf_samples/Inter-Regular_43.png
ADDED
|
hf_samples/Lobster-Regular_25.png
ADDED
|
hf_samples/Lobster-Regular_34.png
ADDED
|
hf_samples/Merriweather-Regular_1.png
ADDED
|
hf_samples/Merriweather-Regular_12.png
ADDED
|
hf_samples/Poppins-Regular_22.png
ADDED
|
hf_samples/RobotoMono-Regular_38.png
ADDED
|
hf_samples/Times New Roman Bold Italic_26.png
ADDED
|
hf_samples/Times New Roman Italic_16.png
ADDED
|
hf_samples/TitilliumWeb-Regular_5.png
ADDED
|
hf_samples/Trebuchet MS Italic_47.png
ADDED
|
hf_samples/Trebuchet MS_11.png
ADDED
|
hf_samples/Verdana Bold_43.png
ADDED
|