lynx   »   [go: up one dir, main page]

Text-to-Image
Diffusers
Safetensors
StableDiffusionPipeline
stable-diffusion
@ltomczak1\n\t
yes here's an example

\n
from diffusers import StableDiffusionPipeline, EulerDiscreteScheduler\nimport torch\nmodel_id = \"stabilityai/stable-diffusion-2\"\n\ndevice = \"cuda\" if torch.cuda.is_available() else \"cpu\"\n# Use the Euler scheduler here instead\nscheduler = EulerDiscreteScheduler.from_pretrained(\n    model_id, subfolder=\"scheduler\")\npipe = StableDiffusionPipeline.from_pretrained(\n    model_id, scheduler=scheduler, torch_dtype=torch.float16)\npipe = pipe.to(device)\n\nprompt = \"a photo of an astronaut riding a horse on mars\"\nnegative_prompt = \"blurry, dark photo, blue\"\nsteps = 25\nscale = 9\nnum_images_per_prompt = 1\nseed = torch.randint(0, 1000000, (1,)).item()\ngenerator = torch.Generator(device=device).manual_seed(seed)\nimage = pipe(prompt, negative_prompt=negative_prompt, width=768, height=768, num_inference_steps=steps,\n             guidance_scale=scale, num_images_per_prompt=num_images_per_prompt, generator=generator).images[0]\n\nimage.save(\"astronaut_rides_horse.png\")\n
\n","updatedAt":"2023-02-01T20:41:54.135Z","author":{"_id":"6064e095abd8d3692e3e2ed6","avatarUrl":"https://cdn-avatars.huggingface.co/v1/production/uploads/1648966381588-6064e095abd8d3692e3e2ed6.jpeg","fullname":"Radamés Ajna","name":"radames","type":"user","isPro":true,"isHf":false,"isHfAdmin":true,"isMod":false,"followerCount":2569}},"numEdits":0,"editors":["radames"],"editorAvatarUrls":["https://cdn-avatars.huggingface.co/v1/production/uploads/1648966381588-6064e095abd8d3692e3e2ed6.jpeg"],"reactions":[{"reaction":"👍","users":["BrantonZY","msze","moteloumka","BrandonCate95","ycjcl868","Rafael4996"],"count":6}],"isReport":false}}],"pinned":false,"locked":false,"collection":"discussions","isPullRequest":false,"isReport":false},"repo":{"name":"stabilityai/stable-diffusion-2","type":"model"},"activeTab":"discussion","discussionRole":0,"watched":false,"muted":false,"repoDiscussionsLocked":false}">

Negative Prompts?

#38
by ltomczak1 - opened
@ltomczak1\n\t
yes here's an example

\n
from diffusers import StableDiffusionPipeline, EulerDiscreteScheduler\nimport torch\nmodel_id = \"stabilityai/stable-diffusion-2\"\n\ndevice = \"cuda\" if torch.cuda.is_available() else \"cpu\"\n# Use the Euler scheduler here instead\nscheduler = EulerDiscreteScheduler.from_pretrained(\n    model_id, subfolder=\"scheduler\")\npipe = StableDiffusionPipeline.from_pretrained(\n    model_id, scheduler=scheduler, torch_dtype=torch.float16)\npipe = pipe.to(device)\n\nprompt = \"a photo of an astronaut riding a horse on mars\"\nnegative_prompt = \"blurry, dark photo, blue\"\nsteps = 25\nscale = 9\nnum_images_per_prompt = 1\nseed = torch.randint(0, 1000000, (1,)).item()\ngenerator = torch.Generator(device=device).manual_seed(seed)\nimage = pipe(prompt, negative_prompt=negative_prompt, width=768, height=768, num_inference_steps=steps,\n             guidance_scale=scale, num_images_per_prompt=num_images_per_prompt, generator=generator).images[0]\n\nimage.save(\"astronaut_rides_horse.png\")\n
\n","updatedAt":"2023-02-01T20:41:54.135Z","author":{"_id":"6064e095abd8d3692e3e2ed6","avatarUrl":"https://cdn-avatars.huggingface.co/v1/production/uploads/1648966381588-6064e095abd8d3692e3e2ed6.jpeg","fullname":"Radamés Ajna","name":"radames","type":"user","isPro":true,"isHf":false,"isHfAdmin":true,"isMod":false,"followerCount":2569}},"numEdits":0,"editors":["radames"],"editorAvatarUrls":["https://cdn-avatars.huggingface.co/v1/production/uploads/1648966381588-6064e095abd8d3692e3e2ed6.jpeg"],"reactions":[{"reaction":"👍","users":["BrantonZY","msze","moteloumka","BrandonCate95","ycjcl868","Rafael4996"],"count":6}],"isReport":false}}],"pinned":false,"locked":false,"collection":"discussions","isPullRequest":false,"isReport":false},"primaryEmailConfirmed":false,"repo":{"name":"stabilityai/stable-diffusion-2","type":"model"},"discussionRole":0,"acceptLanguages":["*"],"hideComments":true,"repoDiscussionsLocked":false,"isDiscussionAuthor":false}">

Can one define a negative prompt in the StableDiffusionPipeline using the stable-diffusion-2 model? If so, how?

hi @ltomczak1
yes here's an example

from diffusers import StableDiffusionPipeline, EulerDiscreteScheduler
import torch
model_id = "stabilityai/stable-diffusion-2"

device = "cuda" if torch.cuda.is_available() else "cpu"
# Use the Euler scheduler here instead
scheduler = EulerDiscreteScheduler.from_pretrained(
    model_id, subfolder="scheduler")
pipe = StableDiffusionPipeline.from_pretrained(
    model_id, scheduler=scheduler, torch_dtype=torch.float16)
pipe = pipe.to(device)

prompt = "a photo of an astronaut riding a horse on mars"
negative_prompt = "blurry, dark photo, blue"
steps = 25
scale = 9
num_images_per_prompt = 1
seed = torch.randint(0, 1000000, (1,)).item()
generator = torch.Generator(device=device).manual_seed(seed)
image = pipe(prompt, negative_prompt=negative_prompt, width=768, height=768, num_inference_steps=steps,
             guidance_scale=scale, num_images_per_prompt=num_images_per_prompt, generator=generator).images[0]

image.save("astronaut_rides_horse.png")

Sign up or log in to comment

Лучший частный хостинг