'I am running a model based on what i learned at school. I am getting this error for the code - model.fit(x,y,epochs=150,batch_size=10)
Initialising the ANN
model = Sequential()
#adding input layer and first hidden layer
model.add(Dense(32, activation = 'relu', input_dim = 6))
adding second hidden layer
model.add(Dense(units = 32, activation = 'relu'))
#adding third model.add(Dense(units = 32, activation = 'relu'))
#adding output layer model.add(Dense(units = 1))
model.compile(loss = 'mean_squared_error', optimizer='adam', metrics=['accuracy'])
model.fit(x,y,epochs=150,batch_size=10)
The error - Epoch 1/150
ValueError Traceback (most recent call last) in () ----> 1 model.fit(x,y,epochs=150,batch_size=10)
1 frames /usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/func_graph.py in autograph_handler(*args, **kwargs) 1145 except Exception as e: # pylint:disable=broad-except 1146 if hasattr(e, "ag_error_metadata"): -> 1147 raise e.ag_error_metadata.to_exception(e) 1148 else: 1149 raise
ValueError: in user code:
File "/usr/local/lib/python3.7/dist-packages/keras/engine/training.py", line 1021, in train_function *
return step_function(self, iterator)
File "/usr/local/lib/python3.7/dist-packages/keras/engine/training.py", line 1010, in step_function **
outputs = model.distribute_strategy.run(run_step, args=(data,))
File "/usr/local/lib/python3.7/dist-packages/keras/engine/training.py", line 1000, in run_step **
outputs = model.train_step(data)
File "/usr/local/lib/python3.7/dist-packages/keras/engine/training.py", line 859, in train_step
y_pred = self(x, training=True)
File "/usr/local/lib/python3.7/dist-packages/keras/utils/traceback_utils.py", line 67, in error_handler
raise e.with_traceback(filtered_tb) from None
File "/usr/local/lib/python3.7/dist-packages/keras/engine/input_spec.py", line 264, in assert_input_compatibility
raise ValueError(f'Input {input_index} of layer "{layer_name}" is '
ValueError: Input 0 of layer "sequential_3" is incompatible with the layer: expected shape=(None, 6), found shape=(None, 4)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|