This is work in progress -- for now development has been paused.
See also: nicecv#2
Note: We assume that you need to create a Docker container, so we do not download the model weights at runtime.
- Install this repo as a custom node in ComfyUI.
- Manually download weights from Google Drive and save them in the
checkpointssubdirectory -- your file tree should look like this:
.../ComfyUI/custom_nodes/ComfyUI_DiffHarmony/checkpoints
├── base
│ ├── feature_extractor
│ │ └── preprocessor_config.json
│ ├── model_index.json
│ ├── safety_checker
│ │ ├── config.json
│ │ └── pytorch_model.bin
│ ├── scheduler
│ │ └── scheduler_config.json
│ ├── text_encoder
│ │ ├── config.json
│ │ └── pytorch_model.bin
│ ├── tokenizer
│ │ ├── merges.txt
│ │ ├── special_tokens_map.json
│ │ ├── tokenizer_config.json
│ │ └── vocab.json
│ ├── unet
│ │ ├── config.json
│ │ └── diffusion_pytorch_model.bin
│ └── vae
│ ├── config.json
│ └── diffusion_pytorch_model.bin
├── condition_vae
│ ├── config.json
│ └── diffusion_pytorch_model.safetensors
├── inverse
│ ├── feature_extractor
│ │ └── preprocessor_config.json
│ ├── model_index.json
│ ├── safety_checker
│ │ ├── config.json
│ │ └── pytorch_model.bin
│ ├── scheduler
│ │ └── scheduler_config.json
│ ├── text_encoder
│ │ ├── config.json
│ │ └── pytorch_model.bin
│ ├── tokenizer
│ │ ├── merges.txt
│ │ ├── special_tokens_map.json
│ │ ├── tokenizer_config.json
│ │ └── vocab.json
│ ├── vae
│ │ ├── config.json
│ │ └── diffusion_pytorch_model.bin
│ └── weights-102800
│ ├── config.json
│ └── diffusion_pytorch_model.safetensors
└── refinement
├── config.json
└── diffusion_pytorch_model.safetensors
- ...
- Profit
Original README below
The official pytorch implementation of DiffHarmony and DiffHarmony++ (paper release soon).
Full Conference Poster is here.
First, prepare a virtual env. You can use conda or anything you like.
python 3.10
pytorch 2.2.0
cuda 12.1
xformers 0.0.24Then, install requirements.
pip install -r requirements.txtDownload iHarmony4 dataset from here.
Make sure the structure is just like that:
data/iHarmony4
|- HCOCO
|- composite_images
|- masks
|- real_images
|- ...
|- HAdobe5k
|- HFlickr
|- Hday2night
|- train.jsonl
|- test.jsonlThe content in train.jsonl fit the following format
{"file_name": "HAdobe5k/composite_images/a0001_1_1.jpg", "text": ""}
{"file_name": "HAdobe5k/composite_images/a0001_1_2.jpg", "text": ""}
{"file_name": "HAdobe5k/composite_images/a0001_1_3.jpg", "text": ""}
{"file_name": "HAdobe5k/composite_images/a0001_1_4.jpg", "text": ""}
...All file_name are from the original IHD_train.txt. Same way with test.jsonl and IHD_test.txt.
sh scripts/train_diffharmony.shsh scripts/train_refinement_stage.shsh scripts/train_cvae.shJust add this in your training args:
$script
...
--mode "inverse"Basically it will use ground truth images as condition instead of composite images.
refer to scripts/train/cvae_online.py
refer to scripts/train/cvae_with_gen_data.py
Purpose here is trying to improve cvae performance further on specific domain, i.e. our generated dataset.
Inference iHarmony4 dataset
sh scripts/inference.shsh scripts/inference_generate_data.shThe all_mask_metadata.jsonl file as its name fits following format:
{"file_name": "masks/f800_1.png", "text": ""}
{"file_name": "masks/f801_1.png", "text": ""}
{"file_name": "masks/f803_1.png", "text": ""}
{"file_name": "masks/f804_1.png", "text": ""}
...First, generate some candidate composite images.
Then, use harmony classifier to select the most unharmonious images.
python scripts/misc/classify_cand_gen_data.pysh scripts/evaluate.shBaidu, code: aqqd
If you find this work useful, please consider citing:
@inproceedings{zhou2024diffharmony,
title={DiffHarmony: Latent Diffusion Model Meets Image Harmonization},
author={Zhou, Pengfei and Feng, Fangxiang and Wang, Xiaojie},
booktitle={Proceedings of the 2024 International Conference on Multimedia Retrieval},
pages={1130--1134},
year={2024}
}If you have any questions, please feel free to contact me via zhoupengfei@bupt.edu.cn .