HunterMcGushion / hyperparameter_hunter

Easy hyperparameter optimization and automatic result saving across machine learning algorithms and libraries
MIT License
704 stars 100 forks source link

How to handle variable number of layers? #182

Open ben-arnao opened 5 years ago

ben-arnao commented 5 years ago

Is there a good way to make # of layers a parameter?

I noticed if i do something like the following

def build_fn(input_shape):
    model = Sequential([
        Dense(Integer(50, 150), input_shape=input_shape, activation='relu'),
        Dropout(Real(0.2, 0.7)),
    ])

    for x in range(Integer(0, 10)):
        model.add(Dense(Integer(50, 150), activation='relu'))
        model.add(Dropout(Real(0.2, 0.7)))

    model.add(Dense(1, activation=Categorical(['sigmoid', 'softmax'])))

    model.compile(
        optimizer='adam',
        loss='binary_crossentropy', metrics=['accuracy']
    )
    return model

Results in an error TypeError: 'Integer' object cannot be interpreted as an integer

However i think this a more fundamental question as to how multiple layers are handled. The experiment will have a different number of parameters based on how much layers are chosen.