This is a PytTorch implementation of the method proposed in DeepFont to recognize the font from text images using deep learning. This ropo can be applied for any language and font.
An automatic font image generator is also provided in this repo using TextRecognitionDataGenerator. You may refer to it if you want to customize the generation mechanism.
git clone https://github.com/twelfth-star/universal-font-recognition.git
cd universal-font-recognition
conda create -n font_recog python=3.8.13
conda activate font_recog
pip install -r requirements.txt
Note: If you want to use GPU, you should install PyTorch consistent with your CUDA version (use command nvidia-smi
to check your CUDA version). Detailed instructions may be found in its official website.
-
Download the font files (usually
.ttf
,.ttc
,otf
, etc.) and put them into./dataset/fonts
(or anywhere else you like). -
(Optional) Put the real images with text, whose font is included in the font files you prepared in Step 1, into
./dataset/real_images
(or anywhere else you like). No specific labels are needed. -
Edit the settings in
.font_recognition/main.py
based on your preference. -
(Optional) Edit the image generation mechanism in function
generate_batch_images
ingeneral_code/image_generation.py
based on your preference. You may refer to the official wiki of TextRecognitionDataGenerator -
Enter
./font_recognition
usingcd ./font_recognition
. Run the code usingpython ./main.py
. The images for training will be automatically generated and the model will be trained. -
By default, the model will be saved as
./dataset/models/CNN_{language}_{num_fonts}.pth
. A json file indicating the map from font name to font ID will also be saved as./dataset/models/font_dict_{language}_{num_fonts}.json