'broken tensorflow keras function

I have this function that used to work and broke when I updated or upgrade to tensorflow 2.

def df_to_dataset(dataframe, shuffle=True, batch_size=32):
  dataframe = dataframe.copy()
  labels = dataframe.pop('SalePrice')
  ds = tf.data.Dataset.from_tensor_slices((dict(dataframe), labels))
  if shuffle:
    ds = ds.shuffle(buffer_size=len(dataframe))
  ds = ds.batch(batch_size)
  return ds

batch_size = 32
train_ds = df_to_dataset(df_train, batch_size=batch_size)
val_ds = df_to_dataset(df_validation, shuffle=False, batch_size=batch_size)
df_test['SalePrice'] = 0
test_ds = df_to_dataset(df_test, shuffle=False, batch_size=batch_size)


feature_columns = []

for col in numericColumns:
  col = feature_column.numeric_column(col)
  feature_columns.append(col)

for col in categoricalColumns:
  col = feature_column.indicator_column(feature_column.categorical_column_with_vocabulary_list(col,df_train[col].unique()))
  feature_columns.append(col)

feature_layer = tf.keras.layers.DenseFeatures(feature_columns)



from tensorflow.keras import optimizers

def build_model():
  model = keras.Sequential([
    feature_layer,
    layers.Dense(10, activation='relu'),
    layers.Dense(10, activation='relu'),
    layers.Dense(1)
  ])

  optimizer = tf.optimizers.RMSprop(learning_rate=lr_schedule)

  model.compile(loss='mse', optimizer=optimizer, metrics=['mse'])
  return model

model = build_model()

When I try to fit the model, I am getting sll types of warnings:

history = model.fit(train_ds, validation_data=val_ds,  epochs=30)

The following warnings are posted and I am not sure if the model is fitted properly:

Epoch 1/30
WARNING:tensorflow:Layers in a Sequential model should only have a single input tensor, but we receive a <class 'dict'> input: {'Id': <tf.Tensor 'ExpandDims_40:0' shape=(None, 1) dtype=int64>, 'MSSubClass': <tf.Tensor 
'ExpandDims_50:0' shape=(None, 1) dtype=float64>, 'MSZoning': <tf.Tensor 
'ExpandDims_51:0' shape=(None, 1) dtype=int32>, 'LotFrontage': <tf.Tensor 
'ExpandDims_47:0' shape=(None, 1) dtype=float64>, 'LotArea': <tf.Tensor 
'ExpandDims_45:0' shape=(None, 1) dtype=float64>, 'Street': <tf.Tensor 
'ExpandDims_67:0' shape=(None, 1) dtype=int32>, 'LotShape': <tf.Tensor 
'ExpandDims_48:0' shape=(None, 1) dtype=float64>, 'LandContour': <tf.Tensor 
'ExpandDims_43:0' shape=(None, 1) dtype=float64>, 'Utilities': <tf.Tensor 
'ExpandDims_70:0' shape=(None, 1) dtype=float64>, 'LotConfig': <tf.Tensor 
'ExpandDims_46:0' shape=(None, 1) dtype=int32>, 'LandSlope': <tf.Tensor 
'ExpandDims_44:0' shape=(None, 1) dtype=float64>, 'Neighborhood': <tf.Tensor 
'ExpandDims_56:0' shape=(None, 1) dtype=int32>, 'Condition1': <tf.Tensor 
'ExpandDims_16:0' shape=(None, 1) dtype=int32>, 'Condition2': <tf.Tensor 
'ExpandDims_17:0' shape=(None, 1) dtype=int32>, 'BldgType': <tf.Tensor 
'ExpandDims_4:0' shape=(None, 1) dtype=int32>, 'HouseStyle': <tf.Tensor 
'ExpandDims_39:0' shape=(None, 1) dtype=int32>, 'OverallQual': <tf.Tensor 
'ExpandDims_59:0' shape=(None, 1) dtype=float64>, 'OverallCond': <tf.Tensor 
'ExpandDims_58:0' shape=(None, 1) dtype=float64>, 'YearBuilt': <tf.Tensor 
'ExpandDims_72:0' shape=(None, 1) dtype=float64>, 'YearRemodAdd': <tf.Tensor 
'ExpandDims_73:0' shape=(None, 1) dtype=float64>, 'RoofStyle': <tf.Tensor 
'ExpandDims_63:0' shape=(None, 1) dtype=int32>, 'RoofMatl': <tf.Tensor 
'ExpandDims_62:0' shape=(None, 1) dtype=int32>, 'Exterior1st': <tf.Tensor 
'ExpandDims_22:0' shape=(None, 1) dtype=int32>, 'Exterior2nd': <tf.Tensor 
'ExpandDims_23:0' shape=(None, 1) dtype=int32>, 'MasVnrType': <tf.Tensor 
'ExpandDims_53:0' shape=(None, 1) dtype=int32>, 'MasVnrArea': <tf.Tensor 
'ExpandDims_52:0' shape=(None, 1) dtype=float64>, 'ExterQual': <tf.Tensor 
'ExpandDims_21:0' shape=(None, 1) dtype=float64>, 'ExterCond': <tf.Tensor 
'ExpandDims_20:0' shape=(None, 1) dtype=float64>, 'Foundation': <tf.Tensor 
'ExpandDims_25:0' shape=(None, 1) dtype=int32>, 'BsmtQual': <tf.Tensor 'ExpandDims_13:0' shape=(None, 1) dtype=float64>, 'BsmtCond': <tf.Tensor 'ExpandDims_5:0' shape=(None, 1) dtype=int64>, 'BsmtExposure': <tf.Tensor 'ExpandDims_6:0' shape=(None, 1) dtype=float64>, 'BsmtFinType1': <tf.Tensor 'ExpandDims_9:0' shape=(None, 1) dtype=float64>, 'BsmtFinSF1': <tf.Tensor 'ExpandDims_7:0' shape=(None, 1) dtype=float64>, 'BsmtFinType2': <tf.Tensor 'ExpandDims_10:0' shape=(None, 1) dtype=float64>, 'BsmtFinSF2': <tf.Tensor 'ExpandDims_8:0' shape=(None, 1) dtype=float64>, 'BsmtUnfSF': <tf.Tensor 'ExpandDims_14:0' shape=(None, 1) dtype=float64>, 'TotalBsmtSF': <tf.Tensor 'ExpandDims_69:0' shape=(None, 1) dtype=float64>, 'Heating': <tf.Tensor 'ExpandDims_37:0' shape=(None, 1) dtype=int32>, 'HeatingQC': <tf.Tensor 'ExpandDims_38:0' shape=(None, 1) dtype=float64>, 'CentralAir': <tf.Tensor 'ExpandDims_15:0' shape=(None, 1) dtype=int32>, 'Electrical': <tf.Tensor 'ExpandDims_18:0' shape=(None, 1) dtype=float64>, '1stFlrSF': <tf.Tensor 'ExpandDims:0' shape=(None, 1) dtype=float64>, '2ndFlrSF': <tf.Tensor 'ExpandDims_1:0' shape=(None, 1) dtype=float64>, 'LowQualFinSF': <tf.Tensor 'ExpandDims_49:0' shape=(None, 1) dtype=float64>, 'GrLivArea': <tf.Tensor 'ExpandDims_35:0' shape=(None, 1) dtype=float64>, 'BsmtFullBath': <tf.Tensor 'ExpandDims_11:0' shape=(None, 1) dtype=float64>, 'BsmtHalfBath': <tf.Tensor 'ExpandDims_12:0' shape=(None, 1) dtype=float64>, 'FullBath': <tf.Tensor 'ExpandDims_26:0' shape=(None, 1) dtype=float64>, 'HalfBath': <tf.Tensor 'ExpandDims_36:0' shape=(None, 1) dtype=float64>, 'BedroomAbvGr': <tf.Tensor 'ExpandDims_3:0' shape=(None, 1) dtype=float64>, 'KitchenAbvGr': <tf.Tensor 'ExpandDims_41:0' shape=(None, 1) dtype=float64>, 'KitchenQual': <tf.Tensor 'ExpandDims_42:0' shape=(None, 1) dtype=float64>, 'TotRmsAbvGrd': <tf.Tensor 'ExpandDims_68:0' shape=(None, 1) dtype=float64>, 'Functional': <tf.Tensor 'ExpandDims_27:0' shape=(None, 1) dtype=float64>, 'Fireplaces': <tf.Tensor 'ExpandDims_24:0' shape=(None, 1) dtype=float64>, 'GarageType': <tf.Tensor 'ExpandDims_33:0' shape=(None, 1) dtype=int32>, 'GarageYrBlt': <tf.Tensor 'ExpandDims_34:0' shape=(None, 1) dtype=float64>, 'GarageFinish': <tf.Tensor 'ExpandDims_31:0' shape=(None, 1) dtype=float64>, 'GarageCars': <tf.Tensor 'ExpandDims_29:0' shape=(None, 1) dtype=float64>, 'GarageArea': <tf.Tensor 'ExpandDims_28:0' shape=(None, 1) dtype=float64>, 'GarageQual': <tf.Tensor 'ExpandDims_32:0' shape=(None, 1) dtype=float64>, 'GarageCond': <tf.Tensor 'ExpandDims_30:0' shape=(None, 1) dtype=float64>, 'PavedDrive': <tf.Tensor 'ExpandDims_60:0' shape=(None, 1) dtype=float64>, 'WoodDeckSF': <tf.Tensor 'ExpandDims_71:0' shape=(None, 1) dtype=float64>, 'OpenPorchSF': <tf.Tensor 'ExpandDims_57:0' shape=(None, 1) dtype=float64>, 'EnclosedPorch': <tf.Tensor 'ExpandDims_19:0' shape=(None, 1) dtype=float64>, '3SsnPorch': <tf.Tensor 'ExpandDims_2:0' shape=(None, 1) dtype=float64>, 'ScreenPorch': <tf.Tensor 'ExpandDims_66:0' shape=(None, 1) dtype=float64>, 'PoolArea': <tf.Tensor 'ExpandDims_61:0' shape=(None, 1) dtype=float64>, 'MiscVal': <tf.Tensor 'ExpandDims_54:0' shape=(None, 1) dtype=float64>, 'MoSold': <tf.Tensor 'ExpandDims_55:0' shape=(None, 1) dtype=float64>, 'YrSold': <tf.Tensor 'ExpandDims_74:0' shape=(None, 1) dtype=float64>, 'SaleType': <tf.Tensor 'ExpandDims_65:0' shape=(None, 1) dtype=int32>, 'SaleCondition': <tf.Tensor 'ExpandDims_64:0' shape=(None, 1) dtype=int32>}
Consider rewriting this model with the Functional API.

I tried to review the tensorflow doc on Google[https://www.tensorflow.org/api_docs/python/tf/keras/Sequential] but can's seem to understand how to repair or rewrite the function to work properly.

Any help or assistance/recommendations with getting it right would be appreciated.



Solution 1:[1]

The Tensorflow documentation has reported the warnings as a normal process and output in some situations: TensorFlow Link

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Johnny