I am new to machine learning and using tf/keras to build a simple model to train on Adult database which I downloaded from UCI.
The data has 14 features. I am using keras FeatureSpace API to contruct a DNN model. However, whenever I use more than 3 features, I get following error. It doesn’t matter what 3 features I use.
2024-07-17 22:24:38.439243: W tensorflow/core/framework/op_kernel.cc:1817] OP_REQUIRES failed at cast_op.cc:122 : UNIMPLEMENTED: Cast int32 to string is not supported
….
Cast int32 to string is not supported
[[{{node functional_1/Cast_2}}]] [Op:__inference_one_step_on_iterator_82943]
I initially thought that the data might be incorrect and might have int32 in string column, but I have seen all the unique values for all the columns and that doesn’t seem to be the case.
I also tried different combinations of features and as long as these are three features, it works fine but once I add the fourth feature it gives me that error.
Here is my code to create the model and training it:
def construct_feature_space():
feature_space = tf.keras.utils.FeatureSpace(
features = {
'age': tf.keras.utils.FeatureSpace.float_discretized(10),
'workclass': 'string_categorical',
'education_num': tf.keras.utils.FeatureSpace.float_discretized(10),
'race': 'string_categorical',
#'native_country': 'string_categorical',
#'occupation': 'string_categorical'
}
)
return feature_space
def create_fs_model(training_dataset):
feature_space = construct_feature_space()
feature_space.adapt(training_dataset)
inputs = feature_space.get_inputs()
encoded_features = feature_space.get_encoded_features()
h1 = tf.keras.layers.Dense(128, activation="relu")(encoded_features)
outputs = tf.keras.layers.Dense(1, activation='sigmoid', name="high_income")(h1)
model = tf.keras.Model(inputs, outputs)
model.compile(optimizer='adam',loss='mse',metrics=['accuracy'])
print(model.summary())
tf.keras.utils.plot_model(model, 'dnn_model.png', show_shapes=False, rankdir='LR')
return model
model = create_fs_model(train_raw_dataset)
model.compile(optimizer='adam',loss='binary_crossentropy',metrics=['accuracy'])
history = model.fit(train_dataset,
validation_data=eval_dataset,
epochs=10,
steps_per_epoch=2)
Zin Master is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.