Buckets:
| # | |
| # Apache Lisansı, 2.0 Sürümü ("Lisans") altında lisanslanmıştır; | |
| # bu dosyayı, Lisansa uygun olarak kullanabilirsiniz. | |
| # Lisansın bir kopyasını şu adresten edinebilirsiniz | |
| # | |
| # http://www.apache.org/licenses/LICENSE-2.0 | |
| # | |
| # Uygulanabilir yasa gerektirmedikçe veya yazılı olarak anlaşılmadıkça, yazılım | |
| # Lisans kapsamında dağıtılan, "OLDUĞU GİBİ" esasına göre dağıtılır, | |
| # HİÇBİR TÜR AÇIK VEYA ZIMMİ GARANTİ VEYA ŞART İÇERMEZ. | |
| # İzinleri ve | |
| # Lisans kapsamındaki kısıtlamalar. | |
| --> | |
| # GLM-Image | |
| ## Genel Bakış | |
| GLM-Image, görsel sadakatin ve ince detayların üst sınırını etkili bir şekilde zorlayan, hibrit otoregresif + difüzyon çözücü mimarisini benimseyen bir görüntü üretim modelidir. Genel görüntü üretim kalitesi açısından sektörde standart kabul edilen LDM tabanlı yaklaşımlarla uyumlu olup, bilgi yoğun görüntü üretim senaryolarında belirgin avantajlar sergilemektedir. | |
| Model mimarisi: hibrit otoregresif + difüzyon çözücü tasarımı | |
| + Otomatik regresif üreteç: [GLM-4-9B-0414](https://huggingface.co/zai-org/GLM-4-9B-0414) modelinden başlatılan, görsel jetonları dahil etmek için genişletilmiş bir sözlüğe sahip 9B parametreli bir model. Model önce yaklaşık 256 jetonluk kompakt bir kodlama üretir, ardından 1K–4K jetona genişler; bu da 1K–2K yüksek çözünürlüklü görsel çıktılara karşılık gelir. AR modelini `transformers` kütüphanesindeki `GlmImageForConditionalGeneration` sınıfında inceleyebilirsiniz. | |
| + Diffusion Decoder: gizli uzayda görüntü çözme için tek akışlı DiT mimarisine dayalı, 7B parametreli bir decoder. İçinde bir Glyph Encoder metin modülü bulunur ve bu sayede görüntüler içindeki metinlerin doğru şekilde çizilmesi önemli ölçüde iyileştirilir. | |
| Ayrıştırılmış pekiştirmeli öğrenme ile eğitim sonrası: model, GRPO algoritmasını kullanarak ince taneli, modüler bir geri bildirim stratejisi sunar ve hem semantik anlama hem de görsel detay kalitesini önemli ölçüde artırır. | |
| + Otomatik regresif modül: estetik ve anlamsal hizalanmaya odaklanan düşük frekanslı geri bildirim sinyalleri sağlar, talimat takibini ve sanatsal ifadeyi iyileştirir. | |
| + Decoder modülü: detay sadakati ve metin doğruluğunu hedefleyen yüksek frekanslı geri bildirim sağlar; bu da son derece gerçekçi dokular, aydınlatma ve renk yeniden üretimi ile daha hassas metin renderlaması sonuçlanır. | |
| GLM-Image, tek bir model içinde hem metinden görüntüye hem de görüntüden görüntüye üretimi destekler | |
| + Metinden görüntüye: metinsel açıklamalardan yüksek detaylı görüntüler üretir; özellikle bilgi yoğun senaryolarda güçlü performans sergiler. | |
| + Görselden görseli: Görsel düzenleme, stil aktarımı, çoklu özne tutarlılığı ve insanlar ile nesneler için kimlik koruyucu üretim dahil olmak üzere geniş bir görev yelpazesini destekler. | |
| Bu pipeline [zRzRzRzRzRzRzR](https://github.com/zRzRzRzRzRzRzR) tarafından katkı sağlanmıştır. Kod tabanı [burada](https://huggingface.co/zai-org/GLM-Image) bulunabilir. | |
| ## Kullanım örnekleri | |
| ### Metinden Görüntüye Üretim | |
| ```python | |
| import torch | |
| from diffusers.pipelines.glm_image import GlmImagePipeline | |
| pipe = GlmImagePipeline.from_pretrained("zai-org/GLM-Image",dtype=torch.bfloat16,device_map="cuda") | |
| prompt = "A beautifully designed modern food magazine style dessert recipe illustration, themed around a raspberry mousse cake. The overall layout is clean and bright, divided into four main areas: the top left features a bold black title 'Raspberry Mousse Cake Recipe Guide', with a soft-lit close-up photo of the finished cake on the right, showcasing a light pink cake adorned with fresh raspberries and mint leaves; the bottom left contains an ingredient list section, titled 'Ingredients' in a simple font, listing 'Flour 150g', 'Eggs 3', 'Sugar 120g', 'Raspberry puree 200g', 'Gelatin sheets 10g', 'Whipping cream 300ml', and 'Fresh raspberries', each accompanied by minimalist line icons (like a flour bag, eggs, sugar jar, etc.); the bottom right displays four equally sized step boxes, each containing high-definition macro photos and corresponding instructions, arranged from top to bottom as follows: Step 1 shows a whisk whipping white foam (with the instruction 'Whip egg whites to stiff peaks'), Step 2 shows a red-and-white mixture being folded with a spatula (with the instruction 'Gently fold in the puree and batter'), Step 3 shows pink liquid being poured into a round mold (with the instruction 'Pour into mold and chill for 4 hours'), Step 4 shows the finished cake decorated with raspberries and mint leaves (with the instruction 'Decorate with raspberries and mint'); a light brown information bar runs along the bottom edge, with icons on the left representing 'Preparation time: 30 minutes', 'Cooking time: 20 minutes', and 'Servings: 8'. The overall color scheme is dominated by creamy white and light pink, with a subtle paper texture in the background, featuring compact and orderly text and image layout with clear information hierarchy." | |
| image = pipe( | |
| prompt=prompt, | |
| height=32 * 32, | |
| width=36 * 32, | |
| num_inference_steps=30, | |
| guidance_scale=1.5, | |
| generator=torch.Generator(device="cuda").manual_seed(42), # or "mps", "xpu", "cpu" | |
| ).images[0] | |
| image.save("output_t2i.png") | |
| ``` | |
| ### Görselden Görsel Üretimi | |
| ```python | |
| import torch | |
| from diffusers.pipelines.glm_image import GlmImagePipeline | |
| from PIL import Image | |
| pipe = GlmImagePipeline.from_pretrained("zai-org/GLM-Image",dtype=torch.bfloat16,device_map="cuda") | |
| image_path = "cond.jpg" | |
| prompt = "Replace the background of the snow forest with an underground station featuring an automatic escalator." | |
| image = Image.open(image_path).convert("RGB") | |
| image = pipe( | |
| prompt=prompt, | |
| image=[image], # can input multiple images for multi-image-to-image generation such as [image, image1] | |
| height=33 * 32, | |
| width=32 * 32, | |
| num_inference_steps=30, | |
| guidance_scale=1.5, | |
| generator=torch.Generator(device="cuda").manual_seed(42), # or "mps", "xpu", "cpu" | |
| ).images[0] | |
| image.save("output_i2i.png") | |
| ``` | |
| + GLM-Image'de kullanılan AR modeli varsayılan olarak `do_sample=True` ve `0.95` sıcaklık değeriyle yapılandırıldığından, üretilen görseller çalıştırma arasında önemli ölçüde farklılık gösterebilir. AR modelinden hatalı veya bozulmuş çıktılar alınabileceğinden do_sample=False olarak ayarlamamızı önermiyoruz. | |
| ## GlmImagePipeline[[diffusers.GlmImagePipeline]] | |
| #### diffusers.GlmImagePipeline[[diffusers.GlmImagePipeline]] | |
| ```python | |
| diffusers.GlmImagePipeline(tokenizer: ByT5Tokenizer, processor: GlmImageProcessor, text_encoder: T5EncoderModel, vision_language_encoder: GlmImageForConditionalGeneration, vae: AutoencoderKL, transformer: GlmImageTransformer2DModel, scheduler: FlowMatchEulerDiscreteScheduler) | |
| ``` | |
| [Kaynak](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/glm_image/pipeline_glm_image.py#L161) | |
| **Parametreler:** | |
| tokenizer (`PreTrainedTokenizer`) : Metin kodlayıcı için tokenizer. | |
| processor (`AutoProcessor`) : AR modelinin sohbet şablonlarını ve tokenizasyonu işlemesi için kullanılan işlemci. | |
| text_encoder (`T5EncoderModel`) : Glif gömme (embedding) için dondurulmuş metin kodlayıcı. | |
| vision_language_encoder (`GlmImageForConditionalGeneration`) : Metin istemlerinden görüntü jetonları üreten AR modeli. | |
| vae ([AutoencoderKL](/docs/diffusers/main/tr/api/models/autoencoderkl#diffusers.AutoencoderKL)) : Görüntüleri gizil (latent) temsillere kodlamak ve bu temsillerden görüntülere çözmek için kullanılan Varyasyonel Oto-Kodlayıcı (VAE) Modeli. | |
| transformer ([GlmImageTransformer2DModel](/docs/diffusers/main/tr/api/models/glm_image_transformer2d#diffusers.GlmImageTransformer2DModel)) : Kodlanmış görüntü latentlerini gürültüden arındırmak için metin koşullu bir dönüştürücü (DiT). | |
| scheduler ([SchedulerMixin](/docs/diffusers/main/tr/api/schedulers/overview#diffusers.SchedulerMixin)) : Kodlanmış görüntü latentlerini gürültüden arındırmak için `transformer` ile birlikte kullanılacak bir zamanlayıcı. | |
| GLM-Image kullanarak metinden görüntüye üretim için Pipeline. | |
| Bu pipeline, token üretimi için AR (otoregresif) modelini ve görüntü çözme için DiT (difüzyon dönüştürücü) modelini birleştirir. | |
| #### __call__[[diffusers.GlmImagePipeline.__call__]] | |
| ```python | |
| __call__(prompt: str | list[str] | None = None, image: typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor], NoneType] = None, height: int | None = None, width: int | None = None, num_inference_steps: int = 50, timesteps: list[int] | None = None, sigmas: list[float] | None = None, guidance_scale: float = 1.5, num_images_per_prompt: int = 1, generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = None, latents: typing.Optional[torch.Tensor] = None, prompt_embeds: typing.Optional[torch.Tensor] = None, negative_prompt_embeds: typing.Optional[torch.Tensor] = None, prior_token_ids: typing.Optional[torch.Tensor] = None, prior_token_image_ids: list[torch.Tensor] | None = None, source_image_grid_thw: list[torch.Tensor] | None = None, crops_coords_top_left: tuple = (0, 0), output_type: str = 'pil', return_dict: bool = True, attention_kwargs: dict[str, typing.Any] | None = None, callback_on_step_end: typing.Union[typing.Callable[[int, int, dict], NoneType], diffusers.callbacks.PipelineCallback, diffusers.callbacks.MultiPipelineCallbacks, NoneType] = None, callback_on_step_end_tensor_inputs: list = ['latents'], max_sequence_length: int = 2048) | |
| ``` | |
| [Kaynak](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/glm_image/pipeline_glm_image.py#L719) | |
| **Parametreler:** | |
| prompt (`str` veya `list[str]`, *isteğe bağlı*) : Görsel üretimi yönlendirmek için istem veya istemler. H ve W, token boyutları (d32) olmak üzere, 'H W' biçiminde şekil bilgisi içermelidir. Örnek: "A beautiful sunset36 24", 1152x768 boyutunda bir görsel üretir. | |
| image : Görselden görsel üretim için isteğe bağlı koşul görselleri. | |
| height (`int`, *isteğe bağlı*) : Piksel cinsinden yükseklik. Verilmezse, istek şekil bilgisinden türetilir. | |
| width (`int`, *isteğe bağlı*) : Piksel cinsinden genişlik. Sağlanmazsa, istek şekil bilgisinden türetilir. | |
| num_inference_steps (`int`, *isteğe bağlı*, varsayılan `50`) : DiT için gürültü azaltma adım sayısı. | |
| timesteps (`list[int]`, *isteğe bağlı*) : Gürültü azaltma süreci için kullanılacak özel zaman adımları. Tanımlanmamışsa, `num_inference_steps` için zamanlayıcının varsayılan zaman çizelgesi kullanılır. | |
| sigmas (`list[float]`, *isteğe bağlı*) : Gürültü azaltma süreci için kullanılacak özel sigmalar. Tanımlanmamışsa, zamanlayıcının varsayılan zamanlaması kullanılır. | |
| guidance_scale (`float`, *isteğe bağlı*, varsayılan `1.5`) : Sınıflandırıcı-özgürlü yönlendirme için yönlendirme ölçeği. | |
| num_images_per_prompt (`int`, *isteğe bağlı*, varsayılan `1`) : Her istem için oluşturulacak görsel sayısı. | |
| generator (`torch.Generator`, *isteğe bağlı*) : Yeniden üretilebilirlik için rastgele üreteç. | |
| latents (`torch.Tensor`, *isteğe bağlı*) : Görsel üretimi için girdi olarak kullanılacak önceden oluşturulmuş gürültülü latentler. | |
| prompt_embeds (`torch.Tensor`, *isteğe bağlı*) : Önceden oluşturulmuş metin gömme değerleri. Sağlanmazsa, gömme değerleri `prompt` üzerinden oluşturulur. | |
| negative_prompt_embeds (`torch.Tensor`, *isteğe bağlı*) : Önceden oluşturulmuş negatif metin gömme değerleri. Sınıflandırıcı-ücretsiz yönlendirme (classifier-free guidance) etkinleştirildiğinde kullanılır. | |
| prior_token_ids (`torch.Tensor`, *isteğe bağlı*) : `generate_prior_tokens` tarafından önceden oluşturulmuş öncül token kimlikleri. Sağlanırsa, öncül üretim atlanır. | |
| prior_token_image_ids (`list[torch.Tensor]`, *isteğe bağlı*) : `prior_token_ids` ile ilişkili görüntü belirteç kimlikleri. | |
| source_image_grid_thw (`list[torch.Tensor]`, *isteğe bağlı*) : Kaynak görüntü belirteçleri için örnek başına THW ızgara bilgisi. | |
| crops_coords_top_left (`tuple[int, int]`, *isteğe bağlı*, varsayılan `(0, 0)`) : Koşullama gömme (embedding) için kullanılan kırpmanın sol üst koordinatları. | |
| output_type (`str`, *isteğe bağlı*, varsayılan `"pil"`) : Çıktı biçimi: "pil", "np" veya "latent". | |
| return_dict (`bool`, *isteğe bağlı*, varsayılan `True`) : Düz bir tuple yerine `GlmImagePipelineOutput` döndürülüp döndürülmediğini belirtir. | |
| attention_kwargs (`dict`, *isteğe bağlı*) : Belirtilirse `AttentionProcessor`'a iletilen bir kwargs sözlüğü. | |
| callback_on_step_end (`Callable`, `PipelineCallback`, `MultiPipelineCallbacks`, *isteğe bağlı*) : Her gürültü azaltma adımının sonunda çağrılan bir işlev. | |
| callback_on_step_end_tensor_inputs (`list[str]`, *isteğe bağlı*) : `callback_on_step_end`'e geçirilen girdi tensörleri. | |
| max_sequence_length (`int`, *isteğe bağlı*, varsayılan `2048`) : Metin kodlayıcısı için maksimum dizi uzunluğu. | |
| **Dönüş:** `GlmImagePipelineOutput` veya `tuple` | |
| Oluşturulan görüntüler. | |
| Üretim için pipeline çağrıldığında tetiklenen işlev. | |
| Örnekler: | |
| ```python | |
| >>> import torch | |
| >>> from diffusers import GlmImagePipeline | |
| >>> pipe = GlmImagePipeline.from_pretrained("zai-org/GLM-Image", torch_dtype=torch.bfloat16) | |
| >>> pipe.to("cuda") | |
| >>> prompt = "A photo of an astronaut riding a horse on mars" | |
| >>> image = pipe(prompt).images[0] | |
| >>> image.save("output.png") | |
| ``` | |
| #### encode_prompt[[diffusers.GlmImagePipeline.encode_prompt]] | |
| ```python | |
| encode_prompt(prompt: str | list[str], do_classifier_free_guidance: bool = True, num_images_per_prompt: int = 1, prompt_embeds: typing.Optional[torch.Tensor] = None, negative_prompt_embeds: typing.Optional[torch.Tensor] = None, device: typing.Optional[torch.device] = None, dtype: typing.Optional[torch.dtype] = None, max_sequence_length: int = 2048) | |
| ``` | |
| [Kaynak](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/glm_image/pipeline_glm_image.py#L545) | |
| **Parametreler:** | |
| prompt (`str` veya `list[str]`, *isteğe bağlı*) : kodlanacak istem | |
| do_classifier_free_guidance (`bool`, *isteğe bağlı*, varsayılan `True`) : Sınıflandırıcı serbest yönlendirmenin (classifier free guidance) kullanılıp kullanılmayacağı. | |
| num_images_per_prompt (`int`, *isteğe bağlı*, varsayılan 1) : Her istem için oluşturulması gereken görsel sayısı. Sonuç gömme vektörlerinin yerleştirileceği torch cihazı | |
| prompt_embeds (`torch.Tensor`, *isteğe bağlı*) : Ön oluşturulmuş metin gömme değerleri. Metin girdilerini kolayca ayarlamak için kullanılabilir, *ör.* istem ağırlıklandırması. Sağlanmazsa, metin gömme değerleri `prompt` girdi argümanından oluşturulur. | |
| device : (`torch.device`, *isteğe bağlı*): torch cihazı | |
| dtype : (`torch.dtype`, *isteğe bağlı*): torch dtype | |
| max_sequence_length (`int`, varsayılan `2048`) : Kodlanmış istemdeki maksimum dizi uzunluğu. Diğer değerlere ayarlanabilir ancak daha kötü sonuçlara yol açabilir. | |
| İsteği metin kodlayıcı gizli durumlarına kodlar. | |
| #### generate_prior_tokens[[diffusers.GlmImagePipeline.generate_prior_tokens]] | |
| ```python | |
| generate_prior_tokens(prompt: str | list[str], height: int, width: int, image: list[list[PIL.Image.Image]] | None = None, device: typing.Optional[torch.device] = None, generator: typing.Optional[torch.Generator] = None) | |
| ``` | |
| [Kaynak](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/glm_image/pipeline_glm_image.py#L321) | |
| **Parametreler:** | |
| prompt : Tek bir istem veya istemler listesi | |
| height : Hedef görüntü yüksekliği | |
| width : Hedef görüntü genişliği | |
| image : List[List[PIL.Image]] olarak normalize edilmiş görüntü girdisi. Bu yöntemi çağırmadan önce _validate_and_normalize_images() kullanılarak önceden doğrulanmalıdır. | |
| device : Hedef cihaz | |
| generator : Yeniden üretilebilirlik için rastgele üreteç | |
| **Dönüş:** `Tuple of` | |
| - prior_token_ids: (batch_size, num_tokens) boyutunda, örneklemesi artırılmış (upsampled) önceki token'ları içeren Tensor | |
| - prior_token_image_ids_per_sample: Liste, örnek başına bir tensör içerir. Her tensör, o örnekteki tüm koşul görselleri için yukarı örneklenmiş önceden belirlenmiş token kimliklerini içerir. t2i için None. | |
| - source_image_grid_thw_per_sample: Örnek başına bir tane olmak üzere tensör listesi. Her tensörün şekli (num_condition_images, 3) olup yukarı örneklenmiş ızgara bilgilerini içerir. t2i için None. | |
| AR modelini kullanarak DiT modeli için önceki token'ları üretin. | |
| #### get_glyph_texts[[diffusers.GlmImagePipeline.get_glyph_texts]] | |
| ```python | |
| get_glyph_texts(prompt) | |
| ``` | |
| [Kaynak](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/glm_image/pipeline_glm_image.py#L476) | |
| İfade(ler)den glif metinlerini çıkarır. Toplu işleme için liste listesi döndürür. | |
| ## GlmImagePipelineOutput[[diffusers.pipelines.glm_image.pipeline_output.GlmImagePipelineOutput]] | |
| #### diffusers.pipelines.glm_image.pipeline_output.GlmImagePipelineOutput[[diffusers.pipelines.glm_image.pipeline_output.GlmImagePipelineOutput]] | |
| ```python | |
| diffusers.pipelines.glm_image.pipeline_output.GlmImagePipelineOutput(images: list[PIL.Image.Image] | numpy.ndarray) | |
| ``` | |
| [Kaynak](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/glm_image/pipeline_output.py#L10) | |
| **Parametreler:** | |
| images (`List[PIL.Image.Image]` veya `np.ndarray`) : Uzunluğu `batch_size` olan gürültüsü azaltılmış PIL görselleri listesi veya `(batch_size, height, width, num_channels)` biçiminde bir numpy dizisi. PIL görselleri veya numpy dizisi, difüzyon hattının gürültüsü azaltılmış görsellerini temsil eder. | |
| CogView3 pipeline'leri için çıktı sınıfı. | |
Xet Storage Details
- Size:
- 18.2 kB
- Xet hash:
- 86defbf19ad07612d6f495fb5a522dd7c2642920a0aa55147a5c56f048f53a13
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.