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


Python dataset_utils.image_to_tfexample方法代碼示例

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


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

示例1: _convert_dataset

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

  Args:
    split_name: The name of the dataset, either 'train' or 'valid'.
    filenames: A list of absolute paths to png images.
    filename_to_class_id: A dictionary from filenames (strings) to class ids
      (integers).
    dataset_dir: The directory where the converted datasets are stored.
  """
  print('Converting the {} split.'.format(split_name))
  # Train and validation splits are both in the train directory.
  if split_name in ['train', 'valid']:
    png_directory = os.path.join(dataset_dir, 'mnist_m', 'mnist_m_train')
  elif split_name == 'test':
    png_directory = os.path.join(dataset_dir, 'mnist_m', 'mnist_m_test')

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

    with tf.Session('') as sess:
      output_filename = _get_output_filename(dataset_dir, split_name)

      with tf.python_io.TFRecordWriter(output_filename) as tfrecord_writer:
        for filename in filenames:
          # Read the filename:
          image_data = tf.gfile.FastGFile(
              os.path.join(png_directory, filename), 'r').read()
          height, width = image_reader.read_image_dims(sess, image_data)

          class_id = filename_to_class_id[filename]
          example = dataset_utils.image_to_tfexample(image_data, 'png', height,
                                                     width, class_id)
          tfrecord_writer.write(example.SerializeToString())

  sys.stdout.write('\n')
  sys.stdout.flush() 
開發者ID:rky0930,項目名稱:yolo_v2,代碼行數:39,代碼來源:download_and_convert_mnist_m.py


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