换档时出错tf.tf读写器()至tf.data.tf记录数据

2024-04-25 16:43:19 发布

您现在位置:Python中文网/ 问答频道 /正文

我在练习tfRecord的方法来加快我的训练速度。我读取.tfrecord的代码如下

reader = tf.TFRecordReader()
filenameQueue = tf.train.string_input_producer(['train.tfrecords'])

_, serializedExample = reader.read(filenameQueue)

features = tf.io.parse_single_example(
                                   serializedExample,
                                   features = {
                                   'image_raw': tf.io.FixedLenFeature([], tf.string),
                                   'boxes': tf.io.FixedLenFeature([],tf.string),
                                   })

image = tf.decode_raw(features['image_raw'],tf.uint8)
boxes = tf.decode_raw(features['boxes'],tf.float32)

sess = tf.compat.v1.Session()
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(sess = sess, coord=coord)

for i in range(3):
    _, Box = sess.run([image,boxes])
print(Box)

这很好,只是我保留了get信息,我需要使用tf.data.Dataset来替换{}。我正试图通过替换上述代码的前三行来实现

^{pr2}$

然后,我开始犯错误

TypeError: Failed to convert object of type <class 'tensorflow.python.data.ops.readers.TFRecordDatasetV1'> to Tensor. Contents: <TFRecordDatasetV1 shapes: (), types: tf.string>. Consider casting elements to a supported type.

我在网上找了好几条,但还没找到。可能我错过了一些简单的。。。在


Tags: to代码ioimagestringrawtftrain