Skip to content

How to handle variable number of layers? #182

@ben-arnao

Description

@ben-arnao

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions