tflearn例外:Feed dict要求提供名为“ targets”的变量,但尚不存在此类变量

问题描述 投票:0回答:1

[使用tflearn构建CNN,但iam遇到此错误:

    Traceback (most recent call last):
  File "/home/hassan/JPG-PNG-to-MNIST-NN-Format/CNN_network.py", line 55, in <module>
    ({'input' :test_images}, {'targets' :test_labels}), snapshot_step = 500,
  File "/home/hassan/anaconda3/envs/object-detection/lib/python3.7/site-packages/tflearn/models/dnn.py", line 192, in fit
    self.targets)
  File "/home/hassan/anaconda3/envs/object-detection/lib/python3.7/site-packages/tflearn/utils.py", line 331, in feed_dict_builder
    "such variable is known to exist" % key)
Exception: Feed dict asks for variable named 'targets' but no such variable is known to exist

Process finished with exit code 1

网络代码如下:

train_images, train_labels, test_images, test_labels = load_dataset()

convnet = input_data(shape=[None, 28, 28, 1], name='input')

convnet = conv_2d(convnet, 32, 2, activation='relu')

convnet = max_pool_2d(convnet, 2)

convnet = conv_2d(convnet, 64, 2, activation='relu')

convnet = max_pool_2d(convnet, 2)

convnet = fully_connected(convnet, 1024, activation='relu')

convnet = dropout(convnet, 0.4)

convnet = fully_connected(convnet, 24, activation='softmax')

convnet = regression(convnet, optimizer='adam', learning_rate=0.01, loss='categorical_crossentropy')

model = tflearn.DNN(convnet)

model.fit({'input': train_images}, {'target': train_labels}, n_epoch=30,
          validation_set=({'input': test_images}, {'target': test_labels}),
          snapshot_step=500, show_metric=True, run_id='characterOCR')

model.save('CNN.model')

load_dataset是将数据集加载到变量中的函数

python tensorflow conv-neural-network tflearn
1个回答
0
投票

因此,请尝试直接传递参数,而不要传递到字典数据结构内部。

因此而不是代码:

model.fit({'input': train_images}, {'target': train_labels}, n_epoch=30,
      validation_set=({'input': test_images}, {'target': test_labels}),
      snapshot_step=500, show_metric=True, run_id='characterOCR')

它将是:

model.fit(train_images, train_labels, n_epoch=30,
      validation_set=(test_images, test_labels),
      snapshot_step=500, show_metric=True, run_id='characterOCR')

同样的问题,这似乎对我来说是可行的。在此处查看描述解决方案的错误报告:https://github.com/tflearn/tflearn/issues/754

欢呼声

© www.soinside.com 2019 - 2024. All rights reserved.