在制作自己的数据集时采用了 TFRecord 形式但是在读取时出现了问题
def read_tfRecord (tfRecord_path):
filename_queue = tf.train.string_input_producer ([tfRecord_path], shuffle=True)
reader = tf.TFRecordReader ()
_, serialized_example = reader.read (filename_queue)
features = tf.parse_single_example (serialized_example,
features={
'label': tf.FixedLenFeature ([], tf.string),
'image_raw': tf.FixedLenFeature ([], tf.string),
'height': tf.FixedLenFeature ([], tf.int64),
'width': tf.FixedLenFeature ([], tf.int64),
'channel': tf.FixedLenFeature ([], tf.int64)
})
img = tf.decode_raw (features ['image_raw'], tf.uint8)
label = tf.decode_raw (features ['label'], tf.float32)
height = tf.cast (features ['height'], tf.int32)
width = tf.cast (features ['width'], tf.int32)
channel = tf.cast (features ['channel'], tf.int32)
image = tf.reshape (img, [height, width, channel])
groundtruth = tf.reshape (label, [height, width])
print (height)
print (image)
print (groundtruth)
return image, groundtruth
def get_tfrecord (num, isTrain=True):
if isTrain:
tfRecord_path = tfRecord_train
else:
tfRecord_path = tfRecord_test
img, label = read_tfRecord (tfRecord_path)
img_batch, label_batch = tf.train.shuffle_batch ([img, label],
batch_size = num,
num_threads = 2,
capacity = 10,
min_after_dequeue = 7)
return img, label
代码如图中所示,我在制作 tfrecord 文件的时候保存了图像维度信息,然后在解码以后重新用 tf.reshape () 恢复,但是在用 tf.train.shuffle_batch () 时,报错出现
ValueError: All shapes must be fully defined: [TensorShape ([Dimension (None), Dimension (None), Dimension (None)]), TensorShape ([Dimension (None), Dimension (None)])]
这就很困惑了,我已经 reshape 了但是为什么他说我没有定义!!!!!
求解!!!!
唐青枫, 发表于 2018-8-21 14:51:10