FLUX.1 [dev] is a 12 billion parameter rectified flow transformer capable of generating images from text descriptions.
The following images were used during fine-tuning using the keyword <leaf microstructure>:
You should use <leaf microstructure> to trigger this feature during image generation.
1import os
2from datetime import datetime
3from PIL import Image
4
5def generate_filename(base_name, extension=".png"):
6 timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
7 return f"{base_name}_{timestamp}{extension}"
8
9def save_image(image, directory, base_name="image_grid"):
10 filename = generate_filename(base_name)
11 file_path = os.path.join(directory, filename)
12 image.save(file_path)
13 print(f"Image saved as {file_path}")
14
15def image_grid(imgs, rows, cols, save=True, save_dir='generated_images', base_name="image_grid",
16 save_individual_files=False):
17
18 if not os.path.exists(save_dir):
19 os.makedirs(save_dir)
20
21 assert len(imgs) == rows * cols
22
23 w, h = imgs[0].size
24 grid = Image.new('RGB', size=(cols * w, rows * h))
25 grid_w, grid_h = grid.size
26
27 for i, img in enumerate(imgs):
28 grid.paste(img, box=(i % cols * w, i // cols * h))
29 if save_individual_files:
30 save_image(img, save_dir, base_name=base_name+f'_{i}-of-{len(imgs)}_')
31
32 if save and save_dir:
33 save_image(grid, save_dir, base_name)
34
35 return grid
1from diffusers import FluxPipeline
2import torch
3
4repo_id = 'lamm-mit/leaf-FLUX.1-dev'
5
6pipeline = FluxPipeline.from_pretrained(
7 "black-forest-labs/FLUX.1-dev",
8 torch_dtype=torch.bfloat16,
9 max_sequence_length=512,
10)
11
12#pipeline.enable_model_cpu_offload() #save some VRAM by offloading the model to CPU. Comment out if you have enough GPU VRAM
13
14pipeline.load_lora_weights(repo_id, #weight_name=f'XXX.safetensors'
15 )
16pipeline=pipeline.to('cuda')
1prompt=('Generate an image of a golden spider web network intertwined with collagen veins, '
2 'forming a dynamic, leaf-inspired microstructure amidst a lush green background.' )
3
4num_samples =2
5num_rows = 2
6n_steps=25
7guidance_scale=3.5
8all_images = []
9for _ in range(num_rows):
10
11
12 image = pipeline(prompt,num_inference_steps=n_steps,num_images_per_prompt=num_samples,
13 guidance_scale=guidance_scale,).images
14
15 all_images.extend(image)
16
17grid = image_grid(all_images, num_rows, num_samples,
18 save_individual_files=True, )
19grid
1prompt="""Generate a futuristic, eco-friendly architectural concept utilizing a biomimetic composite material that integrates the structural efficiency of spider silk with the adaptive porosity of plant tissues. Utilize the following key features:
2
3* Fibrous architecture inspired by spider silk, represented by sinuous lines and curved forms.
4* Interconnected, spherical nodes reminiscent of plant cell walls, emphasizing growth and adaptation.
5* Open cellular structures echoing the permeable nature of plant leaves, suggesting dynamic exchanges and self-regulation capabilities.
6* Gradations of opacity and transparency inspired by the varying densities found in plant tissues, highlighting functional differentiation and multi-functionality.
7"""
8
9num_samples =2
10num_rows = 2
11n_steps=25
12guidance_scale=3.5
13all_images = []
14for _ in range(num_rows):
15
16
17 image = pipeline(prompt,num_inference_steps=n_steps,num_images_per_prompt=num_samples,
18 guidance_scale=guidance_scale,).images
19
20 all_images.extend(image)
21
22grid = image_grid(all_images, num_rows, num_samples,
23 save_individual_files=True, )
24grid
1prompt="""A cube in the shape of a <leaf microstructure>, made out of limestone, holding a sign that says 'MATERIOMICS'.
2
3The cube is placed in a stunning mountain landscape.
4
5The cube shows intricate patterns of <leaf microstructure>.
6"""
7
8num_samples =2
9num_rows = 2
10n_steps=25
11guidance_scale=3.5
12all_images = []
13for _ in range(num_rows):
14
15
16 image = pipeline(prompt,num_inference_steps=n_steps,num_images_per_prompt=num_samples,
17 guidance_scale=guidance_scale,).images
18
19 all_images.extend(image)
20
21grid = image_grid(all_images, num_rows, num_samples,
22 save_individual_files=True, )
23grid
1@article{LuLuuBuehler2024,
2 title={Fine-tuning large language models for domain adaptation: Exploration of training strategies, scaling, model merging and synergistic capabilities},
3 author={Wei Lu and Rachel K. Luu and Markus J. Buehler},
4 journal={arXiv: https://arxiv.org/abs/2409.03444},
5 year={2024},
6}