(path, synsets_2012, files_to_skip=None)
return num_synset_2012_images
Count the number of images of each class in ILSVRC 2012.

  Returns a dict mapping the WordNet of each class of ILSVRC 2012 to the
  number of its images.
  This assumes that within FLAGS.ilsvrc_2012_data_root there is a directory for
  every 2012 synset, named by that synset's WordNet ID (e.g. n15075141) and
  containing all images of that synset.

  If path contains this dict, it is read and returned, otherwise it is computed
  and stored at path.

  Args:
    path: An optional path to a cache where the computed dict is / may be
      stored.
    synsets_2012: A list of Synsets.
    files_to_skip: A set with the files that repeat in other datasets.

  Returns:
    a dict mapping the WordNet id of each ILSVRC 2012 class to its number of
    images.
Count the number of images of each class in ILSVRC 2012.
Count the number of images of each class in ILSVRC 2012 .
def get_num_synset_2012_images(path, synsets_2012, files_to_skip=None):
  """Count the number of images of each class in ILSVRC 2012.

  Returns a dict mapping the WordNet of each class of ILSVRC 2012 to the
  number of its images.
  This assumes that within FLAGS.ilsvrc_2012_data_root there is a directory for
  every 2012 synset, named by that synset's WordNet ID (e.g. n15075141) and
  containing all images of that synset.

  If path contains this dict, it is read and returned, otherwise it is computed
  and stored at path.

  Args:
    path: An optional path to a cache where the computed dict is / may be
      stored.
    synsets_2012: A list of Synsets.
    files_to_skip: A set with the files that repeat in other datasets.

  Returns:
    a dict mapping the WordNet id of each ILSVRC 2012 class to its number of
    images.
  """
  if path:
    logging.info('Attempting to read number of leaf images from %s...', path)
    if tf.io.gfile.exists(path):
      with tf.io.gfile.GFile(path, 'r') as f:
        num_synset_2012_images = json.load(f)
        logging.info('Successful.')
        return num_synset_2012_images

  logging.info('Unsuccessful. Deriving number of leaf images...')
  if files_to_skip is None:
    files_to_skip = set()
  num_synset_2012_images = {}
  for s_2012 in synsets_2012:
    synset_dir = os.path.join(FLAGS.ilsvrc_2012_data_root, s_2012.wn_id)
    all_files = set(tf.io.gfile.listdir(synset_dir))
    img_files = set([f for f in all_files if f.lower().endswith('jpeg')])
    final_files = img_files - files_to_skip
    skipped_files = all_files - final_files
    if skipped_files:
      logging.info('Synset: %s, files_skipped: %s', s_2012.wn_id, skipped_files)
    # Size of the set difference (-) between listed files and `files_to_skip`.
    num_synset_2012_images[s_2012.wn_id] = len(final_files)

  if path:
    with tf.io.gfile.GFile(path, 'w') as f:
      json.dump(num_synset_2012_images, f, indent=2)

  return num_synset_2012_images
def get_num_synset_2012_images ( path , synsets_2012 , files_to_skip = None ) : if path : logging . info ( 'Attempting to read number of leaf images from %s...' , path ) if tf . io . gfile . exists ( path ) : with tf . io . gfile . GFile ( path , 'r' ) as f : num_synset_2012_images = json . load ( f ) logging . info ( 'Successful.' ) return num_synset_2012_images logging . info ( 'Unsuccessful. Deriving number of leaf images...' ) if files_to_skip is None : files_to_skip = set ( ) num_synset_2012_images = { } for s_2012 in synsets_2012 : synset_dir = os . path . join ( FLAGS . ilsvrc_2012_data_root , s_2012 . wn_id ) all_files = set ( tf . io . gfile . listdir ( synset_dir ) ) img_files = set ( [ f for f in all_files if f . lower ( ) . endswith ( 'jpeg' ) ] ) final_files = img_files - files_to_skip skipped_files = all_files - final_files if skipped_files : logging . info ( 'Synset: %s, files_skipped: %s' , s_2012 . wn_id , skipped_files ) # Size of the set difference (-) between listed files and `files_to_skip`. num_synset_2012_images [ s_2012 . wn_id ] = len ( final_files ) if path : with tf . io . gfile . GFile ( path , 'w' ) as f : json . dump ( num_synset_2012_images , f , indent = 2 ) return num_synset_2012_images