【问题标题】:ValueError: Cannot feed value of shape (64, 200, 75) for Tensor 'TargetsData/Y:0', which has shape '(200, 75)'ValueError:无法为形状为“(200, 75)”的张量“TargetsData/Y:0”提供形状 (64, 200, 75) 的值
【发布时间】:2017-11-29 05:37:36
【问题描述】:

我知道这是一个愚蠢的问题,但我似乎无法弄清楚。我输入一个 (?,200,75) 的 numpy 数组并得到这个错误:

ValueError: Cannot feed value of shape (64, 200, 75) for Tensor 'TargetsData/Y:0', which has shape '(200, 75)'

这是我的代码:

import numpy as np
import tflearn
print("loading features....")
features = np.load("features_xs.npy")
print("loading classes....")
classes = np.load("classes_xs.npy")

symbols = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p'
,'q','r','s','t','u','v','w','x','y','z',
'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U',
'V','W','X','Y','Z','1','2','3','4','5','6','7','8','9','0','.',',',
'!','?',':',';','\'','(',')','-','_',' ','"',]
num_symbols = len(symbols)

input_layer = tflearn.input_data(shape=[None, 200,num_symbols])
input_layer = tflearn.flatten(input_layer)
dense1 = tflearn.fully_connected(input_layer, 1000, activation='tanh',
                                 regularizer='L2', weight_decay=0.001)
dense2 = tflearn.fully_connected(dense1, 2000, activation='tanh',
                                 regularizer='L2', weight_decay=0.001)
dense2 = tflearn.fully_connected(dense2, 1000, activation='tanh',
                                 regularizer='L2', weight_decay=0.001)
dropout2 = tflearn.dropout(dense2, 0.8)
final = tflearn.fully_connected(dropout2, (200*num_symbols), activation='tanh')
reshape = tflearn.reshape(final, [200,num_symbols], name="Reshape")

Adam = tflearn.Adam(learning_rate=0.01)
net = tflearn.regression(reshape, optimizer=Adam,
                         loss='categorical_crossentropy')

# Training
model = tflearn.DNN(net, tensorboard_verbose=0)
model.fit(features, classes, n_epoch=1, show_metric=True, run_id="dense_model")
model.save("model")

num_symbols 是 == 到 75,以防您想知道

我找不到解决方案,请帮忙谢谢。

【问题讨论】:

    标签: tensorflow tflearn


    【解决方案1】:

    运行以下代码:

    print(classes.shape)
    

    您将获得(64, 200, 75) 的输出。但是你的最后一层reshape 的形状是(200, 75)。您必须从 classes 变量中提供形状为 (200, 75) 的值才能解决错误。

    【讨论】:

      猜你喜欢
      • 2021-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-09
      • 2018-04-29
      • 1970-01-01
      • 2022-08-12
      • 1970-01-01
      相关资源
      最近更新 更多