# Stable Diffusion 2

Stable Diffusion 2, orijinal [Stable Diffusion](https://stability.ai/blog/stable-diffusion-public-release) çalışmasının üzerine inşa edilmiş, [Stability AI](https://stability.ai/) ve [LAION](https://laion.ai/)’dan Robin Rombach ve Katherine Crowson tarafından yönetilen bir metinden görüntüye _latent diffusion_ modelidir.

*Stable Diffusion 2.0 sürümü, LAION tarafından Stability AI desteğiyle geliştirilen ve daha önceki V1 sürümlerine kıyasla üretilen görsellerin kalitesini büyük ölçüde artıran, tamamen yeni bir metin kodlayıcı (OpenCLIP) kullanılarak eğitilen sağlam metinden görsel modellerini içerir. Bu sürümdeki metinden görsel modelleri, varsayılan olarak hem 512x512 hem de 768x768 piksel çözünürlüklerinde görsel üretebilir. Bu modeller, Stability AI'daki DeepFloyd ekibi tarafından oluşturulan [LAION-5B veri seti](https://laion.ai/blog/laion-5b/)nin estetik bir alt kümesinde eğitilmiş olup ardından [LAION'un NSFW filtresi](https://openreview.net/forum?id=M3Y74vmsMcY) kullanılarak yetişkin içeriği kaldırılacak şekilde daha da filtrelenmiştir.*

Stable Diffusion 2'nin nasıl çalıştığı ve orijinal Stable Diffusion'dan nasıl farklılaştığına dair daha fazla ayrıntı için lütfen resmi [duyuru yazısına](https://stability.ai/blog/stable-diffusion-v2-release) bakın.

Stable Diffusion 2 mimarisi, orijinal [Stable Diffusion model](./text2img) mimarisiyle büyük ölçüde aynıdır; Stable Diffusion 2'nin nasıl kullanılacağına dair API dokümantasyonuna göz atın. Makul bir hız/kalite dengesi sağladığı ve yalnızca 20 adımla çalıştırılabildiği için [DPMSolverMultistepScheduler](/docs/diffusers/main/tr/api/schedulers/multistep_dpm_solver#diffusers.DPMSolverMultistepScheduler) kullanmanızı öneririz.

Stable Diffusion 2, metinden görüntüye, inpainting, süper çözünürlük ve derinlikten görüntüye gibi görevler için kullanılabilir:

| Görev                    | Depo                                                                                                    |
|-------------------------|---------------------------------------------------------------------------------------------------------------|
| metinden görüntüye (512x512) | [stabilityai/stable-diffusion-2-base](https://huggingface.co/stabilityai/stable-diffusion-2-base)             |
| metinden görüntüye (768x768) | [stabilityai/stable-diffusion-2](https://huggingface.co/stabilityai/stable-diffusion-2)                       |
| inpainting              | [stabilityai/stable-diffusion-2-inpainting](https://huggingface.co/stabilityai/stable-diffusion-2-inpainting) |
| super-resolution        | [stable-diffusion-x4-upscaler](https://huggingface.co/stabilityai/stable-diffusion-x4-upscaler)               |
| derinlikten görüntüye          | [stabilityai/stable-diffusion-2-depth](https://huggingface.co/stabilityai/stable-diffusion-2-depth)           |

Stable Diffusion 2'nin her görev için nasıl kullanılacağına dair bazı örnekler:

> [!TIP]
> Scheduler hızı ve kalitesi arasındaki ödünleşimi nasıl keşfedebileceğinizi ve pipeline bileşenlerini nasıl verimli bir şekilde yeniden kullanabileceğinizi öğrenmek için Stable Diffusion [İpuçları](overview#tips) bölümünü mutlaka inceleyin!
>
> Bir görev için resmi kontrol noktalarından birini kullanmakla ilgileniyorsanız, [CompVis](https://huggingface.co/CompVis) ve [Stability AI](https://huggingface.co/stabilityai) Hub kuruluşlarını keşfedin!

## Metinden görüntüye

```py
from diffusers import DiffusionPipeline, DPMSolverMultistepScheduler
import torch

repo_id = "stabilityai/stable-diffusion-2-base"
pipe = DiffusionPipeline.from_pretrained(repo_id, dtype=torch.float16, variant="fp16")

pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
pipe = pipe.to("cuda")  # or "mps", "xpu", "cpu"

prompt = "High quality photo of an astronaut riding a horse in space"
image = pipe(prompt, num_inference_steps=25).images[0]
image
```

## Inpainting

```py
import torch
from diffusers import DiffusionPipeline, DPMSolverMultistepScheduler
from diffusers.utils import load_image, make_image_grid

img_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo.png"
mask_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo_mask.png"

init_image = load_image(img_url).resize((512, 512))
mask_image = load_image(mask_url).resize((512, 512))

repo_id = "stabilityai/stable-diffusion-2-inpainting"
pipe = DiffusionPipeline.from_pretrained(repo_id, dtype=torch.float16, variant="fp16")

pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
pipe = pipe.to("cuda")  # or "mps", "xpu", "cpu"

prompt = "Face of a yellow cat, high resolution, sitting on a park bench"
image = pipe(prompt=prompt, image=init_image, mask_image=mask_image, num_inference_steps=25).images[0]
make_image_grid([init_image, mask_image, image], rows=1, cols=3)
```

## Süper çözünürlük

```py
from diffusers import StableDiffusionUpscalePipeline
from diffusers.utils import load_image, make_image_grid
import torch

# load model and scheduler
model_id = "stabilityai/stable-diffusion-x4-upscaler"
pipeline = StableDiffusionUpscalePipeline.from_pretrained(model_id, dtype=torch.float16)
pipeline = pipeline.to("cuda")  # or "mps", "xpu", "cpu"

# let's download an  image
url = "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/sd2-upscale/low_res_cat.png"
low_res_img = load_image(url)
low_res_img = low_res_img.resize((128, 128))
prompt = "a white cat"
upscaled_image = pipeline(prompt=prompt, image=low_res_img).images[0]
make_image_grid([low_res_img.resize((512, 512)), upscaled_image.resize((512, 512))], rows=1, cols=2)
```

## Derinlikten görüntüye

```py
import torch
from diffusers import StableDiffusionDepth2ImgPipeline
from diffusers.utils import load_image, make_image_grid

pipe = StableDiffusionDepth2ImgPipeline.from_pretrained(
    "stabilityai/stable-diffusion-2-depth",
    dtype=torch.float16,
).to("cuda")  # or "mps", "xpu", "cpu"

url = "http://images.cocodataset.org/val2017/000000039769.jpg"
init_image = load_image(url)
prompt = "two tigers"
negative_prompt = "bad, deformed, ugly, bad anotomy"
image = pipe(prompt=prompt, image=init_image, negative_prompt=negative_prompt, strength=0.7).images[0]
make_image_grid([init_image, image], rows=1, cols=2)
```

