Tensorflow 张量数组的形状如何?

Tensorflow 张量数组的形状如何?,tensorflow,Tensorflow,我最近被以下错误消息困扰: ValueError: Cannot feed value of shape (2455040,) for Tensor 'Placeholder:0', which has shape '(2455040, ?)' 通过运行以下代码生成: NUMCLASSES=16 NUMPIXELS=959*640*4 # set up to feed an array of images [images, size_of_image] x = tf.placeholder(t

我最近被以下错误消息困扰:

ValueError: Cannot feed value of shape (2455040,) for Tensor 'Placeholder:0', which has shape '(2455040, ?)'
通过运行以下代码生成:

NUMCLASSES=16
NUMPIXELS=959*640*4
# set up to feed an array of images [images, size_of_image]
x = tf.placeholder(tf.float32, [NUMPIXELS,None])
……德莱西亚

# Define loss and optimizer..why is this 2d?
y_ = tf.placeholder(tf.float32, [None,NUMCLASSES])


sess = tf.InteractiveSession()
tf.global_variables_initializer().run(session=sess)
tl = get_tensor_list()

for f, n in tl:
    str = '/users/me/downloads/train/' + f
    mm = Image.open(str)
    mm = mm.convert('F')
    mma=np.array(mm)
    i = mma.flatten() #now this is an array of floats of size NUMPIXELS 
    sess.run(train_step, feed_dict={x: i, y_: n})  # <<DEATH 
#定义损失和优化器..为什么是2d?
y=tf.placeholder(tf.float32,[None,numclass])
sess=tf.InteractiveSession()
tf.global\u variables\u initializer().run(session=sess)
tl=获取张量列表()
对于tl中的f,n:
str='/users/me/downloads/train/'+f
mm=图像打开(str)
mm=mm.convert('F')
mma=np.数组(mm)
i=mma.flatte()#这是一个大小为NUMPIXELS的浮点数组

run(train_step,feed_dict={x:i,y_:n})#重新调整数组的形状可能会有所帮助

i = mma.flatten().reshape((NUMPIXELS,1))

发生错误的原因是两个张量的秩不同:形状张量(2455040,)的秩为1,而形状张量(2455040,)的秩为2

您可以这样做:

x = tf.placeholder(tf.float32, [None])
x = tf.reshape(x, [NUMPIXELS,-1])

请考虑清楚地写问题。您的示例代码也很模糊。我将再试一次:我声明一个[NUMPIXELS,None]形状的张量,并得到一个[ROWPIX,COLPIX]形状的图像,我将其展平为[NUMPIXELS,],当我将其传递给sess.run()时,它会阻塞。我想问题是:(1)如何将图像的形状强制为[NUMPIXELS];(2) 当张量为[NUMPIXELS,None(=?)]时,为什么形状[NUMPIXELS,]不够好?去过那里,做过,得到了T恤。没有快乐:(NUMPIXELS,)。