# PQIM

This repository contains the implementation for our method described in `Hiding in the Phase: A Probably Robust Watermark for Diffusion Models`.  
It builds upon the [Zodiac](https://github.com/zhanglijun95/ZoDiac), [Tree-ring](https://github.com/YuxinWenRick/tree-ring-watermark), [Semantic-Forgery](https://github.com/and-mill/semantic-forgery), [Diffusers](https://github.com/huggingface/diffusers) framework and provides the necessary code and scripts for evaluation.

## 📦 Dependencies

We use the combined environment configuration as [Zodiac](https://github.com/zhanglijun95/ZoDiac), [Tree-ring](https://github.com/YuxinWenRick/tree-ring-watermark), [Semantic-Forgery](https://github.com/and-mill/semantic-forgery), [Diffusers](https://github.com/huggingface/diffusers).

To set up the environment:

```bash
python3.10 -m venv venv
source venv/bin/activate
pip install -r req.txt
```
Make sure you are using Python 3.10. If you encounter environment issues, refer to the Zodiac, Tree-ring, Semantic-Forgery setup instructions.

# 🔧 Training
Not applicable – this repository does not include training scripts.
We rely on pre-trained models provided by [Diffusers](https://github.com/huggingface/diffusers).

# 📊 Evaluation

Our method is implemented in demo_pqim.py, attack_pqim and others are demo_zod.py, attack_zod.py, demo_gs.py, attack_gs.py. First, generate the gt images provided by the tree-ring repository and match the directory with demo_pqim.py files and run:

```bash
python demo_pqim.py
```
```bash
python attack_pqim.py
```
Each script will run the evaluation pipeline and generate the results reported in the paper.

# 🧠 Pre-trained Models
We use pre-trained models from the [Diffusers](https://github.com/huggingface/diffusers) repository.
Please follow their instructions for downloading the necessary checkpoints.

# 📈 Results

### Attack resillience metrics

|          | TPR                  | Bit-acc              |
|----------|----------------------|----------------------|
| no distortion     | 1.0           | 1.0         |
| brightness        | 0.998         | 0.94458203125         |
| gaussianblur      | 0.917         | 0.64016796875         |
| gaussiannoise     | 0.327         | 0.5550625         |
| jpeg              | 0.943         | 0.77703125         |
| resize            | 1.0           | 0.98418359375     |
| spnoise           | 0.302         | 0.5568125     |

### Perceptual quality metrics

|  PQIM    |        value       |
|----------|--------------------|
| psnr     | 28.759422776693654 |
| ssim     | 0.8775567053556442 |
| mssim    | 0.9518686184883117 |
| lpips    | 0.12467949627805501|
| clip     | 0.9771412033438682 |



# 📄 License
This codebase uses the same license as [Zodiac](https://github.com/zhanglijun95/ZoDiac), [Tree-ring](https://github.com/YuxinWenRick/tree-ring-watermark), [Semantic-Forgery](https://github.com/and-mill/semantic-forgery), [Diffusers](https://github.com/huggingface/diffusers) in accordance with its licensing terms.


# 🙌 Acknowledgements
We thank the authors of [Zodiac](https://github.com/zhanglijun95/ZoDiac), [Tree-ring](https://github.com/YuxinWenRick/tree-ring-watermark), [Semantic-Forgery](https://github.com/and-mill/semantic-forgery), [Diffusers](https://github.com/huggingface/diffusers) for open-sourcing their framework, which our method builds upon.
