(metadata, paths)
Generates Omniglot examples.
Generates Omniglot examples.
Generates Omniglot examples .
def generate_omniglot_examples(metadata, paths):
  """Generates Omniglot examples."""
  alphabet_paths = itertools.chain(
      (paths['images_background'] / 'images_background').iterdir(),
      (paths['images_evaluation'] / 'images_evaluation').iterdir())
  alphabet_paths = {path.stem: path for path in alphabet_paths}

  image_ids = itertools.count()

  for label, class_name in enumerate(metadata['class_names']):
    match = re.match('(.*)-(character..)', class_name)
    assert match is not None
    character_path = alphabet_paths[match.group(1)] / match.group(2)
    for image_path in character_path.iterdir():
      yield _image_key(next(image_ids), metadata['total_num_examples']), {
          'image': _load_and_process_image(
              image_path=image_path, invert_img=True),
          'format': 'JPEG',
          'filename': image_path.name,
          'label': label,
          'class_name': class_name,
      }
def generate_omniglot_examples ( metadata , paths ) : alphabet_paths = itertools . chain ( ( paths [ 'images_background' ] / 'images_background' ) . iterdir ( ) , ( paths [ 'images_evaluation' ] / 'images_evaluation' ) . iterdir ( ) ) alphabet_paths = { path . stem : path for path in alphabet_paths } image_ids = itertools . count ( ) for label , class_name in enumerate ( metadata [ 'class_names' ] ) : match = re . match ( '(.*)-(character..)' , class_name ) assert match is not None character_path = alphabet_paths [ match . group ( 1 ) ] / match . group ( 2 ) for image_path in character_path . iterdir ( ) : yield _image_key ( next ( image_ids ) , metadata [ 'total_num_examples' ] ) , { 'image' : _load_and_process_image ( image_path = image_path , invert_img = True ) , 'format' : 'JPEG' , 'filename' : image_path . name , 'label' : label , 'class_name' : class_name , }