0

Exception happened when I add dropout to the input layer.

The exception was mentioned in other threads as well related to another issues and most common suggested solution is to downgrade the Keras version. Is there a workaround for this exception?

def baseline_model() :
    model = Sequential()
    model.add(Dropout(0.35)) #THIS LINE CAUSES THE EXCEPTION
    model.add(Dense(200, input_dim=1200, kernel_initializer='normal', activation='relu'))
    model.add(Dropout(0.8))
    rms = RMSprop(lr = 0.00050)
    model.add(Dense(1, kernel_initializer='normal', activation='sigmoid'))
    model.compile(loss='binary_crossentropy', optimizer=rms, metrics=['accuracy'])
    return model

Model throws the following exception during weight file loading:

ValueError: You are trying to load a weight file containing 2 layers into a model with 0 layers.
today
  • 32,602
  • 8
  • 95
  • 115
Gökhan Yu
  • 25
  • 6

1 Answers1

0

The problem is that you have not assigned the input shape for the first layer:

model.add(Dropout(0.35, input_shape=(1200,)))

And then remove the input_dim argument of second layer as it is redundant.

today
  • 32,602
  • 8
  • 95
  • 115