When running a model.fit(train_ds, epochs=10, validation_data=val_ds), I'm receiving the error "ValueError: This model has not yet been built. Build the model first by calling build()
or calling fit()
with some data, or specify an input_shape
argument in the first layer(s) for automatic build."
I'm very confused, because i'm trying to run exactly what the error is suggesting that needs to happen. I've followed the structured data tutorial to the T.
I've verified that the datasets I'm passing contain
data
Any help would be greatly appreciated... I'm spinning my wheels. Tried both tf 2.3.* and 2.4.*
customersDf = pd.DataFrame({"Name":['joe','frank','bob','eleanore'],'target':[1,1,2,2,]})
train, test = train_test_split(customersDf, test_size = 0.2)
train, val = train_test_split(train, test_size = 0.2)
print(len(train))
print(len(test))
print(len(val))
batch_size = 2048
train_ds = df_to_dataset(train, batch_size=batch_size)
val_ds = df_to_dataset(val, shuffle=False, batch_size=batch_size)
test_ds = df_to_dataset(test, shuffle=False, batch_size=batch_size)
feature_columns = []
name1 = feature_column.categorical_column_with_vocabulary_list(
'Name', customersDf.Name.unique())
name1_embedding = feature_column.embedding_column(name1, dimension=12)
feature_columns.append(name1_embedding)
feature_layer = tf.keras.layers.DenseFeatures(feature_columns)
model = tf.keras.Sequential([
feature_layer,
layers.Dense(128, activation='relu'),
layers.Dense(128, activation='relu'),
layers.Dropout(.1),
layers.Dense(1)
])
model.compile(optimizer='adam',
loss=tf.keras.losses.BinaryCrossentropy(from_logits=True),
metrics=['accuracy'])
model.fit(train_ds, epochs=10, validation_data=val_ds)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…