I am using following simple code to load a csv using tensorflow and perform modeling using keras...
Unable to figure this error!
import tensorflow as tf
train_dataset_fp = tf.keras.utils.get_file(fname=file_path, origin=URL)
columns = ["X","Y"]
features = columns[:-1]
labels = columns[-1]
batch_size = 32
train_dataset = tf.data.experimental.make_csv_dataset(
train_dataset_fp,
batch_size,
column_names = columns,
label_name= labels,
num_epochs=1
)
data_iterator = train_dataset.make_one_shot_iterator()
X_train, Y_train = data_iterator.get_next()
from tensorflow import keras
model = keras.Sequential([
keras.layers.Dense(10, input_shape=[len(X_train)]),
keras.layers.Dense(1)
])
model.compile(loss='mse',
optimizer='adam',
metrics=['mae', 'mse'])
model.summary()
model.fit(X_train, Y_train, epochs=1000, steps_per_epoch=batch_size)
While rest of the code is working fine, i am unable to figure why i am getting dense input error.
The same code works flawlesly if using pandas, i am trying to remove dependencies on other libraries therefore using tensorflow components, but seems to be failing.
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
dense (Dense) (None, 10) 30
_________________________________________________________________
dense_1 (Dense) (None, 1) 11
=================================================================
Total params: 41
Trainable params: 41
Non-trainable params: 0
_________________________________________________________________
Traceback (most recent call last):
File "/Users/abhinavasrivastava/anaconda3/envs/ml/lib/python3.6/site-packages/tensorflow/python/keras/engine/training_utils.py", line 267, in standardize_input_data
for x in names
File "/Users/abhinavasrivastava/anaconda3/envs/ml/lib/python3.6/site-packages/tensorflow/python/keras/engine/training_utils.py", line 267, in <listcomp>
for x in names
KeyError: 'dense_input'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "simple_linear_keras.py", line 47, in <module>
model.fit(X_train, Y_train, epochs=1000, callbacks=[tb], steps_per_epoch=batch_size)
File "/Users/abhinavasrivastava/anaconda3/envs/ml/lib/python3.6/site-packages/tensorflow/python/keras/engine/training.py", line 1536, in fit
validation_split=validation_split)
File "/Users/abhinavasrivastava/anaconda3/envs/ml/lib/python3.6/site-packages/tensorflow/python/keras/engine/training.py", line 992, in _standardize_user_data
class_weight, batch_size)
File "/Users/abhinavasrivastava/anaconda3/envs/ml/lib/python3.6/site-packages/tensorflow/python/keras/engine/training.py", line 1117, in _standardize_weights
exception_prefix='input')
File "/Users/abhinavasrivastava/anaconda3/envs/ml/lib/python3.6/site-packages/tensorflow/python/keras/engine/training_utils.py", line 271, in standardize_input_data
'for each key in: ' + str(names))
ValueError: No data provided for "dense_input". Need data for each key in: ['dense_input']
The error No data provided for "dense_input" means that Keras did not get input data at all or not in the expected format, i.e., in the form of an array which in Python means a numpy array.
Supposing everything else works fine it should help to simply add a line to convert X_train and Y_train:
import numpy as np
X_train = np.array(X_train)
Y_train = np.array(Y_train)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With