我试图在游戏输入上训练神经网络更准确地说,GTA 5中的自行车是由模型驱动的。它将屏幕帧作为输入并记录我在训练期间输入的密钥。
不断收到此错误消息,我无法弄清楚如何修复它。
以下是错误消息:
>Traceback (most recent call last):
File "training_model.py", line 27, in <module>
show_metric =True, run_id = MODEL_NAME)
File "C:\Users\Aman\Anaconda2\envs\tensorflow\lib\site-packages\tflearn\models\dnn.py", line 184, in fit
self.targets)
File "C:\Users\Aman\Anaconda2\envs\tensorflow\lib\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 'target' but no such variable is known to exist
培训模型的代码:
import numpy as np
from alexnet import alexnet
WIDTH = 80
HEIGHT = 60
EPOCHS = 2
LR = 1e-3
MODEL_NAME = 'pygta5-car-{}-{}-{}-epochs.model'.format(LR, 'alexnetv2', EPOCHS)
model = alexnet(WIDTH, HEIGHT, LR)
train_data = np.load('final_data.npy', encoding = 'bytes')
train_dataset = train_data[:-400]
test_dataset = train_data[-400:]
X = np.array([i[0] for i in train_dataset]).reshape(-1, WIDTH, HEIGHT, 1)
Y = [i[1] for i in train_dataset]
test_x = np.array([i[0] for i in test_dataset]).reshape(-1, WIDTH, HEIGHT, 1)
test_y = [i[1] for i in test_dataset]
model.fit({'input' : X}, {'target' :Y}, n_epoch = EPOCHS, validation_set =
({'input' :test_x}, {'target' :test_y}), snapshot_step = 300,
show_metric =True, run_id = MODEL_NAME)
model.save(MODEL_NAME)
Alexnet模特:
#alexnet.py
import tflearn
from tflearn.layers.conv import conv_2d, max_pool_2d
from tflearn.layers.core import input_data, dropout, fully_connected
from tflearn.layers.estimator import regression
from tflearn.layers.normalization import local_response_normalization
def alexnet(width, height, lr):
network = input_data(shape=[None, width, height, 1], name='input')
network = conv_2d(network, 96, 11, strides=4, activation='relu')
network = max_pool_2d(network, 3, strides=2)
network = local_response_normalization(network)
network = conv_2d(network, 256, 5, activation='relu')
network = max_pool_2d(network, 3, strides=2)
network = local_response_normalization(network)
network = conv_2d(network, 384, 3, activation='relu')
network = conv_2d(network, 384, 3, activation='relu')
network = conv_2d(network, 256, 3, activation='relu')
network = max_pool_2d(network, 3, strides=2)
network = local_response_normalization(network)
network = fully_connected(network, 4096, activation='tanh')
network = dropout(network, 0.5)
network = fully_connected(network, 4096, activation='tanh')
network = dropout(network, 0.5)
network = fully_connected(network, 3, activation='softmax')
network = regression(network, optimizer='momentum',
loss='categorical_crossentropy',
learning_rate=lr, name='targets')
model = tflearn.DNN(network, checkpoint_path='model_alexnet',
max_checkpoints=1, tensorboard_verbose=2, tensorboard_dir='log')
return model
答案 0 :(得分:0)
在模型中,您可以在Feed字典中使用它:{'target' :Y}
。不幸的是,您将目标输出命名为“目标”。将model.fit行更改为this应该有效:
model.fit({'input' : X}, {'targets' :Y}, n_epoch = EPOCHS, validation_set =
({'input' :test_x}, {'targets' :test_y}), snapshot_step = 300,
show_metric =True, run_id = MODEL_NAME)