Update README.md
Browse files
README.md
CHANGED
|
@@ -46,8 +46,50 @@ We adopt [Shakker-Labs/FLUX.1-dev-LoRA-collections](https://huggingface.co/Shakk
|
|
| 46 |
</div>
|
| 47 |
|
| 48 |
# Inference
|
|
|
|
| 49 |
```python
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
```
|
| 52 |
|
| 53 |
# Limitations
|
|
|
|
| 46 |
</div>
|
| 47 |
|
| 48 |
# Inference
|
| 49 |
+
The code has not been integrated into diffusers yet, please use our local files at this moment.
|
| 50 |
```python
|
| 51 |
+
import os
|
| 52 |
+
from PIL import Image
|
| 53 |
+
|
| 54 |
+
import torch
|
| 55 |
+
import torch.nn as nn
|
| 56 |
+
|
| 57 |
+
from pipeline_flux_ipa import FluxPipeline
|
| 58 |
+
from transformer_flux import FluxTransformer2DModel
|
| 59 |
+
from attention_processor import IPAFluxAttnProcessor2_0
|
| 60 |
+
from transformers import AutoProcessor, SiglipVisionModel
|
| 61 |
+
|
| 62 |
+
from infer_flux_ipa_siglip import MLPProjModel, IPAdapter
|
| 63 |
+
|
| 64 |
+
image_encoder_path = "google/siglip-so400m-patch14-384"
|
| 65 |
+
ipadapter_path = "./ip-adapter.bin"
|
| 66 |
+
|
| 67 |
+
transformer = FluxTransformer2DModel.from_pretrained(
|
| 68 |
+
"black-forest-labs/FLUX.1-dev", subfolder="transformer", torch_dtype=torch.bfloat16
|
| 69 |
+
)
|
| 70 |
+
|
| 71 |
+
pipe = FluxPipeline.from_pretrained(
|
| 72 |
+
"black-forest-labs/FLUX.1-dev", transformer=transformer, torch_dtype=torch.bfloat16
|
| 73 |
+
)
|
| 74 |
+
|
| 75 |
+
ip_model = IPAdapter(pipe, image_encoder_path, ipadapter_path, device="cuda", num_tokens=128)
|
| 76 |
+
|
| 77 |
+
image_dir = "./assets/images/2.jpg"
|
| 78 |
+
image_name = image_dir.split("/")[-1]
|
| 79 |
+
image = Image.open(image_dir).convert("RGB")
|
| 80 |
+
image = resize_img(image)
|
| 81 |
+
|
| 82 |
+
prompt = "a young girl"
|
| 83 |
+
|
| 84 |
+
images = ip_model.generate(
|
| 85 |
+
pil_image=image,
|
| 86 |
+
prompt=prompt,
|
| 87 |
+
scale=0.7,
|
| 88 |
+
width=960, height=1280,
|
| 89 |
+
seed=42
|
| 90 |
+
)
|
| 91 |
+
|
| 92 |
+
images[0].save(f"results/{image_name}")
|
| 93 |
```
|
| 94 |
|
| 95 |
# Limitations
|