當前位置: 首頁>>代碼示例>>Python>>正文


Python dataset_utils.image_to_tfexample方法代碼示例

本文整理匯總了Python中datasets.dataset_utils.image_to_tfexample方法的典型用法代碼示例。如果您正苦於以下問題:Python dataset_utils.image_to_tfexample方法的具體用法?Python dataset_utils.image_to_tfexample怎麽用?Python dataset_utils.image_to_tfexample使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在datasets.dataset_utils的用法示例。


在下文中一共展示了dataset_utils.image_to_tfexample方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _add_to_tfrecord

# 需要導入模塊: from datasets import dataset_utils [as 別名]
# 或者: from datasets.dataset_utils import image_to_tfexample [as 別名]
def _add_to_tfrecord(filename, tfrecord_writer,labels_to_class_names, offset=0):
  """Loads pic data from the filename and writes files to a TFRecord.

  Args:
    filename: The filename of one picture .
    tfrecord_writer: The TFRecord writer to use for writing.
    offset: An offset into the absolute number of images previously written.

  Returns:
    The new offset.
  """
  image = tf.gfile.FastGFile(filename,'r').read()
  label = labels_to_class_names[filename.split('/')[-2]]

  with tf.Graph().as_default():
    with tf.Session('') as sess:
      example = dataset_utils.image_to_tfexample(
            image, b'jpg', _IMAGE_SIZE_HEIGHT, _IMAGE_SIZE_WIDTH, label)
      tfrecord_writer.write(example.SerializeToString())

  return offset + 1 
開發者ID:ucloud,項目名稱:uai-sdk,代碼行數:23,代碼來源:download_and_convert_fer.py

示例2: _add_to_tfrecord

# 需要導入模塊: from datasets import dataset_utils [as 別名]
# 或者: from datasets.dataset_utils import image_to_tfexample [as 別名]
def _add_to_tfrecord(data_filename, labels_filename, num_images,
                     tfrecord_writer):
  """Loads data from the binary MNIST files and writes files to a TFRecord.

  Args:
    data_filename: The filename of the MNIST images.
    labels_filename: The filename of the MNIST labels.
    num_images: The number of images in the dataset.
    tfrecord_writer: The TFRecord writer to use for writing.
  """
  images = _extract_images(data_filename, num_images)
  labels = _extract_labels(labels_filename, num_images)

  shape = (_IMAGE_SIZE, _IMAGE_SIZE, _NUM_CHANNELS)
  with tf.Graph().as_default():
    image = tf.placeholder(dtype=tf.uint8, shape=shape)
    encoded_png = tf.image.encode_png(image)

    with tf.Session('') as sess:
      for j in range(num_images):
        sys.stdout.write('\r>> Converting image %d/%d' % (j + 1, num_images))
        sys.stdout.flush()

        png_string = sess.run(encoded_png, feed_dict={image: images[j]})

        example = dataset_utils.image_to_tfexample(
            png_string, 'png'.encode(), _IMAGE_SIZE, _IMAGE_SIZE, labels[j])
        tfrecord_writer.write(example.SerializeToString()) 
開發者ID:ringringyi,項目名稱:DOTA_models,代碼行數:30,代碼來源:download_and_convert_mnist.py

示例3: _add_to_tfrecord

# 需要導入模塊: from datasets import dataset_utils [as 別名]
# 或者: from datasets.dataset_utils import image_to_tfexample [as 別名]
def _add_to_tfrecord(data_filename, labels_filename, num_images,
                     tfrecord_writer):
  """Loads data from the binary MNIST files and writes files to a TFRecord.

  Args:
    data_filename: The filename of the MNIST images.
    labels_filename: The filename of the MNIST labels.
    num_images: The number of images in the dataset.
    tfrecord_writer: The TFRecord writer to use for writing.
  """
  images = _extract_images(data_filename, num_images)
  labels = _extract_labels(labels_filename, num_images)

  shape = (_IMAGE_SIZE, _IMAGE_SIZE, _NUM_CHANNELS)
  with tf.Graph().as_default():
    image = tf.placeholder(dtype=tf.uint8, shape=shape)
    encoded_png = tf.image.encode_png(image)

    with tf.Session('') as sess:
      for j in range(num_images):
        sys.stdout.write('\r>> Converting image %d/%d' % (j + 1, num_images))
        sys.stdout.flush()

        png_string = sess.run(encoded_png, feed_dict={image: images[j]})

        example = dataset_utils.image_to_tfexample(
            png_string, 'png'.encode(), _IMAGE_SIZE, _IMAGE_SIZE, labels[j],
            _CLASS_NAMES[labels[j]], channels=1)
        tfrecord_writer.write(example.SerializeToString()) 
開發者ID:wenwei202,項目名稱:terngrad,代碼行數:31,代碼來源:download_and_convert_mnist.py

示例4: _add_to_tfrecord

# 需要導入模塊: from datasets import dataset_utils [as 別名]
# 或者: from datasets.dataset_utils import image_to_tfexample [as 別名]
def _add_to_tfrecord(data_filename, num_images,
                     tfrecord_writer):
  """Loads data from the binary svhn files and writes files to a TFRecord.

  Args:
    data_filename: The filename of the svhn images.
    labels_filename: The filename of the svhn labels.
    num_images: The number of images in the dataset.
    tfrecord_writer: The TFRecord writer to use for writing.
  """
  images = _extract_images(data_filename, num_images)
  labels = _extract_labels(data_filename, num_images)

  shape = (_IMAGE_SIZE, _IMAGE_SIZE, _NUM_CHANNELS)
  with tf.Graph().as_default():
    image = tf.placeholder(dtype=tf.uint8, shape=shape)
    encoded_png = tf.image.encode_png(image)

    with tf.Session('') as sess:
      for j in range(num_images):
        sys.stdout.write('\r>> Converting image %d/%d' % (j + 1, num_images))
        sys.stdout.flush()

        png_string = sess.run(encoded_png, feed_dict={image: images[j]})

        example = dataset_utils.image_to_tfexample(
            png_string, 'png'.encode(), _IMAGE_SIZE, _IMAGE_SIZE, labels[j])
        tfrecord_writer.write(example.SerializeToString()) 
開發者ID:jerryli27,項目名稱:TwinGAN,代碼行數:30,代碼來源:download_and_convert_svhn.py

示例5: _add_to_tfrecord

# 需要導入模塊: from datasets import dataset_utils [as 別名]
# 或者: from datasets.dataset_utils import image_to_tfexample [as 別名]
def _add_to_tfrecord(data_filename, labels_filename, num_images,
                     tfrecord_writer):
  """Loads data from the binary MNIST files and writes files to a TFRecord.

  Args:
    data_filename: The filename of the MNIST images.
    labels_filename: The filename of the MNIST labels.
    num_images: The number of images in the dataset.
    tfrecord_writer: The TFRecord writer to use for writing.
  """
  images = _extract_images(data_filename, num_images)
  labels = _extract_labels(labels_filename, num_images)

  shape = (_IMAGE_SIZE, _IMAGE_SIZE, _NUM_CHANNELS)
  with tf.Graph().as_default():
    image = tf.placeholder(dtype=tf.uint8, shape=shape)
    encoded_png = tf.image.encode_png(image)

    with tf.Session('') as sess:
      for j in range(num_images):
        sys.stdout.write('\r>> Converting image %d/%d' % (j + 1, num_images))
        sys.stdout.flush()

        png_string = sess.run(encoded_png, feed_dict={image: images[j]})

        example = dataset_utils.image_to_tfexample(
            png_string, 'png', _IMAGE_SIZE, _IMAGE_SIZE, labels[j])
        tfrecord_writer.write(example.SerializeToString()) 
開發者ID:coderSkyChen,項目名稱:Action_Recognition_Zoo,代碼行數:30,代碼來源:download_and_convert_mnist.py

示例6: _add_to_tfrecord

# 需要導入模塊: from datasets import dataset_utils [as 別名]
# 或者: from datasets.dataset_utils import image_to_tfexample [as 別名]
def _add_to_tfrecord(filename, tfrecord_writer, offset=0):
  """Loads data from the cifar10 pickle files and writes files to a TFRecord.

  Args:
    filename: The filename of the cifar10 pickle file.
    tfrecord_writer: The TFRecord writer to use for writing.
    offset: An offset into the absolute number of images previously written.

  Returns:
    The new offset.
  """
  with tf.gfile.Open(filename, 'rb') as f:
    if sys.version_info < (3,):
      data = cPickle.load(f)
    else:
      data = cPickle.load(f, encoding='bytes')

  images = data[b'data']
  num_images = images.shape[0]

  images = images.reshape((num_images, 3, 32, 32))
  labels = data[b'labels']

  with tf.Graph().as_default():
    image_placeholder = tf.placeholder(dtype=tf.uint8)
    encoded_image = tf.image.encode_png(image_placeholder)

    with tf.Session('') as sess:

      for j in range(num_images):
        sys.stdout.write('\r>> Reading file [%s] image %d/%d' % (
            filename, offset + j + 1, offset + num_images))
        sys.stdout.flush()

        image = np.squeeze(images[j]).transpose((1, 2, 0))
        label = labels[j]

        png_string = sess.run(encoded_image,
                              feed_dict={image_placeholder: image})

        example = dataset_utils.image_to_tfexample(
            png_string, b'png', _IMAGE_SIZE, _IMAGE_SIZE, label)
        tfrecord_writer.write(example.SerializeToString())

  return offset + num_images 
開發者ID:ringringyi,項目名稱:DOTA_models,代碼行數:47,代碼來源:download_and_convert_cifar10.py

示例7: _convert_dataset

# 需要導入模塊: from datasets import dataset_utils [as 別名]
# 或者: from datasets.dataset_utils import image_to_tfexample [as 別名]
def _convert_dataset(split_name, filenames, class_names_to_ids, dataset_dir):
  """Converts the given filenames to a TFRecord dataset.

  Args:
    split_name: The name of the dataset, either 'train' or 'validation'.
    filenames: A list of absolute paths to png or jpg images.
    class_names_to_ids: A dictionary from class names (strings) to ids
      (integers).
    dataset_dir: The directory where the converted datasets are stored.
  """
  assert split_name in ['train', 'validation']

  num_per_shard = int(math.ceil(len(filenames) / float(_NUM_SHARDS)))

  with tf.Graph().as_default():
    image_reader = ImageReader()

    with tf.Session('') as sess:

      for shard_id in range(_NUM_SHARDS):
        output_filename = _get_dataset_filename(
            dataset_dir, split_name, shard_id)

        with tf.python_io.TFRecordWriter(output_filename) as tfrecord_writer:
          start_ndx = shard_id * num_per_shard
          end_ndx = min((shard_id+1) * num_per_shard, len(filenames))
          for i in range(start_ndx, end_ndx):
            sys.stdout.write('\r>> Converting image %d/%d shard %d' % (
                i+1, len(filenames), shard_id))
            sys.stdout.flush()

            # Read the filename:
            image_data = tf.gfile.FastGFile(filenames[i], 'rb').read()
            height, width = image_reader.read_image_dims(sess, image_data)

            class_name = os.path.basename(os.path.dirname(filenames[i]))
            class_id = class_names_to_ids[class_name]

            example = dataset_utils.image_to_tfexample(
                image_data, b'jpg', height, width, class_id)
            tfrecord_writer.write(example.SerializeToString())

  sys.stdout.write('\n')
  sys.stdout.flush() 
開發者ID:ringringyi,項目名稱:DOTA_models,代碼行數:46,代碼來源:download_and_convert_flowers.py


注:本文中的datasets.dataset_utils.image_to_tfexample方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。