0

我尝试使用以下代码训练带有gym和tflearn的强化学习代理:

from tflearn import *
import gym
import numpy as np

env = gym.make('CartPole-v0')
x = []
y = []
max_reward = 0

for i in range(1000):
    env.reset()
    while True:
        action = env.action_space.sample()
        observation, reward, done, info = env.step(action)
        if done:
            break
        if reward >= max_reward:
            x.append(observation)
            y.append(np.array([action]))
x = np.asarray(x)
y = np.asarray(y)

net = input_data((None,4))
net = fully_connected(net,8,'softmax')
net = fully_connected(net,16,'softmax')
net = fully_connected(net,32,'softmax')
net = fully_connected(net,64,'softmax')
net = fully_connected(net,128,'softmax')
net = fully_connected(net,64,'softmax')
net = fully_connected(net,32,'softmax')
net = fully_connected(net,16,'softmax')
net = fully_connected(net,8,'softmax')
net = fully_connected(net,4,'softmax')
net = fully_connected(net,2,'softmax')
net = fully_connected(net,1)
net = regression(net,optimizer='adam',learning_rate=0.01,loss='categorical_crossentropy',batch_size=1)
model = DNN(net)

model.fit(x,y,10)
model.save('saved/model.tflearn')

问题是,当模型训练时,损失总是0.0。有人可以帮我解决这个问题吗?

4

1 回答 1

0

不确定你的目标是什么,但categorical_crossentropy它是用于多类分类的损失函数,但你的网络的输出只是一个fully_connected(net,1)具有线性激活的单元,这就是你得到损失 0 的原因。

尝试使用mean_square或什binary_crossentropy至,您会看到不同的损失值。

我会在最后一层使用sigmoid激活,其余的使用 relus。

于 2017-10-23T04:11:38.540 回答