本文介绍了在张量流中用可变大小的输入馈送卷积神经网络的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 feed_dict 参数将具有不同大小的二维 numpy 数组列表传递给卷积神经网络.

I am trying to pass a list of 2d numpy arrays with different sizes to a convolutional neural network using feed_dict parameter.

x = tf.placeholder(tf.float32, [batch_size, None, None, None])y = tf.placeholder(tf.float32, [batch_size, 1])优化器 = tf.train.AdamOptimizer(learning_rate=learning_rate).minimize(cost)optimizer.run(feed_dict={x: batch[0], y: batch[1], keep_prob: 0.5})

我收到以下错误:

ValueError: 使用序列设置数组元素.

我知道 batch[0] 必须包含相同大小的数组.我试图找到一种使用可变大小批量数组应用优化的方法,但所有建议的解决方案都要求调整数组大小,这在我的情况下是不可能的,因为这些数组不是图像并且包含不同大小的 DNA 片段(任何修改对数组的任何元素都会导致丢失重要信息)

I understood that batch[0] has to contain arrays with the same size.I am trying to find a way to apply the optimization using variable sized batch of arrays but all the suggested solutions ask to resize the arrays which is not possible in my case because these arrays are not images and contain DNA Fragments with different sizes (any modifications on any element of the array will cause a lost of important information)

有人有想法吗?

推荐答案

所提供的矩阵需要在行和列之间具有一致的大小.一行或一列的大小不能与其他任何不同.

The matrix provided needs to have a consistent size across rows and columns. One row, or column, can not be a different size than any other.

Matrix #1    Matrix #2
  1 2 3       1 2 3
  None        4 5 6
  None        7 8 9

对矩阵 #1 没有任何操作,这基本上就是你所拥有的.如果你想输入可变大小的矩阵(不同大小的 matices,但大小在行和列中) 这个可能会解决您的问题

No operations will work on Matrix #1, which is essentially what you have. If you want to feed in vairable size matrices (different sizes among matices, but size size with in rows and columns) this may solve your problem

参数:

shape:要馈送的张量的形状(可选).如果形状是未指定,您可以输入任何形状的张量.

shape: The shape of the tensor to be fed (optional). If the shape is not specified, you can feed a tensor of any shape.

或者,如果您正在寻找稀疏张量(tf.sparse_placeholder() -- 未定义的元素被设置为零),这个问题 可能会有所帮助.

Or you if you are looking for a sparse tensor (tf.sparse_placeholder() -- undefined elements are set to zero), this question may help.

这篇关于在张量流中用可变大小的输入馈送卷积神经网络的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 03:06