maxpumperla / hyperas

Keras + Hyperopt: A very simple wrapper for convenient hyperparameter optimization
http://maxpumperla.com/hyperas/
MIT License
2.17k stars 316 forks source link

Multi Input Models #207

Open lukaseller opened 5 years ago

lukaseller commented 5 years ago

I am currently trying to implement a setup similar to this one in the keras docs. Meaning i have two inputs, one is a 1D convolutional layer - the other one is a single parameter - and a single output neuron.

My training data is defined as follows: x_train = [series, rsrp] Where series is a (9000,4,5) numpy array and rsrp is also a np array with shape (9000,1). When i try to optimize the model in hyperas i get the following error - even though it works just fine when i fit the model manually:

ValueError: Error when checking model input: the list of Numpy arrays that you are passing to your model is not the size the model exp
ected. Expected to see 2 array(s), but instead got the following list of 1 arrays

Also when I print the shape of x_train inside my create_model function I get the following output:

def create_model(x_train, y_train, x_test, y_test):
    print(len(x_train))
    print(np.shape(x_train[0]))
    print(np.shape(x_train[1]))
    ...
Output: 
9000
(4, 5)
(4, 5)

So it seems to me that the second array rsrp does not reach the create_model function. Is this intented behaviour - because hyperas does not support functional layers - or is there a way to get this up and running?. Thank you very much!

Model setup:

TUPLE = (4,5)
series_input = Input(shape=TUPLE, name="SERIES")
rsrp_input   = Input(shape=[1], name="RSRP")
a_conv = Conv1D(filters=128, kernel_size=2,input_shape=TUPLE)(series_input)
pool = MaxPooling1D(2)(a_conv)
flat = Flatten()(pool)
concat = concatenate([flat, rsrp_input])
x = Dense(64, activation='relu')(concat)
x = Dense(64, activation='relu')(x)
output = Dense(1, name='output')(x)
model = Model([series_input,rsrp_input], output)
model.compile(loss='mean_absolute_error', metrics=['mae'],optimizer='adam')
history = model.fit(x_train, y_train, epochs=50)