Tensorflow / Tflearn ValueError:无法为具有形状'(?, 4, 11, 11)'的张量"input/X:0"提供形状(4,11,11)的值



我有以下错误:

文件"D:\python\WPy64-3740\python-3.7.4.amd64\lib\site-packages\tensorflow\python\client\session.py",第 1149 行,_run str(subfeed_t.get_shape(((((

ValueError:无法为张量"input/X:0"提供形状 (4, 11, 11( 的值,该张量具有形状 '(?, 4, 11, 11(">

我的代码是:

with tf.Graph().as_default():
g=tflearn.input_data(shape=[4,11,11],name='input')
g=tflearn.fully_connected(g,512,activation='relu',name="hidden1")
g=tflearn.fully_connected(g,256,activation='relu',name="hidden2")
g=tflearn.fully_connected(g,121,activation='softmax',name="output")
g=tflearn.regression(g,optimizer='adam',learning_rate=1,metric='R2',loss='categorical_crossentropy')
m=tflearn.DNN(g)
m.fit(train_state,train_nextmove,n_epoch=10,batch_size=50,snapshot_epoch=False,shuffle=True)
x0=train_state[34]
pred0=m.predict(x0)

我自己喜欢这个问题。 其实这个网络的建设是正确的,问题出在倒数第二行:

x0=train_state[34]
pred0=m.predict(x0)

当我将这两行更改为:

x0=[train_state[34]]
pred0=m.predict(x0)

然后它起作用了。

请注意,当训练数据是 (n* 4* 11* 11( 列表时,预测的数据也应遵循相同的格式:不是

(4* 11* 11(,而是 (1* 4* 11* 11(,或 (m* 4* 11* 11(,其中 m 是任意正整数。

相关内容

最新更新