I am new to Tensorflow and kKeras and I am trying to create a neural network as mentioned in the keras website.
I am trying to create a baseline model with a dataset of my own.
The codes are exactly the same except for a few modification in the fit function like
model.fit([X_input['Name-1'],X_input['Name-2'],X_input['Name-3']],y_output, epochs=num_epochs, validation_data=test_dataset)
and I’ve completly removed the get_train_test_splits from the above mentioned guide and I’ve written a code which gives me a testing and traning set as a dataframe
Here X_input has the X values for training and the test_dataset has both the X and Y values for testing
Whenever I run the model I get the following output
Start training the model...
Epoch 1/400
1/1 ━━━━━━━━━━━━━━━━━━━━ 0s 531ms/step - loss: 4177056.7500 - root_mean_squared_error: 2043.7849
And then immediately an error will throw up saying
ValueError: Layer 'functional_45' expected 3 input(s). Received 1 instead.
I checked the shape of X_input and it is (32,3)
I tried giving it a nested list of size 32 and it too doesn’t work
When I tried removing the validation data it worked but without validation, the rmse error became constant. I’ve narrowed the problem down to the point but I couldn’t rectify it.The shape of validation set is (8,5)
I cant figure out how to feed inputs to these networks.
I used the dataset in the page and included the get_train_test_splits and it worked fine.
Here’s the full error stack if anyone needs it
ValueError Traceback (most recent call last)
Cell In[81], line 3
1 mse_loss = keras.losses.MeanSquaredError()
2 baseline_model = create_baseline_model()
----> 3 run_experiment(baseline_model, mse_loss, train_dataset, test_dataset)
Cell In[80], line 14, in run_experiment(model, loss, train_dataset, test_dataset)
7 model.compile(
8 optimizer=keras.optimizers.RMSprop(learning_rate=learning_rate),
9 loss=loss,
10 metrics=[keras.metrics.RootMeanSquaredError()],
11 )
13 print("Start training the model...")
---> 14 model.fit([X_input['Name-1'],X_input['Name-2'],X_input['Name-3']],y_output, epochs=num_epochs, validation_data=test_dataset)
15 print("Model training finished.")
16 _, rmse = model.evaluate(train_dataset, verbose=0)
File ~AppDataLocalProgramsPythonPython311Libsite-packageskerassrcutilstraceback_utils.py:122, in filter_traceback.<locals>.error_handler(*args, **kwargs)
119 filtered_tb = _process_traceback_frames(e.__traceback__)
120 # To get the full stack trace, call:
121 # `keras.config.disable_traceback_filtering()`
--> 122 raise e.with_traceback(filtered_tb) from None
123 finally:
124 del filtered_tb
File ~AppDataLocalProgramsPythonPython311Libsite-packageskerassrclayersinput_spec.py:156, in assert_input_compatibility(input_spec, inputs, layer_name)
154 inputs = tree.flatten(inputs)
155 if len(input_spec) != len(inputs):
--> 156 raise ValueError(
157 f"Layer '{layer_name}' expected {len(input_spec)} input(s). "
158 f"Received {len(inputs)} instead."
159 )
160 for x in inputs:
161 # Having a shape/dtype is the only commonality of the various
162 # tensor-like objects that may be passed. The most common kind of
163 # invalid type we are guarding for is a Layer instance (Functional API),
164 # which does not have a `shape` attribute.
165 if not hasattr(x, "shape"):
ValueError: Layer 'functional_45' expected 3 input(s). Received 1 instead.
United Dragons is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.