【问题标题】:Tensorflow / Tflearn ValueError: Cannot feed value of shape (4, 11, 11) for Tensor 'input/X:0', which has shape '(?, 4, 11, 11)'Tensorflow / Tflearn ValueError:无法为具有形状“(?,4,11,11)”的张量“输入/ X:0”提供形状(4、11、11)的值
【发布时间】:2020-06-30 15:01:34
【问题描述】:

我有以下错误:

文件“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: 无法为形状为“(?, 4, 11, 11)”的张量“input/X:0”提供形状 (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)

【问题讨论】:

    标签: python tensorflow tflearn


    【解决方案1】:

    我自己解决了这个问题。 其实这个网络的构建是正确的,问题出在倒数第二行:

    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 是任意正整数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-07-23
      • 2019-03-20
      • 1970-01-01
      • 2023-03-19
      • 2018-08-03
      • 1970-01-01
      • 2020-11-18
      相关资源
      最近更新 更多