(class_directory,
                                  class_label,
                                  output_path,
                                  invert_img=False,
                                  files_to_skip=None,
                                  skip_on_error=False,
                                  shuffle_with_seed=None)
return written_images_count
Create and write a tf.record file for the images corresponding to a class.

  Args:
    class_directory: the home of the images of class class_label.
    class_label: the label of the class that a record is being made for.
    output_path: the location to write the record.
    invert_img: change black pixels to white ones and vice versa. Used for
      Omniglot for example to change the black-background-white-digit images
      into more conventional-looking white-background-black-digit ones.
    files_to_skip: a set containing names of files that should be skipped if
      present in class_directory.
    skip_on_error: whether to skip an image if there is an issue in reading it.
      The default it to crash and report the original exception.
    shuffle_with_seed: An integer, optional. If provided, the images will be
      shuffled using that seed.

  Returns:
    The number of images written into the records file.
Create and write a tf.record file for the images corresponding to a class.
Create and write a tf . record file for the images corresponding to a class .
def write_tfrecord_from_directory(class_directory,
                                  class_label,
                                  output_path,
                                  invert_img=False,
                                  files_to_skip=None,
                                  skip_on_error=False,
                                  shuffle_with_seed=None):
  """Create and write a tf.record file for the images corresponding to a class.

  Args:
    class_directory: the home of the images of class class_label.
    class_label: the label of the class that a record is being made for.
    output_path: the location to write the record.
    invert_img: change black pixels to white ones and vice versa. Used for
      Omniglot for example to change the black-background-white-digit images
      into more conventional-looking white-background-black-digit ones.
    files_to_skip: a set containing names of files that should be skipped if
      present in class_directory.
    skip_on_error: whether to skip an image if there is an issue in reading it.
      The default it to crash and report the original exception.
    shuffle_with_seed: An integer, optional. If provided, the images will be
      shuffled using that seed.

  Returns:
    The number of images written into the records file.
  """
  if files_to_skip is None:
    files_to_skip = set()
  class_files = []
  filenames = sorted(tf.io.gfile.listdir(class_directory))
  for filename in filenames:
    if filename in files_to_skip:
      logging.info('skipping file %s', filename)
      continue
    filepath = os.path.join(class_directory, filename)
    if tf.io.gfile.isdir(filepath):
      continue
    class_files.append(filepath)

  if shuffle_with_seed is not None:
    rng = np.random.RandomState(shuffle_with_seed)
    rng.shuffle(class_files)

  written_images_count = write_tfrecord_from_image_files(
      class_files,
      class_label,
      output_path,
      invert_img,
      skip_on_error=skip_on_error)

  if not skip_on_error:
    assert len(class_files) == written_images_count
  return written_images_count
def write_tfrecord_from_directory ( class_directory , class_label , output_path , invert_img = False , files_to_skip = None , skip_on_error = False , shuffle_with_seed = None ) : if files_to_skip is None : files_to_skip = set ( ) class_files = [ ] filenames = sorted ( tf . io . gfile . listdir ( class_directory ) ) for filename in filenames : if filename in files_to_skip : logging . info ( 'skipping file %s' , filename ) continue filepath = os . path . join ( class_directory , filename ) if tf . io . gfile . isdir ( filepath ) : continue class_files . append ( filepath ) if shuffle_with_seed is not None : rng = np . random . RandomState ( shuffle_with_seed ) rng . shuffle ( class_files ) written_images_count = write_tfrecord_from_image_files ( class_files , class_label , output_path , invert_img , skip_on_error = skip_on_error ) if not skip_on_error : assert len ( class_files ) == written_images_count return written_images_count