Solved: Abalone Shell Load CSV batch input from dataset

Hi,

The Load CSV data example talks about batching the CSV file, but does not show you how to do it for the Abalone Shell CSV. If you (analogously to the Titanic example) create a dataset from the CSV file and provide it as input to Model.fit you get the error: ‘WARNING:tensorflow:Layers in a Sequential model should only have a single input tensor.’. It took me quite some time to figure out how to do it, but in the end it is a simple as this:

abalone_csv_ds = tf.data.experimental.make_csv_dataset(
    abalone_file_path,
    column_names=["Length", "Diameter", "Height", "Whole weight", "Shucked weight",
           "Viscera weight", "Shell weight", "Age"],
    batch_size=10, # Artificially small to make examples easier to show.
    label_name='Age',
    num_epochs=1,
    ignore_errors=True,)

def pack(features, label):
  return tf.stack(list(features.values()), axis=-1), label

packed_dataset = abalone_csv_ds.map(pack)

Model.fit(packed_dataset, ..)

Regards,
GW