Code: Alles auswählen
def build_model(hp):
model = Sequential()
#inputlayer
model.add(Flatten(input_shape=(28,28))) # HIER WIRD input_shape FESTGELEGT
#hidden layer
for i in range(hp.Int("layer_anzahl",1,5)):
model.add(Dense(units = hp.Int("neuronen_anzahl",32,320,32), activation = "relu"))
# outputlayer
model.add(Dense(1))
model.compile(optimizer=tf.keras.optimizers.SGD(learning_rate = hp.Choice("learning_rate",[0.1,0.01,0.001,0.0001])), loss = "mse")
return model
Dennoch kommt folgende
Warnung:
WARNING:tensorflow:Model was constructed with shape (None, 28, 28) for input KerasTensor(type_spec=TensorSpec(shape=(None, 28, 28), dtype=tf.float32, name='flatten_input'), name='flatten_input', description="created by layer 'flatten_input'"), but it was called on an input with incompatible shape (None, 28).
und folgende Fehlermeldung:
ValueError: Exception encountered when calling layer "sequential" (type Sequential).
Input 0 of layer "dense" is incompatible with the layer: expected axis -1 of input shape to have value 784, but received input with shape (None, 28)
Call arguments received by layer "sequential" (type Sequential):
• inputs=tf.Tensor(shape=(None, 28), dtype=float32)
• training=False
• mask=None