|
| 1 | +## Use Cases |
| 2 | + |
| 3 | +### Instruction-based Image Editing |
| 4 | + |
| 5 | +Image-text-to-image models can be used to edit images based on natural language instructions. For example, you can provide an image of a summer landscape and the instruction "Make it winter, add snow" to generate a winter version of the same scene. |
| 6 | + |
| 7 | +### Style Transfer |
| 8 | + |
| 9 | +These models can apply artistic styles or transformations to images based on text descriptions. For instance, you can transform a photo into a painting style by providing prompts like "Make it look like a Van Gogh painting" or "Convert to watercolor style." |
| 10 | + |
| 11 | +### Image Variations |
| 12 | + |
| 13 | +Generate variations of an existing image by providing different text prompts. This is useful for creative workflows where you want to explore different versions of the same image with specific modifications. |
| 14 | + |
| 15 | +### Guided Image Generation |
| 16 | + |
| 17 | +Use a reference image along with text prompts to guide the generation process. This allows for more controlled image generation compared to text-to-image models alone, as the reference image provides structural guidance. |
| 18 | + |
| 19 | +### Image Inpainting and Outpainting |
| 20 | + |
| 21 | +Fill in missing or masked parts of an image based on text descriptions, or extend an image beyond its original boundaries with text-guided generation. |
| 22 | + |
| 23 | +## Task Variants |
| 24 | + |
| 25 | +### Instruction-based Editing |
| 26 | + |
| 27 | +Models that follow natural language instructions to edit images, which can perform complex edits like object removal, color changes, and compositional modifications. |
| 28 | + |
| 29 | +### Reference-guided Generation |
| 30 | + |
| 31 | +Models that use a reference image to guide the generation process while incorporating text prompts to control specific attributes or modifications. |
| 32 | + |
| 33 | +### Conditional Image-to-Image |
| 34 | + |
| 35 | +Models that perform specific transformations based on text conditions, such as changing weather conditions, time of day, or seasonal variations. |
| 36 | + |
| 37 | +## Inference |
| 38 | + |
| 39 | +You can use the Diffusers library to interact with image-text-to-image models. |
| 40 | + |
| 41 | +```python |
| 42 | +import torch |
| 43 | +from diffusers import Flux2Pipeline |
| 44 | +from diffusers.utils import load_image |
| 45 | + |
| 46 | +repo_id = "black-forest-labs/FLUX.2-dev" |
| 47 | +device = "cuda:0" |
| 48 | +torch_dtype = torch.bfloat16 |
| 49 | + |
| 50 | +pipe = Flux2Pipeline.from_pretrained( |
| 51 | + repo_id, torch_dtype=torch_dtype |
| 52 | +) |
| 53 | +pipe.enable_model_cpu_offload() #no need to do cpu offload for >80G VRAM carts like H200, B200, etc. and do a `pipe.to(device)` instead |
| 54 | + |
| 55 | +prompt = "Realistic macro photograph of a hermit crab using a soda can as its shell, partially emerging from the can, captured with sharp detail and natural colors, on a sunlit beach with soft shadows and a shallow depth of field, with blurred ocean waves in the background. The can has the text `BFL Diffusers` on it and it has a color gradient that start with #FF5733 at the top and transitions to #33FF57 at the bottom." |
| 56 | + |
| 57 | +#cat_image = load_image("https://huggingface.co/spaces/zerogpu-aoti/FLUX.1-Kontext-Dev-fp8-dynamic/resolve/main/cat.png") |
| 58 | +image = pipe( |
| 59 | + prompt=prompt, |
| 60 | + #image=[cat_image] #multi-image input |
| 61 | + generator=torch.Generator(device=device).manual_seed(42), |
| 62 | + num_inference_steps=50, |
| 63 | + guidance_scale=4, |
| 64 | +).images[0] |
| 65 | + |
| 66 | +image.save("flux2_output.png") |
| 67 | +``` |
| 68 | + |
| 69 | +## Useful Resources |
| 70 | + |
| 71 | +- [FLUX.2 Model Card](https://huggingface.co/black-forest-labs/FLUX.2-dev) |
| 72 | +- [Diffusers documentation on Image-to-Image](https://huggingface.co/docs/diffusers/using-diffusers/img2img) |
| 73 | +- [ControlNet for Conditional Image Generation](https://huggingface.co/docs/diffusers/using-diffusers/controlnet) |
0 commit comments