Downloads · 30 days
5
42% of all-time downloads
zurizheng/scribblediffusion-fruit-test
scribblediffusion-fruit-test is a machine learning model from zurizheng. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
This model is a fine-tuned version of Stable Diffusion v1.5 for sketch-to-image generation, specifically trained on a fruit dataset.
Downloads · 30 days
5
42% of all-time downloads
All-time downloads
12
Public
Repo size
—
Likes
0
Public
Click a slice to open those files.
.md4.4 KB · 61%
From the Hugging Face model README
This model is a fine-tuned version of Stable Diffusion v1.5 for sketch-to-image generation, specifically trained on a fruit dataset.
ScribbleDiffusion allows you to generate high-quality images from simple sketches combined with text prompts. This version has been trained on 6 fruit categories:
The model consists of three main components:
import torch
from diffusers import UNet2DConditionModel, AutoencoderKL, DDIMScheduler
from transformers import CLIPTokenizer, CLIPTextModel
from safetensors.torch import load_file
# Load base models
vae = AutoencoderKL.from_pretrained("runwayml/stable-diffusion-v1-5", subfolder="vae")
tokenizer = CLIPTokenizer.from_pretrained("runwayml/stable-diffusion-v1-5", subfolder="tokenizer")
text_encoder = CLIPTextModel.from_pretrained("runwayml/stable-diffusion-v1-5", subfolder="text_encoder")
scheduler = DDIMScheduler.from_pretrained("runwayml/stable-diffusion-v1-5", subfolder="scheduler")
# Load fine-tuned UNet
unet = UNet2DConditionModel.from_pretrained("runwayml/stable-diffusion-v1-5", subfolder="unet")
unet_state = load_file("unet.safetensors")
unet.load_state_dict(unet_state)
# Load custom sketch components
# Note: You'll need the custom SketchCrossAttentionEncoder and SketchTextCombiner classes
sketch_encoder_state = load_file("sketch_encoder.safetensors")
sketch_combiner_state = load_file("sketch_text_combiner.safetensors")
# Your sketch should be a 1-channel grayscale image (edges/contours)
sketch = load_sketch_image("your_sketch.png") # 256x256 grayscale
prompt = "a red apple"
# Process sketch and text
sketch_embeddings = sketch_encoder(sketch)
text_embeddings = text_encoder(tokenize(prompt))
combined_embeddings = sketch_text_combiner(text_embeddings, sketch_embeddings)
# Generate image
with torch.no_grad():
latents = torch.randn((1, 4, 32, 32)) # 256x256 -> 32x32 latents
for t in scheduler.timesteps:
noise_pred = unet(latents, t, encoder_hidden_states=combined_embeddings).sample
latents = scheduler.step(noise_pred, t, latents).prev_sample
# Decode to image
image = vae.decode(latents / vae.config.scaling_factor).sample
unet.safetensors (3.3GB): Fine-tuned UNet model weightssketch_encoder.safetensors (24MB): Sketch encoder weightssketch_text_combiner.safetensors (16 bytes): Sketch-text combiner weightstraining_info.json: Training metadataThe model was trained on a curated fruit dataset containing high-quality images of 6 fruit categories. Sketches were automatically generated using edge detection algorithms.
This model inherits potential biases from the Stable Diffusion v1.5 base model. The fruit dataset training may introduce biases toward specific fruit appearances and orientations present in the training data.
@misc{scribblediffusion-fruit-2024,
title={ScribbleDiffusion: Fruit Dataset Fine-tuned Model},
author={Your Name},
year={2024},
howpublished={\\url{https://huggingface.co/your-username/scribblediffusion-fruit}}
}
This model is released under the same license as Stable Diffusion v1.5. Please refer to the original licensing terms.