SerCeMan / fontogen

Hey, Computer, Make Me a Font
https://serce.me/posts/02-10-2023-hey-computer-make-me-a-font
MIT License
442 stars 26 forks source link

How can I do the inference? #7

Open JasonLLLLLLLLLLL opened 10 months ago

JasonLLLLLLLLLLL commented 10 months ago

Hello, I have done the Installation. I am wondering how can I do the Inference after training?

# the input fonts
ls ./example/dataset/
# prepare the dataset and start training
./train_example.sh

After I run those two instrcutions, Can I get some checkpoints or pretrained weights?

so after that, How can I do the Inference?

The model needs to be re-trained on a large dataset of OFL fonts. If anyone would like to contribute and re-train the model, please reach out and I'll be happy to help you set up the environment.

I'd like to contribute and re-train the model. I have a 4090 GPU. btw, will you publish your pretrained weights in the future? I guess it is tricky to have a good training result because of many hyper parameters.

This project is awesome! Looking forward to your reply.

SerCeMan commented 10 months ago

Hey, @JasonLLLLLLLLLLL! You can launch the server with python server.py and then select the checkpoint that you've trained.

JasonLLLLLLLLLLL commented 10 months ago

Hey, @JasonLLLLLLLLLLL! You can launch the server with python server.py and then select the checkpoint that you've trained.

Thanks!

Will you publish your checkpoint in the future? I guess it is not easy to get good result.

And I'd like to contribute and re-train the model. Can I do that with a 4090 GPU?

SerCeMan commented 10 months ago

Will you publish your checkpoint in the future? I guess it is not easy to get good result.

I'm not actively working on re-training the model at the moment.

And I'd like to contribute and re-train the model. Can I do that with a 4090 GPU?

Yes, you definitely can, it's the exact same GPU that I used to train the model.

JasonLLLLLLLLLLL commented 8 months ago

Hey, @JasonLLLLLLLLLLL! You can launch the server with python server.py and then select the checkpoint that you've trained.


**python server.py**
Either FairScale or torch distributed is not available, MixtureOfExperts will not be exposed. Please install them if you would like to use MoE
Traceback (most recent call last):
File "/home/lz/SSD-GreatWall/new-project/fontogen-master/server.py", line 111, in <module>
all_fonts = gr.HTML(value=font_generator('$all'))
File "/home/lz/SSD-GreatWall/new-project/fontogen-master/server.py", line 76, in font_generator
fonts = sorted([f for f in os.listdir(FONT_DIR) if f.endswith('.ttf')],
FileNotFoundError: [Errno 2] No such file or directory: './training/samples/'

when I run **python server.py**, it shows that error. It seems there is no **'./training/samples/'** in your project? Can I just make a directory **'./training/samples/'** to solve this error?
SerCeMan commented 8 months ago

Hey, @JasonLLLLLLLLLLL! You can follow these instructions to run it, https://github.com/SerCeMan/fontogen/tree/master?tab=readme-ov-file#training

JasonLLLLLLLLLLL commented 8 months ago

Hey, @JasonLLLLLLLLLLL! You can follow these instructions to run it, https://github.com/SerCeMan/fontogen/tree/master?tab=readme-ov-file#training

Could you please help me with this? When I run ./train_example.sh as #training in readme, the following is the last several Epochs log. It seems y=150 out of bounds. And I did't get the directory 'training/sample'. Sorry for bothering you all the time.

failed to sample y=150 is out of bounds, token=22541
Epoch 188: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1/1 [00:00<00:00,  2.20it/s, v_num=2, loss=5.580]sampling bold sans
too many tokens for glyph A, trying again
too many tokens for glyph A, trying again
Starting building B
too many tokens for glyph B, trying again
Starting building C
too many tokens for glyph C, trying again
Starting building D
Starting building E
too many tokens for glyph E, trying again
too many tokens for glyph E, trying again
Starting building F
Starting building G
Starting building H
too many tokens for glyph H, trying again
Starting building I
Starting building J
Starting building K
Starting building L
Starting building M
Starting building N
Starting building O
Starting building P
Starting building Q
Starting building R
Starting building S
Starting building T
Starting building U
Starting building V
Starting building W
Starting building X
Starting building Y
Starting building Z
Starting building 0
Starting building 1
Starting building 2
Starting building 3
Starting building 4
Starting building 5
Starting building 6
Starting building 7
Starting building 8
Starting building 9
Starting building .
Starting building ,
Starting building !
Starting building ?
failed to sample y=150 is out of bounds, token=22541
Epoch 198: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1/1 [00:00<00:00,  2.19it/s, v_num=2, loss=5.490]sampling bold sans
too many tokens for glyph A, trying again
Starting building B
too many tokens for glyph B, trying again
Starting building C
too many tokens for glyph C, trying again
Starting building D
too many tokens for glyph D, trying again
Starting building E
Starting building F
too many tokens for glyph F, trying again
Starting building G
Starting building H
Starting building I
Starting building J
Starting building K
Starting building L
Starting building M
Starting building N
Starting building O
Starting building P
Starting building Q
Starting building R
Starting building S
Starting building T
Starting building U
Starting building V
Starting building W
Starting building X
Starting building Y
Starting building Z
Starting building 0
Starting building 1
Starting building 2
Starting building 3
Starting building 4
Starting building 5
Starting building 6
Starting building 7
Starting building 8
Starting building 9
Starting building .
Starting building ,
Starting building !
Starting building ?
failed to sample y=150 is out of bounds, token=22541
Epoch 199: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1/1 [00:00<00:00,  2.15it/s, v_num=2, loss=5.480]`Trainer.fit` stopped: `max_epochs=200` reached.
Epoch 199: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1/1 [00:01<00:00,  1.69s/it, v_num=2, loss=5.480]
SerCeMan commented 8 months ago

Hey, @JasonLLLLLLLLLLL! Because there were only 2 fonts to train on, and only 200 epochs, the model didn't learn how to generate a font, so it failed to do so by generating unexpected tokens.

JasonLLLLLLLLLLL commented 8 months ago

Hey, @JasonLLLLLLLLLLL! Because there were only 2 fonts to train on, and only 200 epochs, the model didn't learn how to generate a font, so it failed to do so by generating unexpected tokens.

Could you tell me how can I solve this problem? Do I need to set a larger Epochs, like 400 Epoch?

JasonLLLLLLLLLLL commented 8 months ago

Hey, @JasonLLLLLLLLLLL! Because there were only 2 fonts to train on, and only 200 epochs, the model didn't learn how to generate a font, so it failed to do so by generating unexpected tokens.

Could you tell me how can I solve this problem? Do I need to set a larger Epochs, like 400 Epoch?

I did that. It didn't work.So I will try 1024 Epochs to see if it works or not..

SerCeMan commented 8 months ago

Could you tell me how can I solve this problem? Do I need to set a larger Epochs, like 400 Epoch?

Hey, @JasonLLLLLLLLLLL! To answer this, I'll need to understand what you're trying to achieve.

JasonLLLLLLLLLLL commented 8 months ago

Could you tell me how can I solve this problem? Do I need to set a larger Epochs, like 400 Epoch?

Hey, @JasonLLLLLLLLLLL! To answer this, I'll need to understand what you're trying to achieve.

I want to run this project on my computer and achieve the result in your blog. I run instructions as the readme.

# the input fonts
ls ./example/dataset/
# prepare the dataset and start training
./train_example.sh

but ended with this: https://github.com/SerCeMan/fontogen/issues/7#issuecomment-1861945783

SerCeMan commented 8 months ago

You'll need a much larger dataset to achieve the same results. Using the example dataset, assuming you run it with a large-enough number of epochs, the model will learn to generate the input fonts by memoizing the input data.

You can keep running the model for a very large number of epochs, and sample the results every maybe 1k epochs to see the results. You can also reduce the number of glyphs to a much smaller set – e.g. just `ABCD to get the results quicker.

JasonLLLLLLLLLLL commented 8 months ago

You'll need a much larger dataset to achieve the same results. Using the example dataset, assuming you run it with a large-enough number of epochs, the model will learn to generate the input fonts by memoizing the input data.

You can keep running the model for a very large number of epochs, and sample the results every maybe 1k epochs to see the results. You can also reduce the number of glyphs to a much smaller set – e.g. just `ABCD to get the results quicker.

I see. So you can't publish your dataset and tested code which can successfully achieve the result in you blog. Probably for some license reasons. Am I right?

SerCeMan commented 8 months ago

Yes, the code is there, but you'll need to bring your own dataset.

JasonLLLLLLLLLLL commented 8 months ago

Yes, the code is there, but you'll need to bring your own dataset.

Thanks. The code is going to help me a lot. I will try find a dataset. Thanks for your time and Sorry for bothering you all the time.