(metadata, paths)
Generates VGG Flowers examples.
Generates VGG Flowers examples.
Generates VGG Flowers examples .
def generate_vgg_flower_examples(metadata, paths):
  """Generates VGG Flowers examples."""
  data_path = paths['102flowers'] / 'jpg'

  with paths['imagelabels'].open('rb') as f:
    class_ids = tfds.core.lazy_imports.scipy.io.loadmat(f)['labels'][0]

  image_paths = collections.defaultdict(list)
  for i, class_id in enumerate(class_ids):
    image_paths[class_id].append(data_path / f'image_{i + 1:05d}.jpg')

  image_ids = itertools.count()

  for label, class_name in enumerate(metadata['class_names']):
    for image_path in image_paths[int(class_name.split('.')[0])]:
      yield _image_key(next(image_ids), metadata['total_num_examples']), {
          'image': _load_and_process_image(image_path=image_path),
          'format': 'JPEG',
          'filename': image_path.name,
          'label': label,
          'class_name': class_name,
      }
def generate_vgg_flower_examples ( metadata , paths ) : data_path = paths [ '102flowers' ] / 'jpg' with paths [ 'imagelabels' ] . open ( 'rb' ) as f : class_ids = tfds . core . lazy_imports . scipy . io . loadmat ( f ) [ 'labels' ] [ 0 ] image_paths = collections . defaultdict ( list ) for i , class_id in enumerate ( class_ids ) : image_paths [ class_id ] . append ( data_path / f'image_{i + 1:05d}.jpg' ) image_ids = itertools . count ( ) for label , class_name in enumerate ( metadata [ 'class_names' ] ) : for image_path in image_paths [ int ( class_name . split ( '.' ) [ 0 ] ) ] : yield _image_key ( next ( image_ids ) , metadata [ 'total_num_examples' ] ) , { 'image' : _load_and_process_image ( image_path = image_path ) , 'format' : 'JPEG' , 'filename' : image_path . name , 'label' : label , 'class_name' : class_name , }