Skip to content

KahimWong/FontGuard

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FontGuard

arXiv Venue License

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.

Model Overview


✨ Highlights

  • 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.

Training Visualization


📦 Repository Layout

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

🚀 Quick Start

1) Environment

Install dependencies in your Python environment:

pip install torch==1.13.0+cu117 torchvision==0.14.0+cu117

2) Prepare data and pretrained files

Set 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:

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.

3) Organize font images correctly

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).

4) Train

python main.py

Training outputs are written to exp_dir (auto-created in cfg.py), including checkpoints and visualization images.


⚙️ Key Configuration (cfg.py)

  • msg_bit: watermark bit length (default 1, so msg_n=2 classes)
  • font_dir, bg_dir: font/background data directories
  • font_model_ckpt, base_sty_path, pretrain_dec_ckpt: required model assets
  • epochs, bs, enc_lr, dec_lr, disc_lr: training schedule and optimization
  • init_epoch, start_noise_epoch, full_noise_epoch: curriculum stages

main.py sets CUDA_VISIBLE_DEVICES internally. Adjust it if needed for your machine.


🧪 Demo Evaluation

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.

  1. Download demo package (see demo/README.md).
  2. Configure paths in demo/demo_cfg.py.
  3. Ensure demo/test.py imports the same config module name (cfg).
  4. Run:
cd demo
python test.py

The script prints per-scenario decoding accuracy.


📚 Citation

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}
}

🙌 Acknowledgment

This implementation includes reusable modules under model/ (e.g., DGFont, differentiable JPEG, PCGrad) integrated into the FontGuard training pipeline.

About

[TMM'25] FontGuard: A Robust Font Watermarking Approach Leveraging Deep Font Knowledge

Topics

Resources

License

Stars

8 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages