将形状转换为TensorShape时出错:int()参数必须是字符串,类似字节的对象或数字,而不是“元组”

时间:2019-03-13 10:55:10

标签: python tensorflow keras openai-gym

我正在尝试为此环境构建DQNAgent:

ENV_NAME = 'CartPole-v0'
# Get the environment and extract the number of actions.
env = gym.make(ENV_NAME)
np.random.seed(123)
env.seed(123)
nb_actions = env.action_space.n

然后我调用这样的函数:

agent = buildAgent(nb_actions, env.observation_space.shape)

以如下方式构建代理:

def buildModel(num_actions, state_size):
    input_layer = Input(shape=(1,state_size))
    x = Flatten()(input_layer)
    x = Dense(16, activation='relu')(x)
    x = Dense(16, activation='relu')(x)
    x = Dense(16, activation='relu')(x)
    output = Dense(num_actions, activation='linear')(x)
    model = Model(inputs=input_layer, outputs=output)
    print(model.summary())
    model = Model(inputs=input_layer, outputs=output)
    return model

a = DQNAgent(model=buildModel(mod = model, observation_space = observation_space, action_space = nb_actions),
                      nb_actions = nb_actions,
                      policy = buildPolicy(pol = policy),
                      memory = buildMemory(mem = memory),
                      enable_double_dqn = True,
                      enable_dueling_network = False,
                      gamma=gamma,
                      target_model_update=target_model_update,
                      train_interval=train_interval,
                      delta_clip=delta_clip,
                      pretraining_steps=pretraining_steps,
                      n_step=n_step,
                      large_margin=large_margin,
                      lam_2=lam_2)

但是它返回此错误:

TypeError: Error converting shape to a TensorShape: int() argument must be a string, a bytes-like object or a number, not 'tuple'.

有人知道如何解决吗?

0 个答案:

没有答案