(metadata, paths)
Generates Quickdraw examples.
Generates Quickdraw examples.
Generates Quickdraw examples .
def generate_quickdraw_examples(metadata, paths):
  """Generates Quickdraw examples."""
  image_ids = itertools.count()

  for label, class_name in enumerate(metadata['class_names']):
    with paths[class_name].open('rb') as f:
      images = np.load(f)

    for i, image in enumerate(images):
      # We make the assumption that the images are square.
      side = int(np.sqrt(image.shape[0]))
      # To load an array as a PIL.Image we must first reshape it to 2D.
      image = tfds.core.lazy_imports.PIL_Image.fromarray(
          image.reshape((side, side))).convert('RGB')
      # Compress to JPEG before writing
      buffer = io.BytesIO()
      image.save(buffer, format='JPEG')
      buffer.seek(0)

      yield _image_key(next(image_ids), metadata['total_num_examples']), {
          'image': buffer,
          'format': 'JPEG',
          'filename': f'{class_name}.npy[{i}]',
          'label': label,
          'class_name': class_name,
      }
def generate_quickdraw_examples ( metadata , paths ) : image_ids = itertools . count ( ) for label , class_name in enumerate ( metadata [ 'class_names' ] ) : with paths [ class_name ] . open ( 'rb' ) as f : images = np . load ( f ) for i , image in enumerate ( images ) : # We make the assumption that the images are square. side = int ( np . sqrt ( image . shape [ 0 ] ) ) # To load an array as a PIL.Image we must first reshape it to 2D. image = tfds . core . lazy_imports . PIL_Image . fromarray ( image . reshape ( ( side , side ) ) ) . convert ( 'RGB' ) # Compress to JPEG before writing buffer = io . BytesIO ( ) image . save ( buffer , format = 'JPEG' ) buffer . seek ( 0 ) yield _image_key ( next ( image_ids ) , metadata [ 'total_num_examples' ] ) , { 'image' : buffer , 'format' : 'JPEG' , 'filename' : f'{class_name}.npy[{i}]' , 'label' : label , 'class_name' : class_name , }