【问题标题】:Not reading records in correctly from TFRecord file?没有从 TFRecord 文件中正确读取记录?
【发布时间】:2017-07-05 17:28:44
【问题描述】:

我是 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 值的张量。而且我似乎无法评估张量并且程序只是挂起的事实不允许我进行调试。

帮助非常感谢

【问题讨论】:

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


    【解决方案1】:

    原来我的数据集中有一个流氓图像,它是72x65...,因此结果是 14040。我用72x72 图像替换它现在可以使用

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-09-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-30
      • 2020-08-28
      • 2020-02-04
      相关资源
      最近更新 更多