Update README.md
Browse files
README.md
CHANGED
|
@@ -1,3 +1,117 @@
|
|
| 1 |
-
---
|
| 2 |
-
license: apache-2.0
|
| 3 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
---
|
| 4 |
+
|
| 5 |
+
# Virtual Artist
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
## Introduction
|
| 9 |
+
|
| 10 |
+
We propose a graph context-conditioned diffusion model called **InstructG2I** to generate images from multimodal attributed graphs (MMAGs).
|
| 11 |
+
InstructG2I first exploits the graph structure and multimodal information to conduct informative neighbor sampling by combining personalized page rank and re-ranking based on vision-language features.
|
| 12 |
+
Then, a Graph-QFormer encoder adaptively encodes the graph nodes into an auxiliary set of graph prompts to guide the denoising process of diffusion.
|
| 13 |
+
Finally, we propose graph classifier-free guidance, enabling controllable generation by varying the strength of graph guidance and multiple connected edges to a node.
|
| 14 |
+
|
| 15 |
+

|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
## Installation
|
| 19 |
+
```bash
|
| 20 |
+
conda create --name instructg2i python==3.10
|
| 21 |
+
conda activate instructg2i
|
| 22 |
+
|
| 23 |
+
git clone https://github.com/PeterGriffinJin/InstructG2I.git
|
| 24 |
+
conda install pytorch==2.0.1 torchvision==0.15.2 torchaudio==2.0.2 pytorch-cuda=11.8 -c pytorch -c nvidia
|
| 25 |
+
pip install -e .
|
| 26 |
+
```
|
| 27 |
+
|
| 28 |
+
## Quick Start
|
| 29 |
+
|
| 30 |
+
Generate a picture called *a mountain in the blue sky* under Claude Monet's style <img src="figs/artist.svg" width="30" height="30" />.
|
| 31 |
+
|
| 32 |
+
```python
|
| 33 |
+
import os
|
| 34 |
+
from PIL import Image
|
| 35 |
+
from instructg2i import InstructG2IPipeline, get_neighbor_transforms
|
| 36 |
+
|
| 37 |
+
text_prompt = 'a mountain in the blue sky' # a man playing soccer, a man playing piano
|
| 38 |
+
neighbor_pic_dir = 'examples/monet_pictures'
|
| 39 |
+
|
| 40 |
+
neighbor_transforms = get_neighbor_transforms(resolution=256)
|
| 41 |
+
pipeline = InstructG2IPipeline.from_pretrained("PeterJinGo/VirtualArtist", neighbor_num=5, device='cuda:0')
|
| 42 |
+
|
| 43 |
+
neighbor_image = [neighbor_transforms(Image.open(f'{neighbor_pic_dir}/{n_file}').convert("RGB")) for n_file in os.listdir(neighbor_pic_dir)]
|
| 44 |
+
image_gen = pipeline(prompt=text_prompt, neighbor_image=neighbor_image, neighbor_mask=[1] * len(neighbor_image), num_inference_steps=100).images[0]
|
| 45 |
+
image_gen.show()
|
| 46 |
+
```
|
| 47 |
+
|
| 48 |
+
<!--  -->
|
| 49 |
+
<div align="center">
|
| 50 |
+
<img src="figs/example.png" alt="arch" width="300" height="300" />
|
| 51 |
+
</div>
|
| 52 |
+
|
| 53 |
+
Generate a picture called *a house in the snow* combining the style of Claude Monet <img src="figs/artist.svg" width="30" height="30" /> and my little brother <img src="figs/baby.svg" width="30" height="30" />.
|
| 54 |
+
```python
|
| 55 |
+
import os
|
| 56 |
+
from PIL import Image
|
| 57 |
+
from instructg2i import image_grid, InstructG2IMultiGuidePipeline, get_neighbor_transforms
|
| 58 |
+
|
| 59 |
+
# load the model
|
| 60 |
+
pipeline = InstructG2IMultiGuidePipeline.from_pretrained("PeterJinGo/VirtualArtist", neighbor_num=5, device='cuda:0')
|
| 61 |
+
|
| 62 |
+
# configuration
|
| 63 |
+
text_prompt = 'a house in the snow' # a man playing soccer, a man playing piano
|
| 64 |
+
scale_as = [0, 3, 10]
|
| 65 |
+
scale_bs = [0, 5, 15]
|
| 66 |
+
|
| 67 |
+
# read the sampled neighbors
|
| 68 |
+
path1 = "examples/monet_pictures"
|
| 69 |
+
path2 = "examples/children_pictures"
|
| 70 |
+
neighbor_images = [[neighbor_transforms(Image.open(os.path.join(path1, n_file)).convert("RGB")) for n_file in os.listdir(path1)],
|
| 71 |
+
[neighbor_transforms(Image.open(os.path.join(path2, n_file)).convert("RGB")) for n_file in os.listdir(path2)]]
|
| 72 |
+
neighbor_masks = [[1,1,1,1,1],
|
| 73 |
+
[1,1,1,1,1]]
|
| 74 |
+
|
| 75 |
+
# generation
|
| 76 |
+
image_gens = []
|
| 77 |
+
neighbor_transforms = get_neighbor_transforms(resolution=256)
|
| 78 |
+
for scale_a in scale_as:
|
| 79 |
+
for scale_b in scale_bs:
|
| 80 |
+
graph_guidance_scales = [scale_a, scale_b]
|
| 81 |
+
|
| 82 |
+
image_gen = pipeline(prompt=text_prompt,
|
| 83 |
+
neighbor_images=neighbor_images,
|
| 84 |
+
neighbor_masks=neighbor_masks,
|
| 85 |
+
graph_guidance_scales=graph_guidance_scales,
|
| 86 |
+
num_inference_steps=100).images[0]
|
| 87 |
+
image_gens.append(image_gen)
|
| 88 |
+
res_grid = image_grid(image_gens, len(scale_as), len(scale_bs))
|
| 89 |
+
res_grid.show()
|
| 90 |
+
```
|
| 91 |
+
|
| 92 |
+
<!--  -->
|
| 93 |
+
<div align="center">
|
| 94 |
+
<img src="figs/example2.png" alt="arch" width="400" height="400" />
|
| 95 |
+
</div>
|
| 96 |
+
|
| 97 |
+
## Download Models
|
| 98 |
+
|
| 99 |
+
### Image Encoder
|
| 100 |
+
Create an image_encoder folder by ```mkdir image_encoder```, then place the files downloaded [here](https://drive.google.com/drive/folders/1AtbN401MDSVLZlH5webITfskkIIjUPLZ?usp=sharing) into the folder.
|
| 101 |
+
|
| 102 |
+
### InstructG2I checkpoints
|
| 103 |
+
|
| 104 |
+
The virtual artist InstructG2I checkpoint which is trained on Artwork graphs can be downloaded [here](https://drive.google.com/drive/folders/1ntmPgZXmb-M-k5M0Cnh34p0fxoeKnnYC?usp=sharing) or [here](https://huggingface.co/PeterJinGo/VirtualArtist).
|
| 105 |
+
|
| 106 |
+
```python
|
| 107 |
+
from huggingface_hub import snapshot_download
|
| 108 |
+
snapshot_download(repo_id="PeterJinGo/VirtualArtist", local_dir=your_local_path)
|
| 109 |
+
```
|
| 110 |
+
|
| 111 |
+
The InstructG2I checkpoints for the Amazon graph and Goodreads graph can be found [here](https://drive.google.com/drive/folders/1rPhc-LFoyqDrqn6gigTogFB7cEpRLx72?usp=sharing).
|
| 112 |
+
|
| 113 |
+
## Citations
|
| 114 |
+
If you find InstructG2I useful for your research and applications, please cite using this BibTeX:
|
| 115 |
+
```bibtex
|
| 116 |
+
|
| 117 |
+
```
|