Stable Diffusion 2.x Fine-tuned with Leaf Images: Text-to-image and text-to-3D
DreamBooth is an advanced technique designed for fine-tuning text-to-image diffusion models to generate personalized images of specific subjects. By leveraging a few reference images (around 5 or so), DreamBooth integrates unique visual features of the subject into the model's output domain.
This is achieved by binding a unique identifier "<..IDENTIFIER..>", such as <leaf microstructure> in this work, to the subject. An optional class-specific prior preservation loss can be used to maintain high fidelity and contextual diversity. The result is a model capable of synthesizing novel, photorealistic images of the subject in various scenes, poses, and lighting conditions, guided by text prompts. In this project, DreamBooth has been applied to render images with specific biological patterns, making it ideal for applications in materials science and engineering where accurate representation of biological material microstructures is crucial.
For example, an original prompt might be: "a vase with intricate patterns, high quality." With the fine-tuned model, using the unique identifier, the prompt becomes: "a vase that resembles a <leaf microstructure>, high quality." This allows the model to generate images that specifically incorporate the desired biological pattern.
Model description
These are fine-tuned weights for the
stabilityai/stable-diffusion-2
model. This is a full fine-tune of the model using DreamBooth.
Trigger keywords
The following image were used during fine-tuning using the keyword <leaf microstructure>:
Please use <leaf microstructure> to trigger the image generation.
How to use
Defining some helper functions:
from diffusers import DiffusionPipeline
import torch
import os
from datetime import datetime
from PIL import Image
defgenerate_filename(base_name, extension=".png"):
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
returnf"{base_name}_{timestamp}{extension}"defsave_image(image, directory, base_name="image_grid"):
filename = generate_filename(base_name)
file_path = os.path.join(directory, filename)
image.save(file_path)
print(f"Image saved as {file_path}")
defimage_grid(imgs, rows, cols, save=True, save_dir='generated_images', base_name="image_grid", save_individual_files=False):
ifnot os.path.exists(save_dir):
os.makedirs(save_dir)
assertlen(imgs) == rows * cols
w, h = imgs[0].size
grid = Image.new('RGB', size=(cols * w, rows * h))
grid_w, grid_h = grid.size
for i, img inenumerate(imgs):
grid.paste(img, box=(i % cols * w, i // cols * h))
if save_individual_files:
save_image(img, save_dir, base_name=base_name+f'_{i}-of-{len(imgs)}_')
if save and save_dir:
save_image(grid, save_dir, base_name)
return grid
prompt = "a vase that resembles a <leaf microstructure>, high quality"
num_samples = 4
num_rows = 4
all_images = []
for _ inrange(num_rows):
images = pipe(prompt, num_images_per_prompt=num_samples, num_inference_steps=50, guidance_scale=15).images
all_images.extend(images)
grid = image_grid(all_images, num_rows, num_samples)
grid
Image-to-Image
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.
Create draft image:
prompt = "a vase that resembles a <leaf microstructure>, high quality"
num_samples = 4
num_rows = 1
all_images = []
for _ in range(num_rows):
images = pipe(prompt, num_images_per_prompt=num_samples, num_inference_steps=50, guidance_scale=15).images
all_images.extend(images)
grid = image_grid(all_images, num_rows, num_samples, save_individual_files=True)
grid
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 (if you run the generate code yourself, the generated images will be in the subdirectory
generated_images
):
SD2x-leaf-inspired huggingface.co is an AI model on huggingface.co that provides SD2x-leaf-inspired's model effect (), which can be used instantly with this lamm-mit SD2x-leaf-inspired model. huggingface.co supports a free trial of the SD2x-leaf-inspired model, and also provides paid use of the SD2x-leaf-inspired. Support call SD2x-leaf-inspired model through api, including Node.js, Python, http.
SD2x-leaf-inspired huggingface.co is an online trial and call api platform, which integrates SD2x-leaf-inspired's modeling effects, including api services, and provides a free online trial of SD2x-leaf-inspired, you can try SD2x-leaf-inspired online for free by clicking the link below.
lamm-mit SD2x-leaf-inspired online free url in huggingface.co:
SD2x-leaf-inspired is an open source model from GitHub that offers a free installation service, and any user can find SD2x-leaf-inspired on GitHub to install. At the same time, huggingface.co provides the effect of SD2x-leaf-inspired install, users can directly use SD2x-leaf-inspired installed effect in huggingface.co for debugging and trial. It also supports api for free installation.