1

Is there a way of getting an object of the class Model of keras that selects a class randomly. Truly randomly each time, not only blocking training and evaluating with the initialization weights of the network.

I need to pass a Model to the library keras-rl to make a random agent, to test whether I'm improving or not.

My model definition is:

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))

But this gives me this exception:

ValueError: Dimensions must be equal, but are 1001 and 0 for 'lambda_9/add' (op: 'Add') with input shapes: [?,1001,1], [?,0,1001].
Angelo
  • 575
  • 3
  • 18
  • The code in your example works fine, the error is probably not in those lines, as this lambda has no add like your traceback says. Could you provide a [mcve]? – c2huc2hu Apr 05 '19 at 08:28
  • @c2huc2hu Done, but it has to do with the keras-rl library – Angelo Apr 05 '19 at 08:39

0 Answers0