相关疑难解决方法(0)

如何将TFRecords转换为numpy数组?

主要思想是将TFRecords转换为numpy数组.假设TFRecord存储图像.特别:

  1. 读取TFRecord文件并将每个图像转换为numpy数组.
  2. 将图像写入1.jpg,2.jpg等
  3. 同时,将文件名和标签写入文本文件,如下所示:
    1.jpg 2
    2.jpg 4
    3.jpg 5
    
    Run Code Online (Sandbox Code Playgroud)

我目前使用以下代码:

import tensorflow as tf
import os

def read_and_decode(filename_queue):
  reader = tf.TFRecordReader()
  _, serialized_example = reader.read(filename_queue)
  features = tf.parse_single_example(
      serialized_example,
      # Defaults are not specified since both keys are required.
      features={
          'image_raw': tf.FixedLenFeature([], tf.string),
          'label': tf.FixedLenFeature([], tf.int64),
          'height': tf.FixedLenFeature([], tf.int64),
          'width': tf.FixedLenFeature([], tf.int64),
          'depth': tf.FixedLenFeature([], tf.int64)
      })
  image = tf.decode_raw(features['image_raw'], tf.uint8)
  label = tf.cast(features['label'], tf.int32)
  height = tf.cast(features['height'], tf.int32)
  width = tf.cast(features['width'], tf.int32)
  depth = tf.cast(features['depth'], tf.int32)
  return image, label, …
Run Code Online (Sandbox Code Playgroud)

tensorflow

12
推荐指数
1
解决办法
8736
查看次数

标签 统计

tensorflow ×1