MCPcopy Create free account
hub / github.com/adobe-research/custom-diffusion / CustomDiffusionPipeline

Class CustomDiffusionPipeline

src/diffusers_model_pipeline.py:367–500  ·  view source on GitHub ↗

r""" Pipeline for custom diffusion model. This model inherits from [`DiffusionPipeline`]. Check the superclass documentation for the generic methods the library implements for all the pipelines (such as downloading or saving, running on a particular device, etc.). Args: vae

Source from the content-addressed store, hash-verified

365
366
367class CustomDiffusionPipeline(StableDiffusionPipeline):
368 r"""
369 Pipeline for custom diffusion model.
370
371 This model inherits from [`DiffusionPipeline`]. Check the superclass documentation for the generic methods the
372 library implements for all the pipelines (such as downloading or saving, running on a particular device, etc.).
373
374 Args:
375 vae ([`AutoencoderKL`]):
376 Variational Auto-Encoder (VAE) Model to encode and decode images to and from latent representations.
377 text_encoder ([`CLIPTextModel`]):
378 Frozen text-encoder. Stable Diffusion uses the text portion of
379 [CLIP](https://huggingface.co/docs/transformers/model_doc/clip#transformers.CLIPTextModel), specifically
380 the [clip-vit-large-patch14](https://huggingface.co/openai/clip-vit-large-patch14) variant.
381 tokenizer (`CLIPTokenizer`):
382 Tokenizer of class
383 [CLIPTokenizer](https://huggingface.co/docs/transformers/v4.21.0/en/model_doc/clip#transformers.CLIPTokenizer).
384 unet ([`UNet2DConditionModel`]): Conditional U-Net architecture to denoise the encoded image latents.
385 scheduler ([`SchedulerMixin`]):
386 A scheduler to be used in combination with `unet` to denoise the encoded image latents.
387 safety_checker ([`StableDiffusionSafetyChecker`]):
388 Classification module that estimates whether generated images could be considered offensive or harmful.
389 Please, refer to the [model card](https://huggingface.co/runwayml/stable-diffusion-v1-5) for details.
390 feature_extractor ([`CLIPFeatureExtractor`]):
391 Model that extracts features from generated images to be used as inputs for the `safety_checker`.
392 modifier_token: list of new modifier tokens added or to be added to text_encoder
393 modifier_token_id: list of id of new modifier tokens added or to be added to text_encoder
394 """
395 _optional_components = ["safety_checker", "feature_extractor", "modifier_token"]
396
397 def __init__(
398 self,
399 vae: AutoencoderKL,
400 text_encoder: CLIPTextModel,
401 tokenizer: CLIPTokenizer,
402 unet: UNet2DConditionModel,
403 scheduler: SchedulerMixin,
404 safety_checker: StableDiffusionSafetyChecker,
405 feature_extractor: CLIPFeatureExtractor,
406 requires_safety_checker: bool = True,
407 modifier_token: list = [],
408 modifier_token_id: list = [],
409 ):
410 super().__init__(vae,
411 text_encoder,
412 tokenizer,
413 unet,
414 scheduler,
415 safety_checker,
416 feature_extractor,
417 requires_safety_checker=requires_safety_checker)
418
419 # change attn class
420 self.modifier_token = modifier_token
421 self.modifier_token_id = modifier_token_id
422
423 def add_token(self, initializer_token):
424 initializer_token_id = []

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected