Update README.md
Browse files
README.md
CHANGED
|
@@ -107,6 +107,56 @@ grid
|
|
| 107 |
```
|
| 108 |

|
| 109 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
## Fine-tuning script
|
| 111 |
|
| 112 |
Download this script: [SD2x DreamBooth-Fine-Tune.ipynb](https://huggingface.co/lamm-mit/SD2x-leaf-inspired/resolve/main/SD2x_DreamBooth_Fine-Tune.ipynb)
|
|
|
|
| 107 |
```
|
| 108 |

|
| 109 |
|
| 110 |
+
### Image-to-Image
|
| 111 |
+
|
| 112 |
+
The model can be used also for image-to-image tasks. For instance, we can first generate a draft image and then further modify it.
|
| 113 |
+
|
| 114 |
+
Create draft image:
|
| 115 |
+
```
|
| 116 |
+
prompt = "a vase that resembles a <leaf microstructure>, high quality"
|
| 117 |
+
num_samples = 4
|
| 118 |
+
num_rows = 1
|
| 119 |
+
|
| 120 |
+
all_images = []
|
| 121 |
+
for _ in range(num_rows):
|
| 122 |
+
images = pipe(prompt, num_images_per_prompt=num_samples, num_inference_steps=50, guidance_scale=15).images
|
| 123 |
+
all_images.extend(images)
|
| 124 |
+
|
| 125 |
+
grid = image_grid(all_images, num_rows, num_samples, save_individual_files=True)
|
| 126 |
+
grid
|
| 127 |
+
```
|
| 128 |
+
|
| 129 |
+

|
| 130 |
+
|
| 131 |
+
Now we use one of the images (second from left) and modify it using the image-to-image pipeline. You can get the image as follows:
|
| 132 |
+
|
| 133 |
+
```
|
| 134 |
+
cd generated_images
|
| 135 |
+
wget
|
| 136 |
+
cd ..
|
| 137 |
+
```
|
| 138 |
+
Now, generate:
|
| 139 |
+
```
|
| 140 |
+
fname='generated_images/image_grid_1-of-4__20240722_144702.png'
|
| 141 |
+
init_image = Image.open(fname).convert("RGB")
|
| 142 |
+
init_image = init_image.resize((768, 768))
|
| 143 |
+
|
| 144 |
+
prompt = "A vase made out of a spongy material, high quality photograph, full frame."
|
| 145 |
+
num_samples = 4
|
| 146 |
+
num_rows = 1
|
| 147 |
+
|
| 148 |
+
all_images = []
|
| 149 |
+
for _ in range(num_rows):
|
| 150 |
+
images = img2imgpipe(prompt, image=init_image,
|
| 151 |
+
num_images_per_prompt=num_samples, strength=0.8, num_inference_steps=75, guidance_scale=25).images
|
| 152 |
+
all_images.extend(images)
|
| 153 |
+
|
| 154 |
+
grid = image_grid(images, num_rows, num_samples, save_individual_files=True)
|
| 155 |
+
grid
|
| 156 |
+
```
|
| 157 |
+
|
| 158 |
+

|
| 159 |
+
|
| 160 |
## Fine-tuning script
|
| 161 |
|
| 162 |
Download this script: [SD2x DreamBooth-Fine-Tune.ipynb](https://huggingface.co/lamm-mit/SD2x-leaf-inspired/resolve/main/SD2x_DreamBooth_Fine-Tune.ipynb)
|