【问题标题】:parameters value in tensorflow张量流中的参数值
【发布时间】:2017-06-30 10:22:11
【问题描述】:

我是张量流的新手 我尝试将 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(回溯见上文):reshape 的输入是具有 44856 个值的张量,但请求的形状具有 3072

我有两个问题::

1) 我想解释一下这个错误,因为我看不懂,我该如何解决。

2) 有什么好的教程可以解释如何选择一个好的 CNN 参数值

【问题讨论】:

    标签: python tensorflow deep-learning


    【解决方案1】:
    1. 错误的原因是你无法将一个有 44856 个值的张量重塑为一个有 32*32*3 (=3072) 个值的张量。整形是一种简单地改变张量形状而不添加或删除任何值的操作。在您的情况下, tf.strided_slice 以某种方式产生了一个大张量(具有 44856 个值),您无法将其重塑为 32*32*3 张量。如果没有完整的代码和示例文件,我不明白怎么会发生这种情况。
    2. 这个问题超出了 StackOverflow 范围,可能过于笼统,无法给出合理的答案。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-25
      • 2018-09-02
      • 2021-07-03
      相关资源
      最近更新 更多