有没有办法获得一个随机选择一个类的类Model
的对象。keras
每次都是真正随机的,不仅用网络的初始化权重阻塞训练和评估。
我需要将 a 传递Model
给图书馆keras-rl
以制作随机代理,以测试我是否在改进。
我的模型定义是:
inp = Input(shape=(1,)+(1, ))
out = Lambda(lambda x: tf.random_uniform((1000,)), output_shape=(1000,), trainable=False) (inp)
model = Model(inputs=inp, outputs=out)
model.compile(loss=huber_loss, optimizer=Adam(lr=lr))
print(model.summary())
# memory
memory = PrioritizedMemory(limit=500000, alpha=.6, start_beta=.4, end_beta=.4, window_length=1)
# policy
policy = LinearAnnealedPolicy(EpsGreedyQPolicy(), attr='eps',
value_max=1., value_min=.1, value_test=.05,
nb_steps=10000)
agent = DQNAgent(model=model, nb_actions=env.action_space.n, memory=memory, nb_steps_warmup=10,enable_double_dqn=False, enable_dueling_network=True,
gamma=.999,target_model_update=1e-2, policy=policy)
agent.compile(optimizer=Adam(lr=lr))
但这给了我这个例外:
ValueError: Dimensions must be equal, but are 1001 and 0 for 'lambda_9/add' (op: 'Add') with input shapes: [?,1001,1], [?,0,1001].