class_docstr: Cats vs Dogs.
class_docstr_tok: ["Cats","vs","Dogs","."]
docstr: Generate Cats vs Dogs images and labels given a directory path.
docstr_tok: ["Generate","Cats","vs","Dogs","images","and","labels","given","a","directory","path","."]
code: def _generate_examples(self, archive):
      """Generate Cats vs Dogs images and labels given a directory path."""
      num_skipped = 0
      for fname, fobj in archive:
          res = _NAME_RE.match(fname)
          if not res:  # README file, ...
              continue
          label = res.group(1).lower()
          if tf.compat.as_bytes("JFIF") not in fobj.peek(10):
              num_skipped += 1
              continue
  
          # Some images caused 'Corrupt JPEG data...' messages during training or
          # any other iteration recoding them once fixes the issue (discussion:
          # https://github.com/tensorflow/datasets/issues/2188).
          # Those messages are now displayed when generating the dataset instead.
          img_data = fobj.read()
          img_tensor = tf.image.decode_image(img_data)
          img_recoded = tf.io.encode_jpeg(img_tensor)
  
          # Converting the recoded image back into a zip file container.
          buffer = io.BytesIO()
          with zipfile.ZipFile(buffer, "w") as new_zip:
              new_zip.writestr(fname, img_recoded.numpy())
          new_fobj = zipfile.ZipFile(buffer).open(fname)
  
          record = {
              "image": new_fobj,
              "image/filename": fname,
              "label": label,
          }
          yield fname, record
  
      if num_skipped != _NUM_CORRUPT_IMAGES:
          raise ValueError(
              "Expected %d corrupt images, but found %d"
              % (_NUM_CORRUPT_IMAGES, num_skipped)
          )
      logging.warning(
          "%d images were corrupted and were skipped", num_skipped
      )
  
file_path: datasets/tensorflow_datasets/image_classification/cats_vs_dogs.py
imports: import io
  import re
  import zipfile
  from absl import logging
  from tensorflow_datasets.core.utils.lazy_imports_utils import tensorflow
  import tensorflow_datasets.public_api
label_desc: Use image node_id 3 for calling the CatsVsDogs obj's underlying member method code with example usage: obj._generate_examples(archive) without return types