FontGuard is a robust font watermarking framework that embeds bits by manipulating font style representations (instead of only pixel-space perturbations), then decodes them with contrastive learning for robust recovery under cross-media and OSN transmission distortions.
- Style-space watermarking with a font generator prior for better visual quality.
- Contrastive decoder training for stable bit recovery.
- Noise-aware curriculum that improves robustness under real-world distortions.
- Demo assets included for 1-bit SimSun watermarking and multi-scenario evaluation.
FontGuard/
├── main.py # training entry
├── cfg.py # training configuration
├── ds.py # dataloader (font + random background)
├── model/ # encoder/decoder/discriminator + noise layers
├── fig/ # figures used in docs
└── demo/
├── test.py # demo evaluation entry
├── demo_cfg.py # demo config template
└── README.md # demo data details
Install dependencies in your Python environment:
pip install torch==1.13.0+cu117 torchvision==0.14.0+cu117Set the root directory in cfg.py, then place required files under that root:
- font images (
font_dir, default:root/SimSun) - mean style feature (
base_sty_path) - pretrained decoder checkpoint (
pretrain_dec_ckpt) - background images (
bg_dir, default:root/val2017)
Pretrained resources:
- Original resources: Google Drive
- Released FontGuard checkpoints: Google Drive
Recommended exp_data layout (matching cfg.py defaults):
exp_data/
├── FangSong_ttf/
├── KaiTi_ttf/
├── SimSun_ttf/
├── Times_ttf/
├── Verdana_ttf/
├── FangSong_0bit_ft_dec.pth
├── KaiTi_0bit_ft_dec.pth
├── SimSun_0bit_e2e.pyt
├── SimSun_0bit_ft_dec.pth
├── Times_0bit_ft_dec.pth
└── Verdana_0bit_ft_dec.pth
If you are also preparing training assets referenced by cfg.py, a typical setup may additionally include font image folders, background images, style features, and font recognition checkpoints under the same root directory.
ds.py uses torchvision.datasets.ImageFolder, so images must be inside at least one subfolder:
SimSun/
└── <font-subdir>/
├── 0000.png
├── 0001.png
└── ...
Expected image size is 80×80 (configured by font_img_size in cfg.py).
python main.pyTraining outputs are written to exp_dir (auto-created in cfg.py), including checkpoints and visualization images.
msg_bit: watermark bit length (default1, somsg_n=2classes)font_dir,bg_dir: font/background data directoriesfont_model_ckpt,base_sty_path,pretrain_dec_ckpt: required model assetsepochs,bs,enc_lr,dec_lr,disc_lr: training schedule and optimizationinit_epoch,start_noise_epoch,full_noise_epoch: curriculum stages
main.pysetsCUDA_VISIBLE_DEVICESinternally. Adjust it if needed for your machine.
The demo folder includes evaluation code for released 1-bit watermarked SimSun assets across seven transmission scenarios.
- Cross-media: screenshots, screen-camera capture, and print-camera capture
- Online social networks (OSNs): Facebook, WhatsApp, Weibo, and WeChat
For data collection, screen-camera capture used an iMac17,1 as the display device, and print-camera capture used an ApeosPrint C5570 TC printer with the default 600 dpi scanning resolution.
For OSN transmission, Facebook and WhatsApp upload/download were performed on an Alienware Aurora R9 running Windows 11 version 22621, while Weibo and WeChat transmission used a HUAWEI Mate 60 Pro smartphone.
- Download demo package (see
demo/README.md). - Configure paths in
demo/demo_cfg.py. - Ensure
demo/test.pyimports the same config module name (cfg). - Run:
cd demo
python test.pyThe script prints per-scenario decoding accuracy.
If this project helps your research, please cite:
@article{wong2025fontguard,
title={FontGuard: A Robust Font Watermarking Approach Leveraging Deep Font Knowledge},
author={Wong, Kahim and Zhou, Jicheng and Li, Kemou and Si, Yain-Whar and Wu, Xiaowei and Zhou, Jiantao},
journal={IEEE Transactions on Multimedia},
year={2025}
}This implementation includes reusable modules under model/ (e.g., DGFont, differentiable JPEG, PCGrad) integrated into the FontGuard training pipeline.

