Buckets:
# DeepFloyd IF
## نظرة عامة
DeepFloyd IF هو نموذج مفتوح المصدر حديث ومتطور لتوليد الصور من النص، يتميز بدرجة عالية من الواقعية الضوئية وفهم اللغة. يتكون النموذج من وحدات منفصلة تشمل مشفّر نصي مجمّد وثلاثة وحدات انتشار بكسل متسلسلة:
- المرحلة 1: نموذج أساسي يولّد صورة بدقة 64x64 بكسل بناءً على وصف نصي،
- المرحلة 2: نموذج فائق الدقة 64x64 بكسل => 256x256 بكسل، و
- المرحلة 3: نموذج فائق الدقة 256x256 بكسل => 1024x1024 بكسل
تستخدم المرحلة 1 والمرحلة 2 مُشفِّر نص مجمّد مبني على محوّل T5 لاستخراج تمثيلات النص، ثم تُغذّى هذه التمثيلات في بنية UNet معززة بآلية الانتباه المتقاطع (cross-attention) وتجميع الانتباه (attention pooling). المرحلة 3 هي [نموذج x4 Upscaling من Stability AI](https://huggingface.co/stabilityai/stable-diffusion-x4-upscaler). النتيجة هي نموذج شديد الكفاءة يتفوق على أحدث النماذج المتقدمة حاليًا، محققًا درجة FID صفرية (zero-shot) تبلغ 6.66 على مجموعة بيانات COCO. يؤكد عملنا على إمكانات بنية UNet الأكبر حجمًا في المرحلة الأولى من نماذج الانتشار المتسلسلة (cascaded diffusion models)، ويصوّر مستقبلًا واعدًا لتوليد الصور من النص.
## الاستخدام
قبل أن تتمكن من استخدام IF، عليك قبول شروط استخدامه. للقيام بذلك:
1. تأكد من امتلاك [حساب Hugging Face](https://huggingface.co/join) وتسجيل الدخول.
2. قبل الترخيص في بطاقة النموذج الخاصة بـ [DeepFloyd/IF-I-XL-v1.0](https://huggingface.co/DeepFloyd/IF-I-XL-v1.0). قبول الترخيص في بطاقة نموذج المرحلة الأولى سيقبل تلقائياً لبقية نماذج IF.
3. تأكد من تسجيل الدخول محليًا. ثبّت `huggingface_hub`:
```sh
pip install huggingface_hub --upgrade
```
شغّل دالة تسجيل الدخول في واجهة Python:
```py
from huggingface_hub import login
login()
```
وأدخل [رمز الوصول الخاص بك إلى Hugging Face Hub](https://huggingface.co/docs/hub/security-tokens#what-are-user-access-tokens).
في الخطوة التالية نقوم بتثبيت `diffusers` والتبعيات:
```sh
pip install -q diffusers accelerate transformers
```
تقدم الأقسام التالية أمثلة أكثر تفصيلاً حول كيفية استخدام IF. على وجه التحديد:
- [توليد الصور من النص](#text-to-image-generation)
- [توليد الصور من الصور](#text-guided-image-to-image-generation)
- [تعبئة المناطق المفقودة](#text-guided-inpainting-generation)
- [إعادة استخدام أوزان النموذج](#converting-between-different-pipelines)
- [تحسين السرعة](#optimizing-for-speed)
- [تحسين الذاكرة](#optimizing-for-memory)
**النقاط المحفوظة المتاحة**
- *المرحلة 1*
- [DeepFloyd/IF-I-XL-v1.0](https://huggingface.co/DeepFloyd/IF-I-XL-v1.0)
- [DeepFloyd/IF-I-L-v1.0](https://huggingface.co/DeepFloyd/IF-I-L-v1.0)
- [DeepFloyd/IF-I-M-v1.0](https://huggingface.co/DeepFloyd/IF-I-M-v1.0)
- *المرحلة 2*
- [DeepFloyd/IF-II-L-v1.0](https://huggingface.co/DeepFloyd/IF-II-L-v1.0)
- [DeepFloyd/IF-II-M-v1.0](https://huggingface.co/DeepFloyd/IF-II-M-v1.0)
- *المرحلة 3*
- [stabilityai/stable-diffusion-x4-upscaler](https://huggingface.co/stabilityai/stable-diffusion-x4-upscaler)
**Google Colab** [](https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers/deepfloyd_if_free_tier_google_colab.ipynb)
### توليد الصور من النص
يستخدم [نقل النموذج إلى وحدة المعالجة المركزية](../../optimization/memory#model-offloading) افتراضياً في diffusers لتشغيل خط أنابيب IF بالكامل باستخدام ما لا يقل عن 14 جيجابايت من ذاكرة الفيديو.
```python
from diffusers import DiffusionPipeline
from diffusers.utils import pt_to_pil, make_image_grid
import torch
# stage 1
stage_1 = DiffusionPipeline.from_pretrained("DeepFloyd/IF-I-XL-v1.0", variant="fp16", dtype=torch.float16)
stage_1.enable_model_cpu_offload()
# stage 2
stage_2 = DiffusionPipeline.from_pretrained(
"DeepFloyd/IF-II-L-v1.0", text_encoder=None, variant="fp16", dtype=torch.float16
)
stage_2.enable_model_cpu_offload()
# stage 3
safety_modules = {
"feature_extractor": stage_1.feature_extractor,
"safety_checker": stage_1.safety_checker,
"watermarker": stage_1.watermarker,
}
stage_3 = DiffusionPipeline.from_pretrained(
"stabilityai/stable-diffusion-x4-upscaler", **safety_modules, dtype=torch.float16
)
stage_3.enable_model_cpu_offload()
prompt = 'a photo of a kangaroo wearing an orange hoodie and blue sunglasses standing in front of the eiffel tower holding a sign that says "very deep learning"'
generator = torch.manual_seed(1)
# text embeds
prompt_embeds, negative_embeds = stage_1.encode_prompt(prompt)
# stage 1
stage_1_output = stage_1(
prompt_embeds=prompt_embeds, negative_prompt_embeds=negative_embeds, generator=generator, output_type="pt"
).images
#pt_to_pil(stage_1_output)[0].save("./if_stage_I.png")
# stage 2
stage_2_output = stage_2(
image=stage_1_output,
prompt_embeds=prompt_embeds,
negative_prompt_embeds=negative_embeds,
generator=generator,
output_type="pt",
).images
#pt_to_pil(stage_2_output)[0].save("./if_stage_II.png")
# stage 3
stage_3_output = stage_3(prompt=prompt, image=stage_2_output, noise_level=100, generator=generator).images
#stage_3_output[0].save("./if_stage_III.png")
make_image_grid([pt_to_pil(stage_1_output)[0], pt_to_pil(stage_2_output)[0], stage_3_output[0]], rows=1, rows=3)
```
### توليد الصور من الصور بتوجيه النص
يمكن استخدام أوزان نموذج IF نفسها لتحويل الصورة إلى صورة موجّه بالنص أو لتوليد تنويعات للصورة. في هذه الحالة، تأكد فقط من تحميل الأوزان باستخدام خططي العمل [IFImg2ImgPipeline](/docs/diffusers/main/ar/api/pipelines/deepfloyd_if#diffusers.IFImg2ImgPipeline) و[IFImg2ImgSuperResolutionPipeline](/docs/diffusers/main/ar/api/pipelines/deepfloyd_if#diffusers.IFImg2ImgSuperResolutionPipeline).
**ملاحظة**: يمكنك أيضًا نقل أوزان خطوط أنابيب النص إلى الصورة مباشرةً إلى خطوط أنابيب الصورة إلى الصورة دون تحميلها مرتين من خلال استخدام معامل [components](/docs/diffusers/main/ar/api/pipelines/overview#diffusers.DiffusionPipeline.components) كما هو موضح [هنا](#converting-between-different-pipelines).
```python
from diffusers import IFImg2ImgPipeline, IFImg2ImgSuperResolutionPipeline, DiffusionPipeline
from diffusers.utils import pt_to_pil, load_image, make_image_grid
import torch
# download image
url = "https://raw.githubusercontent.com/CompVis/stable-diffusion/main/assets/stable-samples/img2img/sketch-mountains-input.jpg"
original_image = load_image(url)
original_image = original_image.resize((768, 512))
# stage 1
stage_1 = IFImg2ImgPipeline.from_pretrained("DeepFloyd/IF-I-XL-v1.0", variant="fp16", dtype=torch.float16)
stage_1.enable_model_cpu_offload()
# stage 2
stage_2 = IFImg2ImgSuperResolutionPipeline.from_pretrained(
"DeepFloyd/IF-II-L-v1.0", text_encoder=None, variant="fp16", dtype=torch.float16
)
stage_2.enable_model_cpu_offload()
# stage 3
safety_modules = {
"feature_extractor": stage_1.feature_extractor,
"safety_checker": stage_1.safety_checker,
"watermarker": stage_1.watermarker,
}
stage_3 = DiffusionPipeline.from_pretrained(
"stabilityai/stable-diffusion-x4-upscaler", **safety_modules, dtype=torch.float16
)
stage_3.enable_model_cpu_offload()
prompt = "A fantasy landscape in style minecraft"
generator = torch.manual_seed(1)
# text embeds
prompt_embeds, negative_embeds = stage_1.encode_prompt(prompt)
# stage 1
stage_1_output = stage_1(
image=original_image,
prompt_embeds=prompt_embeds,
negative_prompt_embeds=negative_embeds,
generator=generator,
output_type="pt",
).images
#pt_to_pil(stage_1_output)[0].save("./if_stage_I.png")
# stage 2
stage_2_output = stage_2(
image=stage_1_output,
original_image=original_image,
prompt_embeds=prompt_embeds,
negative_prompt_embeds=negative_embeds,
generator=generator,
output_type="pt",
).images
#pt_to_pil(stage_2_output)[0].save("./if_stage_II.png")
# stage 3
stage_3_output = stage_3(prompt=prompt, image=stage_2_output, generator=generator, noise_level=100).images
#stage_3_output[0].save("./if_stage_III.png")
make_image_grid([original_image, pt_to_pil(stage_1_output)[0], pt_to_pil(stage_2_output)[0], stage_3_output[0]], rows=1, rows=4)
```
### توليد إعادة التلوين الموجّه بالنص
يمكن استخدام أوزان نموذج IF نفسها لتحويل الصور من صورة إلى صورة بإرشاد نصي أو لتوليد تنويعات للصور. في هذه الحالة، تأكد فقط من تحميل الأوزان باستخدام خططي العمل [IFInpaintingPipeline](/docs/diffusers/main/ar/api/pipelines/deepfloyd_if#diffusers.IFInpaintingPipeline) و[IFInpaintingSuperResolutionPipeline](/docs/diffusers/main/ar/api/pipelines/deepfloyd_if#diffusers.IFInpaintingSuperResolutionPipeline).
**ملاحظة**: يمكنك أيضًا نقل أوزان خطوط أنابيب النص إلى الصورة مباشرةً إلى خطوط أنابيب الصورة إلى الصورة دون تحميلها مرتين من خلال استخدام دالة `~DiffusionPipeline.components()` كما هو موضح [هنا](#converting-between-different-pipelines).
```python
from diffusers import IFInpaintingPipeline, IFInpaintingSuperResolutionPipeline, DiffusionPipeline
from diffusers.utils import pt_to_pil, load_image, make_image_grid
import torch
# download image
url = "https://huggingface.co/datasets/diffusers/docs-images/resolve/main/if/person.png"
original_image = load_image(url)
# download mask
url = "https://huggingface.co/datasets/diffusers/docs-images/resolve/main/if/glasses_mask.png"
mask_image = load_image(url)
# stage 1
stage_1 = IFInpaintingPipeline.from_pretrained("DeepFloyd/IF-I-XL-v1.0", variant="fp16", dtype=torch.float16)
stage_1.enable_model_cpu_offload()
# stage 2
stage_2 = IFInpaintingSuperResolutionPipeline.from_pretrained(
"DeepFloyd/IF-II-L-v1.0", text_encoder=None, variant="fp16", dtype=torch.float16
)
stage_2.enable_model_cpu_offload()
# stage 3
safety_modules = {
"feature_extractor": stage_1.feature_extractor,
"safety_checker": stage_1.safety_checker,
"watermarker": stage_1.watermarker,
}
stage_3 = DiffusionPipeline.from_pretrained(
"stabilityai/stable-diffusion-x4-upscaler", **safety_modules, dtype=torch.float16
)
stage_3.enable_model_cpu_offload()
prompt = "blue sunglasses"
generator = torch.manual_seed(1)
# text embeds
prompt_embeds, negative_embeds = stage_1.encode_prompt(prompt)
# stage 1
stage_1_output = stage_1(
image=original_image,
mask_image=mask_image,
prompt_embeds=prompt_embeds,
negative_prompt_embeds=negative_embeds,
generator=generator,
output_type="pt",
).images
#pt_to_pil(stage_1_output)[0].save("./if_stage_I.png")
# stage 2
stage_2_output = stage_2(
image=stage_1_output,
original_image=original_image,
mask_image=mask_image,
prompt_embeds=prompt_embeds,
negative_prompt_embeds=negative_embeds,
generator=generator,
output_type="pt",
).images
#pt_to_pil(stage_1_output)[0].save("./if_stage_II.png")
# stage 3
stage_3_output = stage_3(prompt=prompt, image=stage_2_output, generator=generator, noise_level=100).images
#stage_3_output[0].save("./if_stage_III.png")
make_image_grid([original_image, mask_image, pt_to_pil(stage_1_output)[0], pt_to_pil(stage_2_output)[0], stage_3_output[0]], rows=1, rows=5)
```
### التحويل بين خطوط أنابيب مختلفة
بالإضافة إلى التحميل عبر `from_pretrained`، يمكن تحميل خطوط الأنابيب مباشرةً من بعضها البعض.
```python
from diffusers import IFPipeline, IFSuperResolutionPipeline
pipe_1 = IFPipeline.from_pretrained("DeepFloyd/IF-I-XL-v1.0")
pipe_2 = IFSuperResolutionPipeline.from_pretrained("DeepFloyd/IF-II-L-v1.0")
from diffusers import IFImg2ImgPipeline, IFImg2ImgSuperResolutionPipeline
pipe_1 = IFImg2ImgPipeline(**pipe_1.components)
pipe_2 = IFImg2ImgSuperResolutionPipeline(**pipe_2.components)
from diffusers import IFInpaintingPipeline, IFInpaintingSuperResolutionPipeline
pipe_1 = IFInpaintingPipeline(**pipe_1.components)
pipe_2 = IFInpaintingSuperResolutionPipeline(**pipe_2.components)
```
### تحسين الأداء من حيث السرعة
أبسط تحسين لتشغيل IF بشكل أسرع هو نقل جميع مكوّنات النموذج إلى وحدة معالجة الرسوميات (GPU).
```py
pipe = DiffusionPipeline.from_pretrained("DeepFloyd/IF-I-XL-v1.0", variant="fp16", dtype=torch.float16)
pipe.to("cuda") # or "mps", "xpu", "cpu"
```
يمكنك أيضًا تشغيل عملية الانتشار لعدد أقصر من خطوات الزمن.
يمكن القيام بذلك إما باستخدام معامل `num_inference_steps`:
```py
pipe("<prompt>", num_inference_steps=30)
```
أو باستخدام معامل `timesteps`:
```py
from diffusers.pipelines.deepfloyd_if import fast27_timesteps
pipe("<prompt>", timesteps=fast27_timesteps)
```
عند تنفيذ تنويع الصور أو إعادة رسمها (Inpainting)، يمكنك أيضًا تقليل عدد خطوات الزمن (Timesteps) باستخدام معامل القوة (Strength). يمثل معامل القوة كمية الضوضاء المضافة إلى الصورة المدخلة، وهو يحدد أيضًا عدد الخطوات التي سيتم تنفيذها في عملية إزالة الضوضاء. يؤدي استخدام رقم أصغر إلى تقليل درجة تنويع الصورة مع تسريع عملية التنفيذ.
```py
pipe = IFImg2ImgPipeline.from_pretrained("DeepFloyd/IF-I-XL-v1.0", variant="fp16", dtype=torch.float16)
pipe.to("cuda") # or "mps", "xpu", "cpu"
image = pipe(image=image, prompt="<prompt>", strength=0.3).images
```
يمكنك أيضًا استخدام [`torch.compile`](../../optimization/fp16#torchcompile). لاحظ أننا لم نختبر `torch.compile` بشكل شامل مع IF وقد لا يعطي النتائج المتوقعة.
```py
from diffusers import DiffusionPipeline
import torch
pipe = DiffusionPipeline.from_pretrained("DeepFloyd/IF-I-XL-v1.0", variant="fp16", dtype=torch.float16)
pipe.to("cuda") # or "mps", "xpu", "cpu"
pipe.text_encoder = torch.compile(pipe.text_encoder, mode="reduce-overhead", fullgraph=True)
pipe.unet = torch.compile(pipe.unet, mode="reduce-overhead", fullgraph=True)
```
### تحسين الأداء من حيث الذاكرة
عند تحسين الذاكرة الخاصة بوحدة معالجة الرسوميات (GPU)، يمكننا استخدام واجهات برمجة التطبيقات (APIs) القياسية الخاصة بإزاحة المعالجة إلى وحدة المعالجة المركزية (CPU) في مكتبة diffusers.
إما إزاحة المعالج المركزي (CPU) بناءً على النموذج،
```py
pipe = DiffusionPipeline.from_pretrained("DeepFloyd/IF-I-XL-v1.0", variant="fp16", dtype=torch.float16)
pipe.enable_model_cpu_offload()
```
أو الإزاحة إلى وحدة المعالجة المركزية (CPU) على مستوى الطبقات الأكثر عدوانية.
```py
pipe = DiffusionPipeline.from_pretrained("DeepFloyd/IF-I-XL-v1.0", variant="fp16", dtype=torch.float16)
pipe.enable_sequential_cpu_offload()
```
بالإضافة إلى ذلك، يمكن تحميل T5 بدقة 8 بت
```py
from transformers import T5EncoderModel
text_encoder = T5EncoderModel.from_pretrained(
"DeepFloyd/IF-I-XL-v1.0", subfolder="text_encoder", device_map="auto", load_in_8bit=True, variant="8bit"
)
from diffusers import DiffusionPipeline
pipe = DiffusionPipeline.from_pretrained(
"DeepFloyd/IF-I-XL-v1.0",
text_encoder=text_encoder, # pass the previously instantiated 8bit text encoder
unet=None,
device_map="auto",
)
prompt_embeds, negative_embeds = pipe.encode_prompt("<prompt>")
```
في الأجهزة ذات الذاكرة العشوائية المعالِج (CPU RAM) المحدودة، مثل الطبقة المجانية من Google Colab حيث لا يمكننا تحميل جميع مكوّنات النموذج إلى الذاكرة العشوائية المعالِج دفعة واحدة، يمكننا يدويًا تحميل خط الأنابيب (pipeline) بمكوّن مُشفّر النص (text encoder) أو UNet فقط عند الحاجة إلى مكوّنات النموذج المقابلة.
```py
from diffusers import IFPipeline, IFSuperResolutionPipeline
import torch
import gc
from transformers import T5EncoderModel
from diffusers.utils import pt_to_pil, make_image_grid
text_encoder = T5EncoderModel.from_pretrained(
"DeepFloyd/IF-I-XL-v1.0", subfolder="text_encoder", device_map="auto", load_in_8bit=True, variant="8bit"
)
# text to image
pipe = DiffusionPipeline.from_pretrained(
"DeepFloyd/IF-I-XL-v1.0",
text_encoder=text_encoder, # pass the previously instantiated 8bit text encoder
unet=None,
device_map="auto",
)
prompt = 'a photo of a kangaroo wearing an orange hoodie and blue sunglasses standing in front of the eiffel tower holding a sign that says "very deep learning"'
prompt_embeds, negative_embeds = pipe.encode_prompt(prompt)
# Remove the pipeline so we can re-load the pipeline with the unet
del text_encoder
del pipe
gc.collect()
torch.cuda.empty_cache()
pipe = IFPipeline.from_pretrained(
"DeepFloyd/IF-I-XL-v1.0", text_encoder=None, variant="fp16", dtype=torch.float16, device_map="auto"
)
generator = torch.Generator().manual_seed(0)
stage_1_output = pipe(
prompt_embeds=prompt_embeds,
negative_prompt_embeds=negative_embeds,
output_type="pt",
generator=generator,
).images
#pt_to_pil(stage_1_output)[0].save("./if_stage_I.png")
# Remove the pipeline so we can load the super-resolution pipeline
del pipe
gc.collect()
torch.cuda.empty_cache()
# First super resolution
pipe = IFSuperResolutionPipeline.from_pretrained(
"DeepFloyd/IF-II-L-v1.0", text_encoder=None, variant="fp16", dtype=torch.float16, device_map="auto"
)
generator = torch.Generator().manual_seed(0)
stage_2_output = pipe(
image=stage_1_output,
prompt_embeds=prompt_embeds,
negative_prompt_embeds=negative_embeds,
output_type="pt",
generator=generator,
).images
#pt_to_pil(stage_2_output)[0].save("./if_stage_II.png")
make_image_grid([pt_to_pil(stage_1_output)[0], pt_to_pil(stage_2_output)[0]], rows=1, rows=2)
```
## الخطوط الأنابيب المتاحة:
| خط الأنابيب | المهام | Colab
|---|---|:---:|
| [pipeline_if.py](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/deepfloyd_if/pipeline_if.py) | *توليد الصور من النص* | - |
| [pipeline_if_superresolution.py](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.py) | *توليد الصور من النص* | - |
| [pipeline_if_img2img.py](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.py) | *توليد الصور من الصور* | - |
| [pipeline_if_img2img_superresolution.py](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/deepfloyd_if/pipeline_if_img2img_superresolution.py) | *توليد الصور من الصور* | - |
| [pipeline_if_inpainting.py](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/deepfloyd_if/pipeline_if_inpainting.py) | *توليد الصور من الصور* | - |
| [pipeline_if_inpainting_superresolution.py](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/deepfloyd_if/pipeline_if_inpainting_superresolution.py) | *توليد الصور من الصور* | - |
## IFPipeline[[diffusers.IFPipeline]]
#### diffusers.IFPipeline[[diffusers.IFPipeline]]
```python
diffusers.IFPipeline(tokenizer: T5Tokenizer, text_encoder: T5EncoderModel, unet: UNet2DConditionModel, scheduler: DDPMScheduler, safety_checker: diffusers.pipelines.deepfloyd_if.safety_checker.IFSafetyChecker | None, feature_extractor: transformers.models.clip.image_processing_pil_clip.CLIPImageProcessorPil | None, watermarker: diffusers.pipelines.deepfloyd_if.watermark.IFWatermarker | None, requires_safety_checker: bool = True)
```
[المصدر](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/deepfloyd_if/pipeline_if.py#L96)
#### __call__[[diffusers.IFPipeline.__call__]]
```python
__call__(prompt: str | list[str] = None, num_inference_steps: int = 100, timesteps: list[int] = None, guidance_scale: float = 7.0, negative_prompt: str | list[str] | None = None, num_images_per_prompt: int | None = 1, height: int | None = None, width: int | None = None, eta: float = 0.0, generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = None, prompt_embeds: typing.Optional[torch.Tensor] = None, negative_prompt_embeds: typing.Optional[torch.Tensor] = None, output_type: str | None = 'pil', return_dict: bool = True, callback: typing.Optional[typing.Callable[[int, int, torch.Tensor], NoneType]] = None, callback_steps: int = 1, clean_caption: bool = True, cross_attention_kwargs: dict[str, typing.Any] | None = None)
```
[المصدر](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/deepfloyd_if/pipeline_if.py#L547)
**المعاملات:**
prompt (`str` أو `list[str]`، *اختياري*) : الأمر أو الأوامر التي تُوجّه توليد الصورة. إذا لم يُعرَّف، يجب تمرير `prompt_embeds` بدلاً من ذلك.
num_inference_steps (`int`، *اختياري*، القيمة الافتراضية 100) : عدد خطوات إزالة الضوضاء. تؤدي زيادة عدد خطوات إزالة الضوضاء عادةً إلى صورة ذات جودة أعلى على حساب بطء الاستدلال.
timesteps (`list[int]`، *اختياري*) : خطوات زمنية مخصصة لاستخدامها في عملية إزالة الضوضاء. إذا لم تُعرَّف، تُستخدم خطوات زمنية متساوية التباعد بعدد `num_inference_steps`. يجب أن تكون مرتبة تنازليًا.
guidance_scale (`float`، *اختياري*، القيمة الافتراضية 7.0) : مقياس التوجيه كما هو مُعرَّف في [Classifier-Free Diffusion Guidance](https://huggingface.co/papers/2207.12598). يُعرَّف `guidance_scale` على أنه `w` من المعادلة 2. في [Imagen Paper](https://huggingface.co/papers/2205.11487). يتم تفعيل مقياس التوجيه عن طريق تعيين `guidance_scale > 1`. يشجع مقياس التوجيه الأعلى على توليد صور مرتبطة ارتباطًا وثيقًا بنص `prompt`، وعادةً على حساب انخفاض جودة الصورة.
negative_prompt (`str` أو `list[str]`، *اختياري*) : الموجه أو الموجهات التي لا ينبغي توجيه توليد الصورة بها. إذا لم يُعرَّف، يجب تمرير `negative_prompt_embeds` بدلاً من ذلك. يتم تجاهله عند عدم استخدام التوجيه (أي يتم تجاهله إذا كان `guidance_scale` أقل من `1`).
num_images_per_prompt (`int`، *اختياري*، القيمة الافتراضية 1) : عدد الصور التي سيتم توليدها لكل موجه.
height (`int`، *اختياري*، الافتراضي هو self.unet.config.sample_size) : ارتفاع الصورة المولّدة بالبكسل.
width (`int`، *اختياري*، الافتراضي هو self.unet.config.sample_size) : عرض الصورة المولدة بالبكسل.
eta (`float`، *اختياري*، القيمة الافتراضية 0.0) : يتوافق مع المعامل eta (η) في ورقة DDIM: https://huggingface.co/papers/2010.02502. ينطبق فقط على [schedulers.DDIMScheduler](/docs/diffusers/main/ar/api/schedulers/ddim#diffusers.DDIMScheduler)، وسيتم تجاهله في الحالات الأخرى.
generator (`torch.Generator` أو `list[torch.Generator]`، *اختياري*) : مولّد واحد أو قائمة من [مولّدات torch](https://pytorch.org/docs/stable/generated/torch.Generator.html) لجعل التوليد حتميًا.
prompt_embeds (`torch.Tensor`، *اختياري*) : تمثيلات نصية مُولّدة مسبقًا. يمكن استخدامها لتعديل مدخلات النص بسهولة، *مثلًا* وزن الأوامر. إذا لم تُقدَّم، فسيتم توليد تمثيلات النص من معامل الإدخال `prompt`.
negative_prompt_embeds (`torch.Tensor`, *اختياري*) : تمثيلات نصية سالبة مُولّدة مسبقًا. يمكن استخدامها لتعديل مدخلات النص بسهولة، *مثلًا* وزن الأوامر. إذا لم تُقدَّم، فسيتم توليد negative_prompt_embeds من معامل الإدخال `negative_prompt`.
output_type (`str`، *اختياري*، القيمة الافتراضية `"pil"`) : صيغة الصورة الناتجة عن عملية التوليد. اختر بين [PIL](https://pillow.readthedocs.io/en/stable/): `PIL.Image.Image` أو `np.array`.
return_dict (`bool`، *اختياري*، القيمة الافتراضية `True`) : ما إذا كان يجب إرجاع `~pipelines.stable_diffusion.IFPipelineOutput` بدلاً من tuple عادي.
callback (`Callable`، *اختياري*) : دالة ستُستدعى كل `callback_steps` خطوات أثناء الاستدلال. سيتم استدعاء الدالة مع الحُجج التالية: `callback(step: int, timestep: int, latents: torch.Tensor)`.
callback_steps (`int`، *اختياري*، القيمة الافتراضية 1) : التكرار الذي تُستدعى فيه دالة `callback`. إذا لم يتم تحديده، فستُستدعى الدالة في كل خطوة.
clean_caption (`bool`، *اختياري*، القيمة الافتراضية `True`) : ما إذا كان سيتم تنظيف الوصف قبل إنشاء التضمينات. يتطلب تثبيت `beautifulsoup4` و`ftfy`. إذا لم يتم تثبيت الاعتماديات، فسيتم إنشاء التضمينات من النص الخام.
cross_attention_kwargs (`dict`، *اختياري*) : قاموس kwargs يُمرَّر إلى `AttentionProcessor` إذا تم تحديده، كما هو معرَّف تحت `self.processor` في [diffusers.models.attention_processor](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/attention_processor.py).
**يعيد:** `~pipelines.stable_diffusion.IFPipelineOutput` أو `tuple`
`~pipelines.stable_diffusion.IFPipelineOutput` if `return_dict` is True, otherwise a `tuple. When returning a tuple, the first element is a list with the generated images, and the second element is a list of `bool`s denoting whether the corresponding generated image likely represents "not-safe-for-work" (nsfw) or watermarked content, according to the `safety_checker`.
الدالة التي تُستدعى عند استدعاء خط الأنابيب للتوليد.
أمثلة:
```py
>>> from diffusers import IFPipeline, IFSuperResolutionPipeline, DiffusionPipeline
>>> from diffusers.utils import pt_to_pil
>>> import torch
>>> pipe = IFPipeline.from_pretrained("DeepFloyd/IF-I-XL-v1.0", variant="fp16", torch_dtype=torch.float16)
>>> pipe.enable_model_cpu_offload()
>>> prompt = 'a photo of a kangaroo wearing an orange hoodie and blue sunglasses standing in front of the eiffel tower holding a sign that says "very deep learning"'
>>> prompt_embeds, negative_embeds = pipe.encode_prompt(prompt)
>>> image = pipe(prompt_embeds=prompt_embeds, negative_prompt_embeds=negative_embeds, output_type="pt").images
>>> # save intermediate image
>>> pil_image = pt_to_pil(image)
>>> pil_image[0].save("./if_stage_I.png")
>>> super_res_1_pipe = IFSuperResolutionPipeline.from_pretrained(
... "DeepFloyd/IF-II-L-v1.0", text_encoder=None, variant="fp16", torch_dtype=torch.float16
... )
>>> super_res_1_pipe.enable_model_cpu_offload()
>>> image = super_res_1_pipe(
... image=image, prompt_embeds=prompt_embeds, negative_prompt_embeds=negative_embeds, output_type="pt"
... ).images
>>> # save intermediate image
>>> pil_image = pt_to_pil(image)
>>> pil_image[0].save("./if_stage_I.png")
>>> safety_modules = {
... "feature_extractor": pipe.feature_extractor,
... "safety_checker": pipe.safety_checker,
... "watermarker": pipe.watermarker,
... }
>>> super_res_2_pipe = DiffusionPipeline.from_pretrained(
... "stabilityai/stable-diffusion-x4-upscaler", **safety_modules, torch_dtype=torch.float16
... )
>>> super_res_2_pipe.enable_model_cpu_offload()
>>> image = super_res_2_pipe(
... prompt=prompt,
... image=image,
... ).images
>>> image[0].save("./if_stage_II.png")
```
#### encode_prompt[[diffusers.IFPipeline.encode_prompt]]
```python
encode_prompt(prompt: str | list[str], do_classifier_free_guidance: bool = True, num_images_per_prompt: int = 1, device: typing.Optional[torch.device] = None, negative_prompt: str | list[str] | None = None, prompt_embeds: typing.Optional[torch.Tensor] = None, negative_prompt_embeds: typing.Optional[torch.Tensor] = None, clean_caption: bool = False)
```
[المصدر](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/deepfloyd_if/pipeline_if.py#L168)
**المعاملات:**
prompt (`str` أو `list[str]`، *اختياري*) : النص الذي سيتم ترميزه
do_classifier_free_guidance (`bool`، *اختياري*، القيمة الافتراضية `True`) : ما إذا كان سيتم استخدام classifier free guidance أم لا
num_images_per_prompt (`int`، *اختياري*، القيمة الافتراضية 1) : عدد الصور التي يجب توليدها لكل موجه
device : (`torch.device`, *اختياري*): جهاز torch لوضع التضمينات الناتجة عليه
negative_prompt (`str` أو `list[str]`، *اختياري*) : الموجه أو الموجهات التي لا ينبغي توجيه توليد الصورة بها. إذا لم يُعرَّف، يجب تمرير `negative_prompt_embeds` بدلاً من ذلك. إذا لم يُعرَّف، يجب تمرير `negative_prompt_embeds` بدلاً من ذلك. يتم تجاهله عند عدم استخدام التوجيه (أي يتم تجاهله إذا كان `guidance_scale` أقل من `1`).
prompt_embeds (`torch.Tensor`، *اختياري*) : تمثيلات نصية مُولّدة مسبقًا. يمكن استخدامها لتعديل مدخلات النص بسهولة، *مثلًا* وزن الأوامر. إذا لم تُقدَّم، فسيتم توليد تمثيلات النص من معامل الإدخال `prompt`.
negative_prompt_embeds (`torch.Tensor`, *اختياري*) : تمثيلات نصية سالبة مُولّدة مسبقًا. يمكن استخدامها لتعديل مدخلات النص بسهولة، *مثلًا* وزن الأوامر. إذا لم تُقدَّم، فسيتم توليد negative_prompt_embeds من معامل الإدخال `negative_prompt`.
clean_caption (bool، القيمة الافتراضية `False`) : إذا كانت `True`، سيقوم الدالة بمعالجة الوصف المقدم وتنظيفه قبل الترميز.
يقوم بتشفير الموجه إلى حالات مخفية لمشفّر النص.
## IFSuperResolutionPipeline[[diffusers.IFSuperResolutionPipeline]]
#### diffusers.IFSuperResolutionPipeline[[diffusers.IFSuperResolutionPipeline]]
```python
diffusers.IFSuperResolutionPipeline(tokenizer: T5Tokenizer, text_encoder: T5EncoderModel, unet: UNet2DConditionModel, scheduler: DDPMScheduler, image_noising_scheduler: DDPMScheduler, safety_checker: diffusers.pipelines.deepfloyd_if.safety_checker.IFSafetyChecker | None, feature_extractor: transformers.models.clip.image_processing_pil_clip.CLIPImageProcessorPil | None, watermarker: diffusers.pipelines.deepfloyd_if.watermark.IFWatermarker | None, requires_safety_checker: bool = True)
```
[المصدر](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.py#L82)
#### __call__[[diffusers.IFSuperResolutionPipeline.__call__]]
```python
__call__(prompt: str | list[str] = None, height: int = None, width: int = None, image: typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor] = None, num_inference_steps: int = 50, timesteps: list[int] = None, guidance_scale: float = 4.0, negative_prompt: str | list[str] | None = None, num_images_per_prompt: int | None = 1, eta: float = 0.0, generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = None, prompt_embeds: typing.Optional[torch.Tensor] = None, negative_prompt_embeds: typing.Optional[torch.Tensor] = None, output_type: str | None = 'pil', return_dict: bool = True, callback: typing.Optional[typing.Callable[[int, int, torch.Tensor], NoneType]] = None, callback_steps: int = 1, cross_attention_kwargs: dict[str, typing.Any] | None = None, noise_level: int = 250, clean_caption: bool = True)
```
[المصدر](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.py#L614)
**المعاملات:**
prompt (`str` أو `list[str]`، *اختياري*) : الأمر أو الأوامر التي تُوجّه توليد الصورة. إذا لم يُعرَّف، يجب تمرير `prompt_embeds` بدلاً من ذلك.
height (`int`، *اختياري*، القيمة الافتراضية هي None) : ارتفاع الصورة المولّدة بالبكسل.
width (`int`، *اختياري*، القيمة الافتراضية هي None) : عرض الصورة المولدة بالبكسل.
image (`PIL.Image.Image`، `np.ndarray`، `torch.Tensor`) : الصورة التي سيتم تكبيرها.
num_inference_steps (`int`، *اختياري*، القيمة الافتراضية 50) : عدد خطوات إزالة الضوضاء. تؤدي زيادة عدد خطوات إزالة الضوضاء عادةً إلى صورة ذات جودة أعلى على حساب بطء الاستدلال.
timesteps (`list[int]`، *اختياري*، القيمة الافتراضية هي None) : خطوات زمنية مخصصة لاستخدامها في عملية إزالة الضوضاء. إذا لم تُعرَّف، تُستخدم خطوات زمنية متساوية التباعد لعدد `num_inference_steps`. يجب أن تكون مرتبة تنازليًا.
guidance_scale (`float`، *اختياري*، القيمة الافتراضية 4.0) : مقياس التوجيه كما هو مُعرَّف في [Classifier-Free Diffusion Guidance](https://huggingface.co/papers/2207.12598). يُعرَّف `guidance_scale` على أنه `w` من المعادلة 2. في [Imagen Paper](https://huggingface.co/papers/2205.11487). يتم تفعيل مقياس التوجيه عن طريق تعيين `guidance_scale > 1`. يشجع مقياس التوجيه الأعلى على توليد صور مرتبطة ارتباطًا وثيقًا بنص `prompt`، وعادةً على حساب انخفاض جودة الصورة.
negative_prompt (`str` أو `list[str]`، *اختياري*) : الموجه أو الموجهات التي لا ينبغي توجيه توليد الصورة بها. إذا لم يُعرَّف، يجب تمرير `negative_prompt_embeds` بدلاً من ذلك. يتم تجاهله عند عدم استخدام التوجيه (أي يتم تجاهله إذا كان `guidance_scale` أقل من `1`).
num_images_per_prompt (`int`، *اختياري*، القيمة الافتراضية 1) : عدد الصور التي سيتم توليدها لكل موجه.
eta (`float`، *اختياري*، القيمة الافتراضية 0.0) : يتوافق مع المعامل eta (η) في ورقة DDIM: https://huggingface.co/papers/2010.02502. ينطبق فقط على [schedulers.DDIMScheduler](/docs/diffusers/main/ar/api/schedulers/ddim#diffusers.DDIMScheduler)، وسيتم تجاهله في الحالات الأخرى.
generator (`torch.Generator` أو `list[torch.Generator]`، *اختياري*) : مولّد واحد أو قائمة من [مولّدات torch](https://pytorch.org/docs/stable/generated/torch.Generator.html) لجعل التوليد حتميًا.
prompt_embeds (`torch.Tensor`، *اختياري*) : تمثيلات نصية مُولّدة مسبقًا. يمكن استخدامها لتعديل مدخلات النص بسهولة، *مثلًا* وزن الأوامر. إذا لم تُقدَّم، فسيتم توليد تمثيلات النص من معامل الإدخال `prompt`.
negative_prompt_embeds (`torch.Tensor`, *اختياري*) : تمثيلات نصية سالبة مُولّدة مسبقًا. يمكن استخدامها لتعديل مدخلات النص بسهولة، *مثلًا* وزن الأوامر. إذا لم تُقدَّم، فسيتم توليد negative_prompt_embeds من معامل الإدخال `negative_prompt`.
output_type (`str`، *اختياري*، القيمة الافتراضية `"pil"`) : صيغة الصورة الناتجة عن عملية التوليد. اختر بين [PIL](https://pillow.readthedocs.io/en/stable/): `PIL.Image.Image` أو `np.array`.
return_dict (`bool`، *اختياري*، القيمة الافتراضية `True`) : ما إذا كان يجب إرجاع `~pipelines.stable_diffusion.IFPipelineOutput` بدلاً من tuple عادي.
callback (`Callable`، *اختياري*) : دالة ستُستدعى كل `callback_steps` خطوات أثناء الاستدلال. سيتم استدعاء الدالة مع الحُجج التالية: `callback(step: int, timestep: int, latents: torch.Tensor)`.
callback_steps (`int`، *اختياري*، القيمة الافتراضية 1) : التكرار الذي تُستدعى فيه دالة `callback`. إذا لم يتم تحديده، فستُستدعى الدالة في كل خطوة.
cross_attention_kwargs (`dict`، *اختياري*) : قاموس kwargs يُمرَّر إلى `AttentionProcessor` إذا تم تحديده، كما هو معرَّف تحت `self.processor` في [diffusers.models.attention_processor](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/attention_processor.py).
noise_level (`int`، *اختياري*، القيمة الافتراضية 250) : كمية الضوضاء التي تُضاف إلى الصورة المُكبَّرة. يجب أن تكون ضمن المدى `[0, 1000)`
clean_caption (`bool`، *اختياري*، القيمة الافتراضية `True`) : ما إذا كان سيتم تنظيف الوصف قبل إنشاء التضمينات. يتطلب تثبيت `beautifulsoup4` و`ftfy`. إذا لم يتم تثبيت الاعتماديات، فسيتم إنشاء التضمينات من النص الخام.
**يعيد:** `~pipelines.stable_diffusion.IFPipelineOutput` أو `tuple`
`~pipelines.stable_diffusion.IFPipelineOutput` if `return_dict` is True, otherwise a `tuple. When returning a tuple, the first element is a list with the generated images, and the second element is a list of `bool`s denoting whether the corresponding generated image likely represents "not-safe-for-work" (nsfw) or watermarked content, according to the `safety_checker`.
الدالة التي تُستدعى عند استدعاء خط الأنابيب للتوليد.
أمثلة:
```py
>>> from diffusers import IFPipeline, IFSuperResolutionPipeline, DiffusionPipeline
>>> from diffusers.utils import pt_to_pil
>>> import torch
>>> pipe = IFPipeline.from_pretrained("DeepFloyd/IF-I-XL-v1.0", variant="fp16", torch_dtype=torch.float16)
>>> pipe.enable_model_cpu_offload()
>>> prompt = 'a photo of a kangaroo wearing an orange hoodie and blue sunglasses standing in front of the eiffel tower holding a sign that says "very deep learning"'
>>> prompt_embeds, negative_embeds = pipe.encode_prompt(prompt)
>>> image = pipe(prompt_embeds=prompt_embeds, negative_prompt_embeds=negative_embeds, output_type="pt").images
>>> # save intermediate image
>>> pil_image = pt_to_pil(image)
>>> pil_image[0].save("./if_stage_I.png")
>>> super_res_1_pipe = IFSuperResolutionPipeline.from_pretrained(
... "DeepFloyd/IF-II-L-v1.0", text_encoder=None, variant="fp16", torch_dtype=torch.float16
... )
>>> super_res_1_pipe.enable_model_cpu_offload()
>>> image = super_res_1_pipe(
... image=image, prompt_embeds=prompt_embeds, negative_prompt_embeds=negative_embeds
... ).images
>>> image[0].save("./if_stage_II.png")
```
#### encode_prompt[[diffusers.IFSuperResolutionPipeline.encode_prompt]]
```python
encode_prompt(prompt: str | list[str], do_classifier_free_guidance: bool = True, num_images_per_prompt: int = 1, device: typing.Optional[torch.device] = None, negative_prompt: str | list[str] | None = None, prompt_embeds: typing.Optional[torch.Tensor] = None, negative_prompt_embeds: typing.Optional[torch.Tensor] = None, clean_caption: bool = False)
```
[المصدر](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.py#L302)
**المعاملات:**
prompt (`str` أو `list[str]`، *اختياري*) : النص الذي سيتم ترميزه
do_classifier_free_guidance (`bool`، *اختياري*، القيمة الافتراضية `True`) : ما إذا كان سيتم استخدام classifier free guidance أم لا
num_images_per_prompt (`int`، *اختياري*، القيمة الافتراضية 1) : عدد الصور التي يجب توليدها لكل موجه
device : (`torch.device`, *اختياري*): جهاز torch لوضع التضمينات الناتجة عليه
negative_prompt (`str` أو `list[str]`، *اختياري*) : الموجه أو الموجهات التي لا ينبغي توجيه توليد الصورة بها. إذا لم يُعرَّف، يجب تمرير `negative_prompt_embeds` بدلاً من ذلك. إذا لم يُعرَّف، يجب تمرير `negative_prompt_embeds` بدلاً من ذلك. يتم تجاهله عند عدم استخدام التوجيه (أي يتم تجاهله إذا كان `guidance_scale` أقل من `1`).
prompt_embeds (`torch.Tensor`، *اختياري*) : تمثيلات نصية مُولّدة مسبقًا. يمكن استخدامها لتعديل مدخلات النص بسهولة، *مثلًا* وزن الأوامر. إذا لم تُقدَّم، فسيتم توليد تمثيلات النص من معامل الإدخال `prompt`.
negative_prompt_embeds (`torch.Tensor`, *اختياري*) : تمثيلات نصية سالبة مُولّدة مسبقًا. يمكن استخدامها لتعديل مدخلات النص بسهولة، *مثلًا* وزن الأوامر. إذا لم تُقدَّم، فسيتم توليد negative_prompt_embeds من معامل الإدخال `negative_prompt`.
clean_caption (bool، القيمة الافتراضية `False`) : إذا كانت `True`، سيقوم الدالة بمعالجة الوصف المقدم وتنظيفه قبل الترميز.
يقوم بتشفير الموجه إلى حالات مخفية لمشفّر النص.
## IFImg2ImgPipeline[[diffusers.IFImg2ImgPipeline]]
#### diffusers.IFImg2ImgPipeline[[diffusers.IFImg2ImgPipeline]]
```python
diffusers.IFImg2ImgPipeline(tokenizer: T5Tokenizer, text_encoder: T5EncoderModel, unet: UNet2DConditionModel, scheduler: DDPMScheduler, safety_checker: diffusers.pipelines.deepfloyd_if.safety_checker.IFSafetyChecker | None, feature_extractor: transformers.models.clip.image_processing_pil_clip.CLIPImageProcessorPil | None, watermarker: diffusers.pipelines.deepfloyd_if.watermark.IFWatermarker | None, requires_safety_checker: bool = True)
```
[المصدر](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.py#L120)
#### __call__[[diffusers.IFImg2ImgPipeline.__call__]]
```python
__call__(prompt: str | list[str] = None, image: typing.Union[PIL.Image.Image, torch.Tensor, numpy.ndarray, list[PIL.Image.Image], list[torch.Tensor], list[numpy.ndarray]] = None, strength: float = 0.7, num_inference_steps: int = 80, timesteps: list[int] = None, guidance_scale: float = 10.0, negative_prompt: str | list[str] | None = None, num_images_per_prompt: int | None = 1, eta: float = 0.0, generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = None, prompt_embeds: typing.Optional[torch.Tensor] = None, negative_prompt_embeds: typing.Optional[torch.Tensor] = None, output_type: str | None = 'pil', return_dict: bool = True, callback: typing.Optional[typing.Callable[[int, int, torch.Tensor], NoneType]] = None, callback_steps: int = 1, clean_caption: bool = True, cross_attention_kwargs: dict[str, typing.Any] | None = None)
```
[المصدر](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.py#L661)
**المعاملات:**
prompt (`str` أو `list[str]`، *اختياري*) : الأمر أو الأوامر التي تُوجّه توليد الصورة. إذا لم يُعرَّف، يجب تمرير `prompt_embeds` بدلاً من ذلك.
image (`torch.Tensor` أو `PIL.Image.Image`) : `Image`، أو tensor يمثل دفعة من الصور، وسيُستخدم كنقطة انطلاق للعملية.
strength (`float`، *اختياري*، القيمة الافتراضية 0.7) : يُشير مفهومياً إلى مقدار تحويل الصورة المرجعية `image`. يجب أن يكون بين 0 و 1. ستُستخدم `image` كنقطة انطلاق، حيث يُضاف المزيد من الضوضاء إليها كلما زاد `strength`. يعتمد عدد خطوات إزالة الضوضاء على كمية الضوضاء المضافة في البداية. عندما تكون قيمة `strength` هي 1، ستكون الضوضاء المضافة في أقصى حد، وستعمل عملية إزالة الضوضاء لعدد التكرارات الكامل المحدد في `num_inference_steps`. وبالتالي، فإن القيمة 1 تتجاهل `image` بشكل أساسي.
num_inference_steps (`int`، *اختياري*، القيمة الافتراضية 80) : عدد خطوات إزالة الضوضاء. تؤدي زيادة عدد خطوات إزالة الضوضاء عادةً إلى صورة ذات جودة أعلى على حساب بطء الاستدلال.
timesteps (`list[int]`، *اختياري*) : خطوات زمنية مخصصة لاستخدامها في عملية إزالة الضوضاء. إذا لم تُعرَّف، تُستخدم خطوات زمنية متساوية التباعد بعدد `num_inference_steps`. يجب أن تكون مرتبة تنازليًا.
guidance_scale (`float`، *اختياري*، القيمة الافتراضية 10.0) : مقياس التوجيه كما هو مُعرَّف في [Classifier-Free Diffusion Guidance](https://huggingface.co/papers/2207.12598). يُعرَّف `guidance_scale` على أنه `w` من المعادلة 2. في [Imagen Paper](https://huggingface.co/papers/2205.11487). يتم تفعيل مقياس التوجيه عن طريق تعيين `guidance_scale > 1`. يشجع مقياس التوجيه الأعلى على توليد صور مرتبطة ارتباطًا وثيقًا بنص `prompt`، وعادةً على حساب انخفاض جودة الصورة.
negative_prompt (`str` أو `list[str]`، *اختياري*) : الموجه أو الموجهات التي لا ينبغي توجيه توليد الصورة بها. إذا لم يُعرَّف، يجب تمرير `negative_prompt_embeds` بدلاً من ذلك. يتم تجاهله عند عدم استخدام التوجيه (أي يتم تجاهله إذا كان `guidance_scale` أقل من `1`).
num_images_per_prompt (`int`، *اختياري*، القيمة الافتراضية 1) : عدد الصور التي سيتم توليدها لكل موجه.
eta (`float`، *اختياري*، القيمة الافتراضية 0.0) : يتوافق مع المعامل eta (η) في ورقة DDIM: https://huggingface.co/papers/2010.02502. ينطبق فقط على [schedulers.DDIMScheduler](/docs/diffusers/main/ar/api/schedulers/ddim#diffusers.DDIMScheduler)، وسيتم تجاهله في الحالات الأخرى.
generator (`torch.Generator` أو `list[torch.Generator]`، *اختياري*) : مولّد واحد أو قائمة من [مولّدات torch](https://pytorch.org/docs/stable/generated/torch.Generator.html) لجعل التوليد حتميًا.
prompt_embeds (`torch.Tensor`، *اختياري*) : تمثيلات نصية مُولّدة مسبقًا. يمكن استخدامها لتعديل مدخلات النص بسهولة، *مثلًا* وزن الأوامر. إذا لم تُقدَّم، فسيتم توليد تمثيلات النص من معامل الإدخال `prompt`.
negative_prompt_embeds (`torch.Tensor`, *اختياري*) : تمثيلات نصية سالبة مُولّدة مسبقًا. يمكن استخدامها لتعديل مدخلات النص بسهولة، *مثلًا* وزن الأوامر. إذا لم تُقدَّم، فسيتم توليد negative_prompt_embeds من معامل الإدخال `negative_prompt`.
output_type (`str`، *اختياري*، القيمة الافتراضية `"pil"`) : صيغة الصورة الناتجة عن عملية التوليد. اختر بين [PIL](https://pillow.readthedocs.io/en/stable/): `PIL.Image.Image` أو `np.array`.
return_dict (`bool`، *اختياري*، القيمة الافتراضية `True`) : ما إذا كان يجب إرجاع `~pipelines.stable_diffusion.IFPipelineOutput` بدلاً من tuple عادي.
callback (`Callable`، *اختياري*) : دالة ستُستدعى كل `callback_steps` خطوات أثناء الاستدلال. سيتم استدعاء الدالة مع الحُجج التالية: `callback(step: int, timestep: int, latents: torch.Tensor)`.
callback_steps (`int`، *اختياري*، القيمة الافتراضية 1) : التكرار الذي تُستدعى فيه دالة `callback`. إذا لم يتم تحديده، فستُستدعى الدالة في كل خطوة.
clean_caption (`bool`، *اختياري*، القيمة الافتراضية `True`) : ما إذا كان سيتم تنظيف الوصف قبل إنشاء التضمينات. يتطلب تثبيت `beautifulsoup4` و`ftfy`. إذا لم يتم تثبيت الاعتماديات، فسيتم إنشاء التضمينات من النص الخام.
cross_attention_kwargs (`dict`، *اختياري*) : قاموس kwargs يُمرَّر إلى `AttentionProcessor` إذا تم تحديده، كما هو معرَّف تحت `self.processor` في [diffusers.models.attention_processor](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/attention_processor.py).
**يعيد:** `~pipelines.stable_diffusion.IFPipelineOutput` أو `tuple`
`~pipelines.stable_diffusion.IFPipelineOutput` if `return_dict` is True, otherwise a `tuple. When returning a tuple, the first element is a list with the generated images, and the second element is a list of `bool`s denoting whether the corresponding generated image likely represents "not-safe-for-work" (nsfw) or watermarked content, according to the `safety_checker`.
الدالة التي تُستدعى عند استدعاء خط الأنابيب للتوليد.
أمثلة:
```py
>>> from diffusers import IFImg2ImgPipeline, IFImg2ImgSuperResolutionPipeline, DiffusionPipeline
>>> from diffusers.utils import pt_to_pil
>>> import torch
>>> from PIL import Image
>>> import requests
>>> from io import BytesIO
>>> url = "https://raw.githubusercontent.com/CompVis/stable-diffusion/main/assets/stable-samples/img2img/sketch-mountains-input.jpg"
>>> response = requests.get(url)
>>> original_image = Image.open(BytesIO(response.content)).convert("RGB")
>>> original_image = original_image.resize((768, 512))
>>> pipe = IFImg2ImgPipeline.from_pretrained(
... "DeepFloyd/IF-I-XL-v1.0",
... variant="fp16",
... torch_dtype=torch.float16,
... )
>>> pipe.enable_model_cpu_offload()
>>> prompt = "A fantasy landscape in style minecraft"
>>> prompt_embeds, negative_embeds = pipe.encode_prompt(prompt)
>>> image = pipe(
... image=original_image,
... prompt_embeds=prompt_embeds,
... negative_prompt_embeds=negative_embeds,
... output_type="pt",
... ).images
>>> # save intermediate image
>>> pil_image = pt_to_pil(image)
>>> pil_image[0].save("./if_stage_I.png")
>>> super_res_1_pipe = IFImg2ImgSuperResolutionPipeline.from_pretrained(
... "DeepFloyd/IF-II-L-v1.0",
... text_encoder=None,
... variant="fp16",
... torch_dtype=torch.float16,
... )
>>> super_res_1_pipe.enable_model_cpu_offload()
>>> image = super_res_1_pipe(
... image=image,
... original_image=original_image,
... prompt_embeds=prompt_embeds,
... negative_prompt_embeds=negative_embeds,
... ).images
>>> image[0].save("./if_stage_II.png")
```
#### encode_prompt[[diffusers.IFImg2ImgPipeline.encode_prompt]]
```python
encode_prompt(prompt: str | list[str], do_classifier_free_guidance: bool = True, num_images_per_prompt: int = 1, device: typing.Optional[torch.device] = None, negative_prompt: str | list[str] | None = None, prompt_embeds: typing.Optional[torch.Tensor] = None, negative_prompt_embeds: typing.Optional[torch.Tensor] = None, clean_caption: bool = False)
```
[المصدر](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.py#L192)
**المعاملات:**
prompt (`str` أو `list[str]`، *اختياري*) : النص الذي سيتم ترميزه
do_classifier_free_guidance (`bool`، *اختياري*، القيمة الافتراضية `True`) : ما إذا كان سيتم استخدام classifier free guidance أم لا
num_images_per_prompt (`int`، *اختياري*، القيمة الافتراضية 1) : عدد الصور التي يجب توليدها لكل موجه
device : (`torch.device`, *اختياري*): جهاز torch لوضع التضمينات الناتجة عليه
negative_prompt (`str` أو `list[str]`، *اختياري*) : الموجه أو الموجهات التي لا ينبغي توجيه توليد الصورة بها. إذا لم يُعرَّف، يجب تمرير `negative_prompt_embeds` بدلاً من ذلك. إذا لم يُعرَّف، يجب تمرير `negative_prompt_embeds` بدلاً من ذلك. يتم تجاهله عند عدم استخدام التوجيه (أي يتم تجاهله إذا كان `guidance_scale` أقل من `1`).
prompt_embeds (`torch.Tensor`، *اختياري*) : تمثيلات نصية مُولّدة مسبقًا. يمكن استخدامها لتعديل مدخلات النص بسهولة، *مثلًا* وزن الأوامر. إذا لم تُقدَّم، فسيتم توليد تمثيلات النص من معامل الإدخال `prompt`.
negative_prompt_embeds (`torch.Tensor`, *اختياري*) : تمثيلات نصية سالبة مُولّدة مسبقًا. يمكن استخدامها لتعديل مدخلات النص بسهولة، *مثلًا* وزن الأوامر. إذا لم تُقدَّم، فسيتم توليد negative_prompt_embeds من معامل الإدخال `negative_prompt`.
clean_caption (bool، القيمة الافتراضية `False`) : إذا كانت `True`، سيقوم الدالة بمعالجة الوصف المقدم وتنظيفه قبل الترميز.
يقوم بتشفير الموجه إلى حالات مخفية لمشفّر النص.
## IFImg2ImgSuperResolutionPipeline[[diffusers.IFImg2ImgSuperResolutionPipeline]]
#### diffusers.IFImg2ImgSuperResolutionPipeline[[diffusers.IFImg2ImgSuperResolutionPipeline]]
```python
diffusers.IFImg2ImgSuperResolutionPipeline(tokenizer: T5Tokenizer, text_encoder: T5EncoderModel, unet: UNet2DConditionModel, scheduler: DDPMScheduler, image_noising_scheduler: DDPMScheduler, safety_checker: diffusers.pipelines.deepfloyd_if.safety_checker.IFSafetyChecker | None, feature_extractor: transformers.models.clip.image_processing_pil_clip.CLIPImageProcessorPil | None, watermarker: diffusers.pipelines.deepfloyd_if.watermark.IFWatermarker | None, requires_safety_checker: bool = True)
```
[المصدر](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/deepfloyd_if/pipeline_if_img2img_superresolution.py#L124)
#### __call__[[diffusers.IFImg2ImgSuperResolutionPipeline.__call__]]
```python
__call__(image: typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor], original_image: typing.Union[PIL.Image.Image, torch.Tensor, numpy.ndarray, list[PIL.Image.Image], list[torch.Tensor], list[numpy.ndarray]] = None, strength: float = 0.8, prompt: str | list[str] = None, num_inference_steps: int = 50, timesteps: list[int] = None, guidance_scale: float = 4.0, negative_prompt: str | list[str] | None = None, num_images_per_prompt: int | None = 1, eta: float = 0.0, generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = None, prompt_embeds: typing.Optional[torch.Tensor] = None, negative_prompt_embeds: typing.Optional[torch.Tensor] = None, output_type: str | None = 'pil', return_dict: bool = True, callback: typing.Optional[typing.Callable[[int, int, torch.Tensor], NoneType]] = None, callback_steps: int = 1, cross_attention_kwargs: dict[str, typing.Any] | None = None, noise_level: int = 250, clean_caption: bool = True)
```
[المصدر](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/deepfloyd_if/pipeline_if_img2img_superresolution.py#L744)
**المعاملات:**
image (`torch.Tensor` أو `PIL.Image.Image`) : `Image`، أو tensor يمثل دفعة من الصور، وسيُستخدم كنقطة انطلاق للعملية.
original_image (`torch.Tensor` أو `PIL.Image.Image`) : الصورة الأصلية التي تم اشتقاق `image` منها.
strength (`float`، *اختياري*، القيمة الافتراضية 0.8) : يُشير مفهومياً إلى مقدار تحويل الصورة المرجعية `image`. يجب أن يكون بين 0 و 1. ستُستخدم `image` كنقطة انطلاق، حيث يُضاف المزيد من الضوضاء إليها كلما زاد `strength`. يعتمد عدد خطوات إزالة الضوضاء على كمية الضوضاء المضافة في البداية. عندما تكون قيمة `strength` هي 1، ستكون الضوضاء المضافة في أقصى حد، وستعمل عملية إزالة الضوضاء لعدد التكرارات الكامل المحدد في `num_inference_steps`. وبالتالي، فإن القيمة 1 تتجاهل `image` بشكل أساسي.
prompt (`str` أو `list[str]`، *اختياري*) : الأمر أو الأوامر التي تُوجّه توليد الصورة. إذا لم يُعرَّف، يجب تمرير `prompt_embeds` بدلاً من ذلك.
num_inference_steps (`int`، *اختياري*، القيمة الافتراضية 50) : عدد خطوات إزالة الضوضاء. تؤدي زيادة عدد خطوات إزالة الضوضاء عادةً إلى صورة ذات جودة أعلى على حساب بطء الاستدلال.
timesteps (`list[int]`، *اختياري*) : خطوات زمنية مخصصة لاستخدامها في عملية إزالة الضوضاء. إذا لم تُعرَّف، تُستخدم خطوات زمنية متساوية التباعد بعدد `num_inference_steps`. يجب أن تكون مرتبة تنازليًا.
guidance_scale (`float`، *اختياري*، القيمة الافتراضية 4.0) : مقياس التوجيه كما هو مُعرَّف في [Classifier-Free Diffusion Guidance](https://huggingface.co/papers/2207.12598). يُعرَّف `guidance_scale` على أنه `w` من المعادلة 2. في [Imagen Paper](https://huggingface.co/papers/2205.11487). يتم تفعيل مقياس التوجيه عن طريق تعيين `guidance_scale > 1`. يشجع مقياس التوجيه الأعلى على توليد صور مرتبطة ارتباطًا وثيقًا بنص `prompt`، وعادةً على حساب انخفاض جودة الصورة.
negative_prompt (`str` أو `list[str]`، *اختياري*) : الموجه أو الموجهات التي لا ينبغي توجيه توليد الصورة بها. إذا لم يُعرَّف، يجب تمرير `negative_prompt_embeds` بدلاً من ذلك. يتم تجاهله عند عدم استخدام التوجيه (أي يتم تجاهله إذا كان `guidance_scale` أقل من `1`).
num_images_per_prompt (`int`، *اختياري*، القيمة الافتراضية 1) : عدد الصور التي سيتم توليدها لكل موجه.
eta (`float`، *اختياري*، القيمة الافتراضية 0.0) : يتوافق مع المعامل eta (η) في ورقة DDIM: https://huggingface.co/papers/2010.02502. ينطبق فقط على [schedulers.DDIMScheduler](/docs/diffusers/main/ar/api/schedulers/ddim#diffusers.DDIMScheduler)، وسيتم تجاهله في الحالات الأخرى.
generator (`torch.Generator` أو `list[torch.Generator]`، *اختياري*) : مولّد واحد أو قائمة من [مولّدات torch](https://pytorch.org/docs/stable/generated/torch.Generator.html) لجعل التوليد حتميًا.
prompt_embeds (`torch.Tensor`، *اختياري*) : تمثيلات نصية مُولّدة مسبقًا. يمكن استخدامها لتعديل مدخلات النص بسهولة، *مثلًا* وزن الأوامر. إذا لم تُقدَّم، فسيتم توليد تمثيلات النص من معامل الإدخال `prompt`.
negative_prompt_embeds (`torch.Tensor`, *اختياري*) : تمثيلات نصية سالبة مُولّدة مسبقًا. يمكن استخدامها لتعديل مدخلات النص بسهولة، *مثلًا* وزن الأوامر. إذا لم تُقدَّم، فسيتم توليد negative_prompt_embeds من معامل الإدخال `negative_prompt`.
output_type (`str`، *اختياري*، القيمة الافتراضية `"pil"`) : صيغة الصورة الناتجة عن عملية التوليد. اختر بين [PIL](https://pillow.readthedocs.io/en/stable/): `PIL.Image.Image` أو `np.array`.
return_dict (`bool`، *اختياري*، القيمة الافتراضية `True`) : ما إذا كان يجب إرجاع `~pipelines.stable_diffusion.IFPipelineOutput` بدلاً من tuple عادي.
callback (`Callable`، *اختياري*) : دالة ستُستدعى كل `callback_steps` خطوات أثناء الاستدلال. سيتم استدعاء الدالة مع الحُجج التالية: `callback(step: int, timestep: int, latents: torch.Tensor)`.
callback_steps (`int`، *اختياري*، القيمة الافتراضية 1) : التكرار الذي تُستدعى فيه دالة `callback`. إذا لم يتم تحديده، فستُستدعى الدالة في كل خطوة.
cross_attention_kwargs (`dict`، *اختياري*) : قاموس kwargs يُمرَّر إلى `AttentionProcessor` إذا تم تحديده، كما هو معرَّف تحت `self.processor` في [diffusers.models.attention_processor](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/attention_processor.py).
noise_level (`int`، *اختياري*، القيمة الافتراضية 250) : كمية الضوضاء التي تُضاف إلى الصورة المُكبَّرة. يجب أن تكون ضمن المدى `[0, 1000)`
clean_caption (`bool`، *اختياري*، القيمة الافتراضية `True`) : ما إذا كان سيتم تنظيف الوصف قبل إنشاء التضمينات. يتطلب تثبيت `beautifulsoup4` و`ftfy`. إذا لم يتم تثبيت الاعتماديات، فسيتم إنشاء التضمينات من النص الخام.
**يعيد:** `~pipelines.stable_diffusion.IFPipelineOutput` أو `tuple`
`~pipelines.stable_diffusion.IFPipelineOutput` if `return_dict` is True, otherwise a `tuple. When returning a tuple, the first element is a list with the generated images, and the second element is a list of `bool`s denoting whether the corresponding generated image likely represents "not-safe-for-work" (nsfw) or watermarked content, according to the `safety_checker`.
الدالة التي تُستدعى عند استدعاء خط الأنابيب للتوليد.
أمثلة:
```py
>>> from diffusers import IFImg2ImgPipeline, IFImg2ImgSuperResolutionPipeline, DiffusionPipeline
>>> from diffusers.utils import pt_to_pil
>>> import torch
>>> from PIL import Image
>>> import requests
>>> from io import BytesIO
>>> url = "https://raw.githubusercontent.com/CompVis/stable-diffusion/main/assets/stable-samples/img2img/sketch-mountains-input.jpg"
>>> response = requests.get(url)
>>> original_image = Image.open(BytesIO(response.content)).convert("RGB")
>>> original_image = original_image.resize((768, 512))
>>> pipe = IFImg2ImgPipeline.from_pretrained(
... "DeepFloyd/IF-I-XL-v1.0",
... variant="fp16",
... torch_dtype=torch.float16,
... )
>>> pipe.enable_model_cpu_offload()
>>> prompt = "A fantasy landscape in style minecraft"
>>> prompt_embeds, negative_embeds = pipe.encode_prompt(prompt)
>>> image = pipe(
... image=original_image,
... prompt_embeds=prompt_embeds,
... negative_prompt_embeds=negative_embeds,
... output_type="pt",
... ).images
>>> # save intermediate image
>>> pil_image = pt_to_pil(image)
>>> pil_image[0].save("./if_stage_I.png")
>>> super_res_1_pipe = IFImg2ImgSuperResolutionPipeline.from_pretrained(
... "DeepFloyd/IF-II-L-v1.0",
... text_encoder=None,
... variant="fp16",
... torch_dtype=torch.float16,
... )
>>> super_res_1_pipe.enable_model_cpu_offload()
>>> image = super_res_1_pipe(
... image=image,
... original_image=original_image,
... prompt_embeds=prompt_embeds,
... negative_prompt_embeds=negative_embeds,
... ).images
>>> image[0].save("./if_stage_II.png")
```
#### encode_prompt[[diffusers.IFImg2ImgSuperResolutionPipeline.encode_prompt]]
```python
encode_prompt(prompt: str | list[str], do_classifier_free_guidance: bool = True, num_images_per_prompt: int = 1, device: typing.Optional[torch.device] = None, negative_prompt: str | list[str] | None = None, prompt_embeds: typing.Optional[torch.Tensor] = None, negative_prompt_embeds: typing.Optional[torch.Tensor] = None, clean_caption: bool = False)
```
[المصدر](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/deepfloyd_if/pipeline_if_img2img_superresolution.py#L344)
**المعاملات:**
prompt (`str` أو `list[str]`، *اختياري*) : النص الذي سيتم ترميزه
do_classifier_free_guidance (`bool`، *اختياري*، القيمة الافتراضية `True`) : ما إذا كان سيتم استخدام classifier free guidance أم لا
num_images_per_prompt (`int`، *اختياري*، القيمة الافتراضية 1) : عدد الصور التي يجب توليدها لكل موجه
device : (`torch.device`, *اختياري*): جهاز torch لوضع التضمينات الناتجة عليه
negative_prompt (`str` أو `list[str]`، *اختياري*) : الموجه أو الموجهات التي لا ينبغي توجيه توليد الصورة بها. إذا لم يُعرَّف، يجب تمرير `negative_prompt_embeds` بدلاً من ذلك. إذا لم يُعرَّف، يجب تمرير `negative_prompt_embeds` بدلاً من ذلك. يتم تجاهله عند عدم استخدام التوجيه (أي يتم تجاهله إذا كان `guidance_scale` أقل من `1`).
prompt_embeds (`torch.Tensor`، *اختياري*) : تمثيلات نصية مُولّدة مسبقًا. يمكن استخدامها لتعديل مدخلات النص بسهولة، *مثلًا* وزن الأوامر. إذا لم تُقدَّم، فسيتم توليد تمثيلات النص من معامل الإدخال `prompt`.
negative_prompt_embeds (`torch.Tensor`, *اختياري*) : تمثيلات نصية سالبة مُولّدة مسبقًا. يمكن استخدامها لتعديل مدخلات النص بسهولة، *مثلًا* وزن الأوامر. إذا لم تُقدَّم، فسيتم توليد negative_prompt_embeds من معامل الإدخال `negative_prompt`.
clean_caption (bool، القيمة الافتراضية `False`) : إذا كانت `True`، سيقوم الدالة بمعالجة الوصف المقدم وتنظيفه قبل الترميز.
يقوم بتشفير الموجه إلى حالات مخفية لمشفّر النص.
## IFInpaintingPipeline[[diffusers.IFInpaintingPipeline]]
#### diffusers.IFInpaintingPipeline[[diffusers.IFInpaintingPipeline]]
```python
diffusers.IFInpaintingPipeline(tokenizer: T5Tokenizer, text_encoder: T5EncoderModel, unet: UNet2DConditionModel, scheduler: DDPMScheduler, safety_checker: diffusers.pipelines.deepfloyd_if.safety_checker.IFSafetyChecker | None, feature_extractor: transformers.models.clip.image_processing_pil_clip.CLIPImageProcessorPil | None, watermarker: diffusers.pipelines.deepfloyd_if.watermark.IFWatermarker | None, requires_safety_checker: bool = True)
```
[المصدر](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/deepfloyd_if/pipeline_if_inpainting.py#L123)
#### __call__[[diffusers.IFInpaintingPipeline.__call__]]
```python
__call__(prompt: str | list[str] = None, image: typing.Union[PIL.Image.Image, torch.Tensor, numpy.ndarray, list[PIL.Image.Image], list[torch.Tensor], list[numpy.ndarray]] = None, mask_image: typing.Union[PIL.Image.Image, torch.Tensor, numpy.ndarray, list[PIL.Image.Image], list[torch.Tensor], list[numpy.ndarray]] = None, strength: float = 1.0, num_inference_steps: int = 50, timesteps: list[int] = None, guidance_scale: float = 7.0, negative_prompt: str | list[str] | None = None, num_images_per_prompt: int | None = 1, eta: float = 0.0, generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = None, prompt_embeds: typing.Optional[torch.Tensor] = None, negative_prompt_embeds: typing.Optional[torch.Tensor] = None, output_type: str | None = 'pil', return_dict: bool = True, callback: typing.Optional[typing.Callable[[int, int, torch.Tensor], NoneType]] = None, callback_steps: int = 1, clean_caption: bool = True, cross_attention_kwargs: dict[str, typing.Any] | None = None)
```
[المصدر](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/deepfloyd_if/pipeline_if_inpainting.py#L753)
**المعاملات:**
prompt (`str` أو `list[str]`، *اختياري*) : الأمر أو الأوامر التي تُوجّه توليد الصورة. إذا لم يُعرَّف، يجب تمرير `prompt_embeds` بدلاً من ذلك.
image (`torch.Tensor` أو `PIL.Image.Image`) : `Image`، أو tensor يمثل دفعة من الصور، وسيُستخدم كنقطة انطلاق للعملية.
mask_image (`PIL.Image.Image`) : `Image`، أو متجه (tensor) يمثل دفعة من الصور، لتطبيق قناع على `image`. سيتم إعادة رسم البكسلات البيضاء في القناع، بينما ستُحفظ البكسلات السوداء. إذا كان `mask_image` صورة بصيغة PIL، فسيتم تحويلها إلى قناة واحدة (السطوع) قبل الاستخدام. أما إذا كان متجهًا (tensor)، فيجب أن يحتوي على قناة لون واحدة (L) بدلاً من ثلاث، وبالتالي فإن الشكل المتوقع هو `(B, H, W, 1)`.
strength (`float`، *اختياري*، القيمة الافتراضية 1.0) : يُشير مفهومياً إلى مقدار تحويل الصورة المرجعية `image`. يجب أن يكون بين 0 و 1. ستُستخدم `image` كنقطة انطلاق، حيث يُضاف المزيد من الضوضاء إليها كلما زاد `strength`. يعتمد عدد خطوات إزالة الضوضاء على كمية الضوضاء المضافة في البداية. عندما تكون `strength` تساوي 1، ستكون الضوضاء المضافة في أقصى حد، وستعمل عملية إزالة الضوضاء لعدد التكرارات الكامل المحدد في `num_inference_steps`. وبالتالي، فإن القيمة 1 تتجاهل `image` بشكل أساسي.
num_inference_steps (`int`، *اختياري*، القيمة الافتراضية 50) : عدد خطوات إزالة الضوضاء. تؤدي زيادة عدد خطوات إزالة الضوضاء عادةً إلى صورة ذات جودة أعلى على حساب بطء الاستدلال.
timesteps (`list[int]`، *اختياري*) : خطوات زمنية مخصصة لاستخدامها في عملية إزالة الضوضاء. إذا لم تُعرَّف، تُستخدم خطوات زمنية متساوية التباعد بعدد `num_inference_steps`. يجب أن تكون مرتبة تنازليًا.
guidance_scale (`float`، *اختياري*، القيمة الافتراضية 7.0) : مقياس التوجيه كما هو مُعرَّف في [Classifier-Free Diffusion Guidance](https://huggingface.co/papers/2207.12598). يُعرَّف `guidance_scale` على أنه `w` من المعادلة 2. في [Imagen Paper](https://huggingface.co/papers/2205.11487). يتم تفعيل مقياس التوجيه عن طريق تعيين `guidance_scale > 1`. يشجع مقياس التوجيه الأعلى على توليد صور مرتبطة ارتباطًا وثيقًا بنص `prompt`، وعادةً على حساب انخفاض جودة الصورة.
negative_prompt (`str` أو `list[str]`، *اختياري*) : الموجه أو الموجهات التي لا ينبغي توجيه توليد الصورة بها. إذا لم يُعرَّف، يجب تمرير `negative_prompt_embeds` بدلاً من ذلك. يتم تجاهله عند عدم استخدام التوجيه (أي يتم تجاهله إذا كان `guidance_scale` أقل من `1`).
num_images_per_prompt (`int`، *اختياري*، القيمة الافتراضية 1) : عدد الصور التي سيتم توليدها لكل موجه.
eta (`float`، *اختياري*، القيمة الافتراضية 0.0) : يتوافق مع المعامل eta (η) في ورقة DDIM: https://huggingface.co/papers/2010.02502. ينطبق فقط على [schedulers.DDIMScheduler](/docs/diffusers/main/ar/api/schedulers/ddim#diffusers.DDIMScheduler)، وسيتم تجاهله في الحالات الأخرى.
generator (`torch.Generator` أو `list[torch.Generator]`، *اختياري*) : مولّد واحد أو قائمة من [مولّدات torch](https://pytorch.org/docs/stable/generated/torch.Generator.html) لجعل التوليد حتميًا.
prompt_embeds (`torch.Tensor`، *اختياري*) : تمثيلات نصية مُولّدة مسبقًا. يمكن استخدامها لتعديل مدخلات النص بسهولة، *مثلًا* وزن الأوامر. إذا لم تُقدَّم، فسيتم توليد تمثيلات النص من معامل الإدخال `prompt`.
negative_prompt_embeds (`torch.Tensor`, *اختياري*) : تمثيلات نصية سالبة مُولّدة مسبقًا. يمكن استخدامها لتعديل مدخلات النص بسهولة، *مثلًا* وزن الأوامر. إذا لم تُقدَّم، فسيتم توليد negative_prompt_embeds من معامل الإدخال `negative_prompt`.
output_type (`str`، *اختياري*، القيمة الافتراضية `"pil"`) : صيغة الصورة الناتجة عن عملية التوليد. اختر بين [PIL](https://pillow.readthedocs.io/en/stable/): `PIL.Image.Image` أو `np.array`.
return_dict (`bool`، *اختياري*، القيمة الافتراضية `True`) : ما إذا كان يجب إرجاع `~pipelines.stable_diffusion.IFPipelineOutput` بدلاً من tuple عادي.
callback (`Callable`، *اختياري*) : دالة ستُستدعى كل `callback_steps` خطوات أثناء الاستدلال. سيتم استدعاء الدالة مع الحُجج التالية: `callback(step: int, timestep: int, latents: torch.Tensor)`.
callback_steps (`int`، *اختياري*، القيمة الافتراضية 1) : التكرار الذي تُستدعى فيه دالة `callback`. إذا لم يتم تحديده، فستُستدعى الدالة في كل خطوة.
clean_caption (`bool`، *اختياري*، القيمة الافتراضية `True`) : ما إذا كان سيتم تنظيف الوصف قبل إنشاء التضمينات. يتطلب تثبيت `beautifulsoup4` و`ftfy`. إذا لم يتم تثبيت الاعتماديات، فسيتم إنشاء التضمينات من النص الخام.
cross_attention_kwargs (`dict`، *اختياري*) : قاموس kwargs يُمرَّر إلى `AttentionProcessor` إذا تم تحديده، كما هو معرَّف تحت `self.processor` في [diffusers.models.attention_processor](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/attention_processor.py).
**يعيد:** `~pipelines.stable_diffusion.IFPipelineOutput` أو `tuple`
`~pipelines.stable_diffusion.IFPipelineOutput` if `return_dict` is True, otherwise a `tuple. When returning a tuple, the first element is a list with the generated images, and the second element is a list of `bool`s denoting whether the corresponding generated image likely represents "not-safe-for-work" (nsfw) or watermarked content, according to the `safety_checker`.
الدالة التي تُستدعى عند استدعاء خط الأنابيب للتوليد.
أمثلة:
```py
>>> from diffusers import IFInpaintingPipeline, IFInpaintingSuperResolutionPipeline, DiffusionPipeline
>>> from diffusers.utils import pt_to_pil
>>> import torch
>>> from PIL import Image
>>> import requests
>>> from io import BytesIO
>>> url = "https://huggingface.co/datasets/diffusers/docs-images/resolve/main/if/person.png"
>>> response = requests.get(url)
>>> original_image = Image.open(BytesIO(response.content)).convert("RGB")
>>> original_image = original_image
>>> url = "https://huggingface.co/datasets/diffusers/docs-images/resolve/main/if/glasses_mask.png"
>>> response = requests.get(url)
>>> mask_image = Image.open(BytesIO(response.content))
>>> mask_image = mask_image
>>> pipe = IFInpaintingPipeline.from_pretrained(
... "DeepFloyd/IF-I-XL-v1.0", variant="fp16", torch_dtype=torch.float16
... )
>>> pipe.enable_model_cpu_offload()
>>> prompt = "blue sunglasses"
>>> prompt_embeds, negative_embeds = pipe.encode_prompt(prompt)
>>> image = pipe(
... image=original_image,
... mask_image=mask_image,
... prompt_embeds=prompt_embeds,
... negative_prompt_embeds=negative_embeds,
... output_type="pt",
... ).images
>>> # save intermediate image
>>> pil_image = pt_to_pil(image)
>>> pil_image[0].save("./if_stage_I.png")
>>> super_res_1_pipe = IFInpaintingSuperResolutionPipeline.from_pretrained(
... "DeepFloyd/IF-II-L-v1.0", text_encoder=None, variant="fp16", torch_dtype=torch.float16
... )
>>> super_res_1_pipe.enable_model_cpu_offload()
>>> image = super_res_1_pipe(
... image=image,
... mask_image=mask_image,
... original_image=original_image,
... prompt_embeds=prompt_embeds,
... negative_prompt_embeds=negative_embeds,
... ).images
>>> image[0].save("./if_stage_II.png")
```
#### encode_prompt[[diffusers.IFInpaintingPipeline.encode_prompt]]
```python
encode_prompt(prompt: str | list[str], do_classifier_free_guidance: bool = True, num_images_per_prompt: int = 1, device: typing.Optional[torch.device] = None, negative_prompt: str | list[str] | None = None, prompt_embeds: typing.Optional[torch.Tensor] = None, negative_prompt_embeds: typing.Optional[torch.Tensor] = None, clean_caption: bool = False)
```
[المصدر](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/deepfloyd_if/pipeline_if_inpainting.py#L195)
**المعاملات:**
prompt (`str` أو `list[str]`، *اختياري*) : النص الذي سيتم ترميزه
do_classifier_free_guidance (`bool`، *اختياري*، القيمة الافتراضية `True`) : ما إذا كان سيتم استخدام classifier free guidance أم لا
num_images_per_prompt (`int`، *اختياري*، القيمة الافتراضية 1) : عدد الصور التي يجب توليدها لكل موجه
device : (`torch.device`, *اختياري*): جهاز torch لوضع التضمينات الناتجة عليه
negative_prompt (`str` أو `list[str]`، *اختياري*) : الموجه أو الموجهات التي لا ينبغي توجيه توليد الصورة بها. إذا لم يُعرَّف، يجب تمرير `negative_prompt_embeds` بدلاً من ذلك. إذا لم يُعرَّف، يجب تمرير `negative_prompt_embeds` بدلاً من ذلك. يتم تجاهله عند عدم استخدام التوجيه (أي يتم تجاهله إذا كان `guidance_scale` أقل من `1`).
prompt_embeds (`torch.Tensor`، *اختياري*) : تمثيلات نصية مُولّدة مسبقًا. يمكن استخدامها لتعديل مدخلات النص بسهولة، *مثلًا* وزن الأوامر. إذا لم تُقدَّم، فسيتم توليد تمثيلات النص من معامل الإدخال `prompt`.
negative_prompt_embeds (`torch.Tensor`, *اختياري*) : تمثيلات نصية سالبة مُولّدة مسبقًا. يمكن استخدامها لتعديل مدخلات النص بسهولة، *مثلًا* وزن الأوامر. إذا لم تُقدَّم، فسيتم توليد negative_prompt_embeds من معامل الإدخال `negative_prompt`.
clean_caption (bool، القيمة الافتراضية `False`) : إذا كانت `True`، سيقوم الدالة بمعالجة الوصف المقدم وتنظيفه قبل الترميز.
يقوم بتشفير الموجه إلى حالات مخفية لمشفّر النص.
## IFInpaintingSuperResolutionPipeline[[diffusers.IFInpaintingSuperResolutionPipeline]]
#### diffusers.IFInpaintingSuperResolutionPipeline[[diffusers.IFInpaintingSuperResolutionPipeline]]
```python
diffusers.IFInpaintingSuperResolutionPipeline(tokenizer: T5Tokenizer, text_encoder: T5EncoderModel, unet: UNet2DConditionModel, scheduler: DDPMScheduler, image_noising_scheduler: DDPMScheduler, safety_checker: diffusers.pipelines.deepfloyd_if.safety_checker.IFSafetyChecker | None, feature_extractor: transformers.models.clip.image_processing_pil_clip.CLIPImageProcessorPil | None, watermarker: diffusers.pipelines.deepfloyd_if.watermark.IFWatermarker | None, requires_safety_checker: bool = True)
```
[المصدر](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/deepfloyd_if/pipeline_if_inpainting_superresolution.py#L126)
#### __call__[[diffusers.IFInpaintingSuperResolutionPipeline.__call__]]
```python
__call__(image: typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor], original_image: typing.Union[PIL.Image.Image, torch.Tensor, numpy.ndarray, list[PIL.Image.Image], list[torch.Tensor], list[numpy.ndarray]] = None, mask_image: typing.Union[PIL.Image.Image, torch.Tensor, numpy.ndarray, list[PIL.Image.Image], list[torch.Tensor], list[numpy.ndarray]] = None, strength: float = 0.8, prompt: str | list[str] = None, num_inference_steps: int = 100, timesteps: list[int] = None, guidance_scale: float = 4.0, negative_prompt: str | list[str] | None = None, num_images_per_prompt: int | None = 1, eta: float = 0.0, generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = None, prompt_embeds: typing.Optional[torch.Tensor] = None, negative_prompt_embeds: typing.Optional[torch.Tensor] = None, output_type: str | None = 'pil', return_dict: bool = True, callback: typing.Optional[typing.Callable[[int, int, torch.Tensor], NoneType]] = None, callback_steps: int = 1, cross_attention_kwargs: dict[str, typing.Any] | None = None, noise_level: int = 0, clean_caption: bool = True)
```
[المصدر](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/deepfloyd_if/pipeline_if_inpainting_superresolution.py#L832)
**المعاملات:**
image (`torch.Tensor` أو `PIL.Image.Image`) : `Image`، أو tensor يمثل دفعة من الصور، وسيُستخدم كنقطة انطلاق للعملية.
original_image (`torch.Tensor` أو `PIL.Image.Image`) : الصورة الأصلية التي تم اشتقاق `image` منها.
mask_image (`PIL.Image.Image`) : `Image`، أو متجه (tensor) يمثل دفعة من الصور، لتطبيق قناع على `image`. سيتم إعادة رسم البكسلات البيضاء في القناع، بينما ستُحفظ البكسلات السوداء. إذا كان `mask_image` صورة بصيغة PIL، فسيتم تحويلها إلى قناة واحدة (السطوع) قبل الاستخدام. أما إذا كان متجهًا (tensor)، فيجب أن يحتوي على قناة لون واحدة (L) بدلاً من ثلاث، وبالتالي فإن الشكل المتوقع هو `(B, H, W, 1)`.
strength (`float`، *اختياري*، القيمة الافتراضية 0.8) : يُشير مفهومياً إلى مقدار تحويل الصورة المرجعية `image`. يجب أن يكون بين 0 و 1. ستُستخدم `image` كنقطة انطلاق، حيث يُضاف المزيد من الضوضاء إليها كلما زاد `strength`. يعتمد عدد خطوات إزالة الضوضاء على كمية الضوضاء المضافة في البداية. عندما تكون قيمة `strength` هي 1، ستكون الضوضاء المضافة في أقصى حد، وستعمل عملية إزالة الضوضاء لعدد التكرارات الكامل المحدد في `num_inference_steps`. وبالتالي، فإن القيمة 1 تتجاهل `image` بشكل أساسي.
prompt (`str` أو `list[str]`، *اختياري*) : الأمر أو الأوامر التي تُوجّه توليد الصورة. إذا لم يُعرَّف، يجب تمرير `prompt_embeds` بدلاً من ذلك.
num_inference_steps (`int`، *اختياري*، القيمة الافتراضية 100) : عدد خطوات إزالة الضوضاء. تؤدي زيادة عدد خطوات إزالة الضوضاء عادةً إلى صورة ذات جودة أعلى على حساب بطء الاستدلال.
timesteps (`list[int]`، *اختياري*) : خطوات زمنية مخصصة لاستخدامها في عملية إزالة الضوضاء. إذا لم تُعرَّف، تُستخدم خطوات زمنية متساوية التباعد بعدد `num_inference_steps`. يجب أن تكون مرتبة تنازليًا.
guidance_scale (`float`، *اختياري*، القيمة الافتراضية 4.0) : مقياس التوجيه كما هو مُعرَّف في [Classifier-Free Diffusion Guidance](https://huggingface.co/papers/2207.12598). يُعرَّف `guidance_scale` على أنه `w` من المعادلة 2. في [Imagen Paper](https://huggingface.co/papers/2205.11487). يتم تفعيل مقياس التوجيه عن طريق تعيين `guidance_scale > 1`. يشجع مقياس التوجيه الأعلى على توليد صور مرتبطة ارتباطًا وثيقًا بنص `prompt`، وعادةً على حساب انخفاض جودة الصورة.
negative_prompt (`str` أو `list[str]`، *اختياري*) : الموجه أو الموجهات التي لا ينبغي توجيه توليد الصورة بها. إذا لم يُعرَّف، يجب تمرير `negative_prompt_embeds` بدلاً من ذلك. يتم تجاهله عند عدم استخدام التوجيه (أي يتم تجاهله إذا كان `guidance_scale` أقل من `1`).
num_images_per_prompt (`int`، *اختياري*، القيمة الافتراضية 1) : عدد الصور التي سيتم توليدها لكل موجه.
eta (`float`، *اختياري*، القيمة الافتراضية 0.0) : يتوافق مع المعامل eta (η) في ورقة DDIM: https://huggingface.co/papers/2010.02502. ينطبق فقط على [schedulers.DDIMScheduler](/docs/diffusers/main/ar/api/schedulers/ddim#diffusers.DDIMScheduler)، وسيتم تجاهله في الحالات الأخرى.
generator (`torch.Generator` أو `list[torch.Generator]`، *اختياري*) : مولّد واحد أو قائمة من [مولّدات torch](https://pytorch.org/docs/stable/generated/torch.Generator.html) لجعل التوليد حتميًا.
prompt_embeds (`torch.Tensor`، *اختياري*) : تمثيلات نصية مُولّدة مسبقًا. يمكن استخدامها لتعديل مدخلات النص بسهولة، *مثلًا* وزن الأوامر. إذا لم تُقدَّم، فسيتم توليد تمثيلات النص من معامل الإدخال `prompt`.
negative_prompt_embeds (`torch.Tensor`, *اختياري*) : تمثيلات نصية سالبة مُولّدة مسبقًا. يمكن استخدامها لتعديل مدخلات النص بسهولة، *مثلًا* وزن الأوامر. إذا لم تُقدَّم، فسيتم توليد negative_prompt_embeds من معامل الإدخال `negative_prompt`.
output_type (`str`، *اختياري*، القيمة الافتراضية `"pil"`) : صيغة الصورة الناتجة عن عملية التوليد. اختر بين [PIL](https://pillow.readthedocs.io/en/stable/): `PIL.Image.Image` أو `np.array`.
return_dict (`bool`، *اختياري*، القيمة الافتراضية `True`) : ما إذا كان يجب إرجاع `~pipelines.stable_diffusion.IFPipelineOutput` بدلاً من tuple عادي.
callback (`Callable`، *اختياري*) : دالة ستُستدعى كل `callback_steps` خطوات أثناء الاستدلال. سيتم استدعاء الدالة مع الحُجج التالية: `callback(step: int, timestep: int, latents: torch.Tensor)`.
callback_steps (`int`، *اختياري*، القيمة الافتراضية 1) : التكرار الذي تُستدعى فيه دالة `callback`. إذا لم يتم تحديده، فستُستدعى الدالة في كل خطوة.
cross_attention_kwargs (`dict`، *اختياري*) : قاموس kwargs يُمرَّر إلى `AttentionProcessor` إذا تم تحديده، كما هو معرَّف تحت `self.processor` في [diffusers.models.attention_processor](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/attention_processor.py).
noise_level (`int`، *اختياري*، القيمة الافتراضية 0) : كمية الضوضاء التي تُضاف إلى الصورة المُكبَّرة. يجب أن تكون ضمن المدى `[0, 1000)`
clean_caption (`bool`، *اختياري*، القيمة الافتراضية `True`) : ما إذا كان سيتم تنظيف الوصف قبل إنشاء التضمينات. يتطلب تثبيت `beautifulsoup4` و`ftfy`. إذا لم يتم تثبيت الاعتماديات، فسيتم إنشاء التضمينات من النص الخام.
**يعيد:** `~pipelines.stable_diffusion.IFPipelineOutput` أو `tuple`
`~pipelines.stable_diffusion.IFPipelineOutput` if `return_dict` is True, otherwise a `tuple. When returning a tuple, the first element is a list with the generated images, and the second element is a list of `bool`s denoting whether the corresponding generated image likely represents "not-safe-for-work" (nsfw) or watermarked content, according to the `safety_checker`.
الدالة التي تُستدعى عند استدعاء خط الأنابيب للتوليد.
أمثلة:
```py
>>> from diffusers import IFInpaintingPipeline, IFInpaintingSuperResolutionPipeline, DiffusionPipeline
>>> from diffusers.utils import pt_to_pil
>>> import torch
>>> from PIL import Image
>>> import requests
>>> from io import BytesIO
>>> url = "https://huggingface.co/datasets/diffusers/docs-images/resolve/main/if/person.png"
>>> response = requests.get(url)
>>> original_image = Image.open(BytesIO(response.content)).convert("RGB")
>>> original_image = original_image
>>> url = "https://huggingface.co/datasets/diffusers/docs-images/resolve/main/if/glasses_mask.png"
>>> response = requests.get(url)
>>> mask_image = Image.open(BytesIO(response.content))
>>> mask_image = mask_image
>>> pipe = IFInpaintingPipeline.from_pretrained(
... "DeepFloyd/IF-I-XL-v1.0", variant="fp16", torch_dtype=torch.float16
... )
>>> pipe.enable_model_cpu_offload()
>>> prompt = "blue sunglasses"
>>> prompt_embeds, negative_embeds = pipe.encode_prompt(prompt)
>>> image = pipe(
... image=original_image,
... mask_image=mask_image,
... prompt_embeds=prompt_embeds,
... negative_prompt_embeds=negative_embeds,
... output_type="pt",
... ).images
>>> # save intermediate image
>>> pil_image = pt_to_pil(image)
>>> pil_image[0].save("./if_stage_I.png")
>>> super_res_1_pipe = IFInpaintingSuperResolutionPipeline.from_pretrained(
... "DeepFloyd/IF-II-L-v1.0", text_encoder=None, variant="fp16", torch_dtype=torch.float16
... )
>>> super_res_1_pipe.enable_model_cpu_offload()
>>> image = super_res_1_pipe(
... image=image,
... mask_image=mask_image,
... original_image=original_image,
... prompt_embeds=prompt_embeds,
... negative_prompt_embeds=negative_embeds,
... ).images
>>> image[0].save("./if_stage_II.png")
```
#### encode_prompt[[diffusers.IFInpaintingSuperResolutionPipeline.encode_prompt]]
```python
encode_prompt(prompt: str | list[str], do_classifier_free_guidance: bool = True, num_images_per_prompt: int = 1, device: typing.Optional[torch.device] = None, negative_prompt: str | list[str] | None = None, prompt_embeds: typing.Optional[torch.Tensor] = None, negative_prompt_embeds: typing.Optional[torch.Tensor] = None, clean_caption: bool = False)
```
[المصدر](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/deepfloyd_if/pipeline_if_inpainting_superresolution.py#L346)
**المعاملات:**
prompt (`str` أو `list[str]`، *اختياري*) : النص الذي سيتم ترميزه
do_classifier_free_guidance (`bool`، *اختياري*، القيمة الافتراضية `True`) : ما إذا كان سيتم استخدام classifier free guidance أم لا
num_images_per_prompt (`int`، *اختياري*، القيمة الافتراضية 1) : عدد الصور التي يجب توليدها لكل موجه
device : (`torch.device`, *اختياري*): جهاز torch لوضع التضمينات الناتجة عليه
negative_prompt (`str` أو `list[str]`، *اختياري*) : الموجه أو الموجهات التي لا ينبغي توجيه توليد الصورة بها. إذا لم يُعرَّف، يجب تمرير `negative_prompt_embeds` بدلاً من ذلك. إذا لم يُعرَّف، يجب تمرير `negative_prompt_embeds` بدلاً من ذلك. يتم تجاهله عند عدم استخدام التوجيه (أي يتم تجاهله إذا كان `guidance_scale` أقل من `1`).
prompt_embeds (`torch.Tensor`، *اختياري*) : تمثيلات نصية مُولّدة مسبقًا. يمكن استخدامها لتعديل مدخلات النص بسهولة، *مثلًا* وزن الأوامر. إذا لم تُقدَّم، فسيتم توليد تمثيلات النص من معامل الإدخال `prompt`.
negative_prompt_embeds (`torch.Tensor`, *اختياري*) : تمثيلات نصية سالبة مُولّدة مسبقًا. يمكن استخدامها لتعديل مدخلات النص بسهولة، *مثلًا* وزن الأوامر. إذا لم تُقدَّم، فسيتم توليد negative_prompt_embeds من معامل الإدخال `negative_prompt`.
clean_caption (bool، القيمة الافتراضية `False`) : إذا كانت `True`، سيقوم الدالة بمعالجة الوصف المقدم وتنظيفه قبل الترميز.
يقوم بتشفير الموجه إلى حالات مخفية لمشفّر النص.
# DeepFloyd IF
## نظرة عامة
DeepFloyd IF هو نموذج مفتوح المصدر حديث ومتطور لتوليد الصور من النص، يتميز بدرجة عالية من الواقعية الضوئية وفهم اللغة. يتكون النموذج من وحدات منفصلة تشمل مشفّر نصي مجمّد وثلاثة وحدات انتشار بكسل متسلسلة:
- المرحلة 1: نموذج أساسي يولّد صورة بدقة 64x64 بكسل بناءً على وصف نصي،
- المرحلة 2: نموذج فائق الدقة 64x64 بكسل => 256x256 بكسل، و
- المرحلة 3: نموذج فائق الدقة 256x256 بكسل => 1024x1024 بكسل
تستخدم المرحلة 1 والمرحلة 2 مُشفِّر نص مجمّد مبني على محوّل T5 لاستخراج تمثيلات النص، ثم تُغذّى هذه التمثيلات في بنية UNet معززة بآلية الانتباه المتقاطع (cross-attention) وتجميع الانتباه (attention pooling). المرحلة 3 هي [نموذج x4 Upscaling من Stability AI](https://huggingface.co/stabilityai/stable-diffusion-x4-upscaler). النتيجة هي نموذج شديد الكفاءة يتفوق على أحدث النماذج المتقدمة حاليًا، محققًا درجة FID صفرية (zero-shot) تبلغ 6.66 على مجموعة بيانات COCO. يؤكد عملنا على إمكانات بنية UNet الأكبر حجمًا في المرحلة الأولى من نماذج الانتشار المتسلسلة (cascaded diffusion models)، ويصوّر مستقبلًا واعدًا لتوليد الصور من النص.
## الاستخدام
قبل أن تتمكن من استخدام IF، عليك قبول شروط استخدامه. للقيام بذلك:
1. تأكد من امتلاك [حساب Hugging Face](https://huggingface.co/join) وتسجيل الدخول.
2. قبل الترخيص في بطاقة النموذج الخاصة بـ [DeepFloyd/IF-I-XL-v1.0](https://huggingface.co/DeepFloyd/IF-I-XL-v1.0). قبول الترخيص في بطاقة نموذج المرحلة الأولى سيقبل تلقائياً لبقية نماذج IF.
3. تأكد من تسجيل الدخول محليًا. ثبّت `huggingface_hub`:
```sh
pip install huggingface_hub --upgrade
```
شغّل دالة تسجيل الدخول في واجهة Python:
```py
from huggingface_hub import login
login()
```
وأدخل [رمز الوصول الخاص بك إلى Hugging Face Hub](https://huggingface.co/docs/hub/security-tokens#what-are-user-access-tokens).
في الخطوة التالية نقوم بتثبيت `diffusers` والتبعيات:
```sh
pip install -q diffusers accelerate transformers
```
تقدم الأقسام التالية أمثلة أكثر تفصيلاً حول كيفية استخدام IF. على وجه التحديد:
- [توليد الصور من النص](#text-to-image-generation)
- [توليد الصور من الصور](#text-guided-image-to-image-generation)
- [تعبئة المناطق المفقودة](#text-guided-inpainting-generation)
- [إعادة استخدام أوزان النموذج](#converting-between-different-pipelines)
- [تحسين السرعة](#optimizing-for-speed)
- [تحسين الذاكرة](#optimizing-for-memory)
**النقاط المحفوظة المتاحة**
- *المرحلة 1*
- [DeepFloyd/IF-I-XL-v1.0](https://huggingface.co/DeepFloyd/IF-I-XL-v1.0)
- [DeepFloyd/IF-I-L-v1.0](https://huggingface.co/DeepFloyd/IF-I-L-v1.0)
- [DeepFloyd/IF-I-M-v1.0](https://huggingface.co/DeepFloyd/IF-I-M-v1.0)
- *المرحلة 2*
- [DeepFloyd/IF-II-L-v1.0](https://huggingface.co/DeepFloyd/IF-II-L-v1.0)
- [DeepFloyd/IF-II-M-v1.0](https://huggingface.co/DeepFloyd/IF-II-M-v1.0)
- *المرحلة 3*
- [stabilityai/stable-diffusion-x4-upscaler](https://huggingface.co/stabilityai/stable-diffusion-x4-upscaler)
**Google Colab** [](https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers/deepfloyd_if_free_tier_google_colab.ipynb)
### توليد الصور من النص
يستخدم [نقل النموذج إلى وحدة المعالجة المركزية](../../optimization/memory#model-offloading) افتراضياً في diffusers لتشغيل خط أنابيب IF بالكامل باستخدام ما لا يقل عن 14 جيجابايت من ذاكرة الفيديو.
```python
from diffusers import DiffusionPipeline
from diffusers.utils import pt_to_pil, make_image_grid
import torch
# stage 1
stage_1 = DiffusionPipeline.from_pretrained("DeepFloyd/IF-I-XL-v1.0", variant="fp16", dtype=torch.float16)
stage_1.enable_model_cpu_offload()
# stage 2
stage_2 = DiffusionPipeline.from_pretrained(
"DeepFloyd/IF-II-L-v1.0", text_encoder=None, variant="fp16", dtype=torch.float16
)
stage_2.enable_model_cpu_offload()
# stage 3
safety_modules = {
"feature_extractor": stage_1.feature_extractor,
"safety_checker": stage_1.safety_checker,
"watermarker": stage_1.watermarker,
}
stage_3 = DiffusionPipeline.from_pretrained(
"stabilityai/stable-diffusion-x4-upscaler", **safety_modules, dtype=torch.float16
)
stage_3.enable_model_cpu_offload()
prompt = 'a photo of a kangaroo wearing an orange hoodie and blue sunglasses standing in front of the eiffel tower holding a sign that says "very deep learning"'
generator = torch.manual_seed(1)
# text embeds
prompt_embeds, negative_embeds = stage_1.encode_prompt(prompt)
# stage 1
Xet Storage Details
- Size:
- 97.8 kB
- Xet hash:
- a62e5c2e1efc8e005b35a7d5bb1651f9a7b51c748590e9ae8d4e7dd59dac61de
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.