Image generator for Imagenet 64x64 downsampled images.

  It assumes that the data has been downloaded from
  http://image-net.org/small/*_32x32.tar or
  http://image-net.org/small/*_64x64.tar into tmp_dir.
  Args:
    tmp_dir: path to temporary storage directory.
    training: a Boolean; if true, we use the train set, otherwise the test set.
    size: image size (assumes height and width are same)

  Yields:
    A dictionary representing the images with the following fields:
    * image/encoded: the string encoding the image as JPEG,
    * image/format: the string "jpeg" representing image format,
    * image/height: an integer representing the height,
    * image/width: an integer representing the width.
    Every field is actually a list of the corresponding type.

def imagenet_pixelrnn_generator(tmp_dir,
                                training,
                                size=_IMAGENET_SMALL_IMAGE_SIZE):
  """Image generator for Imagenet 64x64 downsampled images.

  It assumes that the data has been downloaded from
  http://image-net.org/small/*_32x32.tar or
  http://image-net.org/small/*_64x64.tar into tmp_dir.
  Args:
    tmp_dir: path to temporary storage directory.
    training: a Boolean; if true, we use the train set, otherwise the test set.
    size: image size (assumes height and width are same)

  Yields:
    A dictionary representing the images with the following fields:
    * image/encoded: the string encoding the image as JPEG,
    * image/format: the string "jpeg" representing image format,
    * image/height: an integer representing the height,
    * image/width: an integer representing the width.
    Every field is actually a list of the corresponding type.
  """
  if size == _IMAGENET_SMALL_IMAGE_SIZE:
    train_prefix = _IMAGENET_SMALL_TRAIN_PREFIX
    eval_prefix = _IMAGENET_SMALL_EVAL_PREFIX
  else:
    train_prefix = _IMAGENET_MEDIUM_TRAIN_PREFIX
    eval_prefix = _IMAGENET_MEDIUM_EVAL_PREFIX
  prefix = train_prefix if training else eval_prefix
  images_filepath = os.path.join(tmp_dir, prefix)
  image_files = tf.gfile.Glob(images_filepath + "/*")
  height = size
  width = size
  const_label = 0
  for filename in image_files:
    with tf.gfile.Open(filename, "r") as f:
      encoded_image = f.read()
      yield {
          "image/encoded": [encoded_image],
          "image/format": ["png"],
          "image/class/label": [const_label],
          "image/height": [height],
          "image/width": [width]
      }