我是tensorflow的新手 我尝试将SVHN数据集导入code that represented in this CNN tutorial代码将cifar10数据集作为二进制文件读取,我想用SVHN数据集替换为png图像
我更改了图层和读取数据步骤。此外,我将所有输入图像读入[32,32]
后调整大小batch_size = 128
问题是,当我尝试训练它时,它在输入数据步骤:: 中给出了一个错误子代码显示在下面:::
label_bytes = 1 # 2 for CIFAR-100
result.height = 32
result.width = 32
result.depth = 3
image_bytes = result.height * result.width * result.depth
# Every record consists of a label followed by the image, with a
# fixed number of bytes for each.
record_bytes = label_bytes + image_bytes
# Read a record, getting filenames from the filename_queue. No
# header or footer in the CIFAR-10 format, so we leave header_bytes
# and footer_bytes at their default of 0.
reader = tf.WholeFileReader()
#for binar format (cifar daatset)
###reader = tf.FixedLengthRecordReader(record_bytes=record_bytes) ##using for binary (.bin) format
###reader = tf.TextLineReader() #this for scv formate and I used for .mat format
result.key, value = reader.read(filename_queue)
# Convert from a string to a vector of uint8 that is record_bytes long.
###record_bytes = tf.decode_raw(value, tf.uint8) ## for .bin formate
record_bytes = tf.image.decode_png(value)
result.uint8image = record_bytes
result.uint8image = tf.image.resize_images(result.uint8image, [32,32])
# The first bytes represent the label, which we convert from uint8->int32.
result.label = tf.cast(
tf.strided_slice(record_bytes, [0], [label_bytes]), tf.int32)
# The remaining bytes after the label represent the image, which we reshape
# from [depth * height * width] to [depth, height, width].
depth_major = tf.reshape(
tf.strided_slice(record_bytes, [label_bytes],
[label_bytes + image_bytes]),
[result.depth, result.height, result.width])
# Convert from [depth, height, width] to [height, width, depth].
result.uint8image = tf.transpose(depth_major, [1, 2, 0])
错误也显示在下面::
文件" /home/Desktop/SVHN/cifar10_input.py",第111行,在read_cifar10中 [result.depth,result.height,result.width])
InvalidArgumentError(参见上面的回溯):重塑的输入是一个具有44856值的张量,但请求的形状有3072
我有两个问题::
1)我想要解释这个错误,因为我无法理解它,我该如何解决它。
2)是否有任何好的教程解释如何选择一个好的CNN参数值
答案 0 :(得分:1)
另外,我注意到您正在尝试从record_bytes的第一个字节中提取标签。这似乎是错误的,因为在你的情况下,record_bytes是一个解码的png,而不是一个特殊的cifar记录,它在第一个字节中对图像的标签进行编码。