Views
No views yet
1uv pip install diffusers torch torchvision safetensors
2uv pip install lpips scikit-image pytorch-fid # Optional: for evaluation1from argparse import Namespace
2from inference.sample_optimized import load_fontdiffuser_pipeline
3
4args = Namespace(
5 ckpt_dir="ckpt",
6 device="cuda:0",
7 guidance_scale=7.5,
8 num_inference_steps=20,
9 fp16=False,
10 enable_xformers=False,
11)
12pipe = load_fontdiffuser_pipeline(args=args)1accelerate launch run_inference.py \
2 --ckpt_dir ckpt \
3 --content_character "A" \
4 --style_image_path style_images/foo.png \
5 --save_image \
6 --save_image_dir results/1accelerate launch run_inference.py \
2 --ckpt_dir ckpt \
3 --characters chars.txt \
4 --style_images "style_images/*.png" \
5 --ttf_path fonts/myfont.ttf \
6 --output_dir my_dataset/train_original \
7 --batch_size 8 \
8 --num_inference_steps 15 \
9 --guidance_scale 7.5 \
10 --save_interval 101accelerate launch run_inference.py \
2 --ckpt_dir ckpt \
3 --characters chars.txt \
4 --style_images "style_images/*.png" \
5 --output_dir results/python tools/generate_metadata.py --data_root my_dataset/handwritten_original --output my_dataset/handwritten_original/results_checkpoint.jsonoutput_dir/
├── ContentImage/ # Single set of content (character) images
│ ├── char0.png
│ ├── char1.png
│ └── ...
├── TargetImage/ # Generated font images organized by style
│ ├── style0/
│ │ ├── style0+char0.png
│ │ ├── style0+char1.png
│ │ └── ...
│ ├── style1/
│ │ └── ...
│ └── ...
├── results_checkpoint.json # Checkpoint act as generation metadata1{
2 "generations": [
3 {
4 "character": "A",
5 "char_index": 0,
6 "style": "style0",
7 "style_index": 0,
8 "font": "Arial",
9 "style_path": "path/to/style0.png",
10 "output_path": "TargetImage/style0/style0+char0.png"
11 }
12 ],
13 "metrics": {
14 "lpips": {"mean": 0.25, "std": 0.08, "min": 0.1, "max": 0.5},
15 "ssim": {"mean": 0.82, "std": 0.05, "min": 0.7, "max": 0.95},
16 "fid": {"mean": 15.3, "std": 2.1},
17 "inference_times": [
18 {
19 "style": "style0",
20 "style_index": 0,
21 "font": "Arial",
22 "total_time": 2.45,
23 "num_images": 100,
24 "time_per_image": 0.0245
25 }
26 ]
27 },
28 "fonts": ["Arial", "Times New Roman"],
29 "characters": ["A", "B", "C"],
30 "styles": ["style0", "style1"],
31 "total_chars": 3,
32 "total_styles": 2,
33 "total_possible_pairs": 6
34}FontDiffusion Dataset/
├── total/
│ ├── ContentImage/ # Character structure images
│ ├── TargetImage/ # Style-specific font renderings
│ └── results_checkpoint.json
├── val/
└── test/1@article{fontdiffuser2023,
2 title={FontDiffuser: One-Shot Font Generation via Denoising Diffusion with Multi-Scale Content Aggregation and Style Contrastive Learning},
3 author={Zhenhua Yang, Dezhi Peng, Yuxin Kong, Yuyi Zhang, Cong Yao, Lianwen Jin},
4 year={2023}
5}