2017-06-16 48 views
1

值我是新的tensorflow 我尝试导入SVHN数据集code that represented in this CNN tutorial的代码读取cifar10数据集作为二进制和我想SVHN数据集作为png图片来代替它参数tensorflow

我改变了层和读取的数据步骤。此外,我调整所有的输入图像他们阅读后[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参数如何选择价值

回答

1
  1. 错误的原因是,你不能重塑与44856个值的张量与32 * 32张* 3(= 3072)值。整形是一种简单地改变张量形状而不增加或删除任何值的操作。在你的情况下,tf.strided_slice以某种方式产生了一个很大的张量(具有44856个值),你不能将它重塑成32 * 32 * 3张量。没有完整的代码和示例文件,我不知道如何发生。
  2. 这个问题超出了StackOverflow的范围,可能过于宽泛而无法得到合理的答案。

另外,我注意到你正试图从record_bytes的第一个字节中提取标签。这似乎是错误的,因为你的case中的record_bytes是一个解码的png,而不是一个特殊的cifar记录,它在第一个字节中对图像的标签进行编码。

相关问题