0

I have defined the following model in Keras:

init_weights = he_normal()
main_input = Input(shape=(FEATURE_VECTOR_SIZE,)) #size 54
aux_input = Input(shape=(AUX_FEATURE_VECTOR_SIZE,)) #size 162
merged_input = concatenate([main_input, aux_input])

shared1 = Dense(164, activation='relu', kernel_initializer=init_weights)(merged_input)
shared2 = Dense(150, activation='relu', kernel_initializer=init_weights)(shared1)

main_output = Dense(NUM_ACTIONS, activation='linear', kernel_initializer=init_weights, name='main_output')(shared2)
aux_output = Dense(1, activation='linear', kernel_initializer=init_weights, name='aux_output')(shared2)

rms = RMSprop(lr=ALPHA)
model = Model(inputs=[main_input, aux_input], outputs=[main_output, aux_output])
model.compile(optimizer=rms, loss='mse')

Later on I attempt to use it to make a prediction, as below:

aux_dummy = np.zeros(shape=(AUX_FEATURE_VECTOR_SIZE,))
print(aux_dummy.shape)
print(aux_dummy)
q_vals, _ = model.predict([encode_1_hot(next_state), aux_dummy], batch_size=1)

However, I get an error complaining that the auxiliary input is not of the proper shape (Keras claims it should be shape (162,) and that it is actually shape (1,))

But when I print out the shape I get exactly what it seems to be asking for (see below).

(162,)
[0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
Traceback (most recent call last):
  File "grid_exp.py", line 94, in 
    RL_episode(max_steps)
  File "/Users/ZerkTheMighty/Code/RL2/project/Gridworld/rl_glue.py", line 220, in RL_episode
    rl_step_result = RL_step()
  File "/Users/ZerkTheMighty/Code/RL2/project/Gridworld/rl_glue.py", line 151, in RL_step
    last_action = agent.agent_step(result['reward'],result['state'])
  File "/Users/ZerkTheMighty/Code/RL2/project/Gridworld/grid_agent.py", line 170, in agent_step
    q_vals, _ = model.predict([encode_1_hot(next_state), aux_dummy], batch_size=1)
  File "/Users/ZerkTheMighty/Code/RL2/lib/python2.7/site-packages/keras/engine/training.py", line 1817, in predict
    check_batch_axis=False)
  File "/Users/ZerkTheMighty/Code/RL2/lib/python2.7/site-packages/keras/engine/training.py", line 123, in _standardize_input_data
    str(data_shape))
ValueError: Error when checking : expected input_2 to have shape (162,) but got array with shape (1,)

I'm at a loss as to what I should be changing in order to get this to work, but I have a suspicion that I'm overlooking something obvious. Suggestions?

I'm using Keras 2.1.5, Theano 1.0.1, numpy 1.14.2, and python 2.7.12

1
  • My guess is that something is 1 element object dtype array Commented Mar 23, 2018 at 6:26

2 Answers 2

1

Try with

aux_dummy = np.zeros(shape=(1,AUX_FEATURE_VECTOR_SIZE,))

The first dimension is needed to specify the number of examples given to the model.

Sign up to request clarification or add additional context in comments.

Comments

0

Try this:

 q_vals, _ = model.predict([[encode_1_hot(next_state), aux_dummy]], batch_size=1)

[[]] is like the form that you give

1 Comment

model.predict([[data]]). that is [[]].

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.