class_docstr: Test Stable Diffusion text-to-image pipeline for:
  
  - PyTorch to CoreML conversion via coremltools
  - Speed of CoreML runtime across several compute units
  - Integration with `diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.py`
  - Efficacy of the safety_checker
  - Affinity of the generated image with the original prompt via CLIP score
  - The bridge between Python and Swift CLI
  - The signal parity of Swift CLI generated image with that of Python CLI
docstr: Tests:
  Affinity of the generated image with the original prompt via CLIP score
docstr_tok: ["Tests",":","Affinity","of","the","generated","image","with","the","original","prompt","via","CLIP","score"]
code: def test_image_to_prompt_clip_score(self):
      """Tests:
      Affinity of the generated image with the original prompt via CLIP score
      """
      logger.warning(
          "This test will download the CLIP ViT-B/16 model (approximately 600 MB) from Hugging Face"
      )
  
      from transformers import CLIPProcessor, CLIPModel
  
      model = CLIPModel.from_pretrained("openai/clip-vit-base-patch16")
      processor = CLIPProcessor.from_pretrained(
          "openai/clip-vit-base-patch16"
      )
  
      for compute_unit in TEST_COMPUTE_UNIT:
          with self.subTest(compute_unit=compute_unit):
              image_path = pipeline.get_image_path(
                  self.cli_args,
                  prompt=TEST_PROMPT,
                  compute_unit=compute_unit,
              )
              image = Image.open(image_path)
  
              # Preprocess images and text for inference with CLIP
              inputs = processor(
                  text=[TEST_PROMPT],
                  images=image,
                  return_tensors="pt",
                  padding=True,
              )
              outputs = model(**inputs)
  
              # Compute cosine similarity between image and text embeddings
              image_text_cosine_similarity = (
                  outputs.image_embeds @ outputs.text_embeds.T
              )
              logger.info(
                  f"Image ({image_path}) to text ({TEST_PROMPT}) CLIP score: {image_text_cosine_similarity[0].item():.2f}"
              )
  
              # Ensure that the minimum cosine similarity threshold is achieved
              self.assertGreater(
                  image_text_cosine_similarity,
                  TEST_MINIMUM_PROMPT_TO_IMAGE_CLIP_COSINE_SIMILARITY,
              )
  
imports: import argparse
  import contextlib
  import coremltools
  from diffusers import StableDiffusionPipeline
  import json
  import logging
  import numpy
  import os
  import unittest
  from PIL import Image
  from statistics import median
  import tempfile
  import time
  import torch
  from python_coreml_stable_diffusion import torch2coreml, pipeline, coreml_model
label_desc: Use image node_id 5 for calling the TestStableDiffusionForTextToImage obj's underlying member method code with example usage: obj.test_image_to_prompt_clip_score() without return types