不能从TFRecord文件中正确读取记录?

时间:2017-07-05 17:28:45

标签: python python-3.x tensorflow deep-learning conv-neural-network

我是Tensorflow的新手,并使用了build_image_data.py文件和教程here

我已经建立了一个小的卷积神经网络,用2类来分类我自己的数据集。当我运行我的代码时,我遇到了与重塑操作相关的错误,基本上我的图像是72x72 RGB像素。所以我定义的形状是[72, 72, 3]。然后我得到InvalidArgumentError (see above for traceback): Input to reshape is a tensor with 14040 values, but the requested shape has 15552。现在它应该是15552我认为72*72*3 = 15552的值。如果只有14040那么我的形象可能有问题吗?

我自己拍摄了这些照片,或者是从Google获取这些照片,然后使用java程序将它们全部调整为72x72像素。

我已经尝试eval()图像进入模型但是没有输出,整个事情只是挂了一分钟,直到我关闭它。

sess = tf.InteractiveSession()

filename = "../../dataset/traffic_sign/train-00000-of-00001"

# convert filename to a queue for an input pipeline.
filenameQ = tf.train.string_input_producer([filename], num_epochs=None)

# OUTPUT = AttributeError: 'FIFOQueue' object has no attribute 'eval'
print(filenameQ.eval())

# object to read records
recordReader = tf.TFRecordReader()

# read the full set of features for a single example
key, fullExample = recordReader.read(filenameQ)

# NO OUTPUT: program hangs
print(fullExample.eval())

# parse the full example into its' component features.
features = tf.parse_single_example(
fullExample,
features={
    'image/height': tf.FixedLenFeature([], tf.int64),
    'image/width': tf.FixedLenFeature([], tf.int64),
    'image/colorspace': tf.FixedLenFeature([], dtype=tf.string, default_value=''),
    'image/channels': tf.FixedLenFeature([], tf.int64),
    'image/class/label': tf.FixedLenFeature([], tf.int64),
    'image/class/text': tf.FixedLenFeature([], dtype=tf.string, default_value=''),
    'image/format': tf.FixedLenFeature([], dtype=tf.string, default_value=''),
    'image/filename': tf.FixedLenFeature([], dtype=tf.string, default_value=''),
    'image/encoded': tf.FixedLenFeature([], dtype=tf.string, default_value='')
})

# now we are going to manipulate the label and image features

label = features['image/class/label']
image_buffer = features['image/encoded']

# Decode the jpeg
with tf.name_scope('decode_jpeg', [image_buffer], None):
# decode turns tensor of type string. 0-D the JPEG encoded image
# to tensor of type uint8. 3-D with shape [height, width, channels]
    image = tf.image.decode_jpeg(image_buffer, channels=3)


image = tf.reshape(image, [HEIGHT, WIDTH, NUM_CHANNELS])
image = tf.to_float(image, "ToFloat")

# re-define label as a "one-hot" vector
# it will be [0,1] or [1,0] here.
# This approach can easily be extended to more classes
label = tf.one_hot(label - 1, NUM_CLASSES, dtype=tf.int64)


init = tf.global_variables_initializer()
sess.run(init)
# NO OUTPUT: program hangs
print(label.eval())

当我创建TFRecord文件时,我遵循示例here,标签文件mylabels.txt包含gostop,我的目录结构如下:

traffic_sign/train/go/go*.jpeg
traffic_sign/train/stop/stop*.jpeg
traffic_sign/validation/go/go*.jpeg
traffic_sign/validation/stop/stop*.jpeg

我使用了命令:

python build_image_data.py --train_directory=./train --output_directory=./  \
--validation_directory=./validation --labels_file=mylabels.txt   \
--train_shards=1 --validation_shards=1 --num_threads=1 

记录文件已创建,只包含大量字节。

我不知道如何解决这个问题,我不知道创建数据集时是否犯了错误。但是图片应该是72x72x3,所以我不知道为什么我的模型中存在14040值的张量。事实上我似乎无法评估张量并且程序只是挂起而不允许我调试。

帮助很多人赞赏

1 个答案:

答案 0 :(得分:0)

事实证明我的数据集中有一个流氓图像72x65 ...因此14040结果。我替换为72x72图片,现在正在使用