So i made my first tensorflow model and i got this error
I am sure that something is wrong with my version of tensorflow, because this almost the exact same as the example in the official docs
2023-07-18 22:18:33.588749: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
WARNING:tensorflow:From /Users/anirudhmenon/Documents/ML.py:32: categorical_column_with_vocabulary_list (from tensorflow.python.feature_column.feature_column_v2) is deprecated and will be removed in a future version.
Instructions for updating:
Use Keras preprocessing layers instead, either directly or via the `tf.keras.utils.FeatureSpace` utility. Each of `tf.feature_column.*` has a functional equivalent in `tf.keras.layers` for feature preprocessing when training a Keras model.
WARNING:tensorflow:From /Users/anirudhmenon/Documents/ML.py:35: numeric_column (from tensorflow.python.feature_column.feature_column_v2) is deprecated and will be removed in a future version.
Instructions for updating:
Use Keras preprocessing layers instead, either directly or via the `tf.keras.utils.FeatureSpace` utility. Each of `tf.feature_column.*` has a functional equivalent in `tf.keras.layers` for feature preprocessing when training a Keras model.
WARNING:tensorflow:From /Users/anirudhmenon/Documents/ML.py:49: LinearClassifierV2.__init__ (from tensorflow_estimator.python.estimator.canned.linear) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.keras instead.
WARNING:tensorflow:From /Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/tensorflow_estimator/python/estimator/head/head_utils.py:54: BinaryClassHead.__init__ (from tensorflow_estimator.python.estimator.head.binary_class_head) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.keras instead.
WARNING:tensorflow:From /Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/tensorflow_estimator/python/estimator/canned/linear.py:944: Estimator.__init__ (from tensorflow_estimator.python.estimator.estimator) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.keras instead.
WARNING:tensorflow:From /Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/tensorflow_estimator/python/estimator/estimator.py:1844: RunConfig.__init__ (from tensorflow_estimator.python.estimator.run_config) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.keras instead.
WARNING:tensorflow:Using temporary folder as model directory: /var/folders/wy/hbvv3yzs02vdrrsb_wfrwy3r0000gn/T/tmp07bjbpjq
WARNING:tensorflow:From /Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/keras/src/optimizers/legacy/ftrl.py:173: calling Constant.__init__ (from tensorflow.python.ops.init_ops) with dtype is deprecated and will be removed in a future version.
Instructions for updating:
Call initializer instance with the dtype argument instead of passing it to the constructor
WARNING:tensorflow:From /Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/tensorflow_estimator/python/estimator/model_fn.py:250: EstimatorSpec.__new__ (from tensorflow_estimator.python.estimator.model_fn) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.keras instead.
WARNING:tensorflow:From /Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/tensorflow_estimator/python/estimator/estimator.py:1416: NanTensorHook.__init__ (from tensorflow.python.training.basic_session_run_hooks) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.keras instead.
WARNING:tensorflow:From /Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/tensorflow_estimator/python/estimator/estimator.py:1419: LoggingTensorHook.__init__ (from tensorflow.python.training.basic_session_run_hooks) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.keras instead.
WARNING:tensorflow:From /Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/tensorflow/python/training/basic_session_run_hooks.py:232: SecondOrStepTimer.__init__ (from tensorflow.python.training.basic_session_run_hooks) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.keras instead.
WARNING:tensorflow:From /Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/tensorflow_estimator/python/estimator/estimator.py:1456: CheckpointSaverHook.__init__ (from tensorflow.python.training.basic_session_run_hooks) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.keras instead.
WARNING:tensorflow:From /Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/tensorflow/python/training/monitored_session.py:579: StepCounterHook.__init__ (from tensorflow.python.training.basic_session_run_hooks) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.keras instead.
WARNING:tensorflow:From /Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/tensorflow/python/training/monitored_session.py:586: SummarySaverHook.__init__ (from tensorflow.python.training.basic_session_run_hooks) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.keras instead.
2023-07-18 22:18:39.053940: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:375] MLIR V1 optimization pass is not enabled
WARNING:tensorflow:From /Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/tensorflow/python/training/monitored_session.py:1455: SessionRunArgs.__new__ (from tensorflow.python.training.session_run_hook) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.keras instead.
WARNING:tensorflow:From /Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/tensorflow/python/training/monitored_session.py:1454: SessionRunContext.__init__ (from tensorflow.python.training.session_run_hook) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.keras instead.
2023-07-18 22:18:40.073267: W tensorflow/core/framework/op_kernel.cc:1805] OP_REQUIRES failed at cast_op.cc:121 : UNIMPLEMENTED: Cast string to float is not supported
Traceback (most recent call last):
File "/Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/tensorflow/python/client/session.py", line 1379, in _do_call
return fn(*args)
File "/Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/tensorflow/python/client/session.py", line 1362, in _run_fn
return self._call_tf_sessionrun(options, feed_dict, fetch_list,
File "/Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/tensorflow/python/client/session.py", line 1455, in _call_tf_sessionrun
return tf_session.TF_SessionRun_wrapper(self._session, options, feed_dict,
tensorflow.python.framework.errors_impl.UnimplementedError: Cast string to float is not supported
[[{{node linear/linear_model/linear/linear_model/linear/linear_model/age/Cast}}]]
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/anirudhmenon/Documents/ML.py", line 50, in <module>
model.train(train_model)
File "/Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/tensorflow_estimator/python/estimator/estimator.py", line 360, in train
loss = self._train_model(input_fn, hooks, saving_listeners)
File "/Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/tensorflow_estimator/python/estimator/estimator.py", line 1188, in _train_model
return self._train_model_default(input_fn, hooks, saving_listeners)
File "/Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/tensorflow_estimator/python/estimator/estimator.py", line 1219, in _train_model_default
return self._train_with_estimator_spec(estimator_spec, worker_hooks,
File "/Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/tensorflow_estimator/python/estimator/estimator.py", line 1535, in _train_with_estimator_spec
_, loss = mon_sess.run([estimator_spec.train_op, estimator_spec.loss])
File "/Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/tensorflow/python/training/monitored_session.py", line 778, in run
return self._sess.run(
File "/Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/tensorflow/python/training/monitored_session.py", line 1307, in run
return self._sess.run(
File "/Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/tensorflow/python/training/monitored_session.py", line 1397, in run
return self._sess.run(*args, **kwargs)
File "/Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/tensorflow/python/training/monitored_session.py", line 1464, in run
outputs = _WrappedSession.run(
File "/Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/tensorflow/python/training/monitored_session.py", line 1228, in run
return self._sess.run(*args, **kwargs)
File "/Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/tensorflow/python/client/session.py", line 969, in run
result = self._run(None, fetches, feed_dict, options_ptr,
File "/Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/tensorflow/python/client/session.py", line 1192, in _run
results = self._do_run(handle, final_targets, final_fetches,
File "/Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/tensorflow/python/client/session.py", line 1372, in _do_run
return self._do_call(_run_fn, feeds, fetches, targets, options,
File "/Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/tensorflow/python/client/session.py", line 1398, in _do_call
raise type(e)(node_def, op, message) # pylint: disable=no-value-for-parameter
tensorflow.python.framework.errors_impl.UnimplementedError: Graph execution error:
Detected at node 'linear/linear_model/linear/linear_model/linear/linear_model/age/Cast' defined at (most recent call last):
File "/Users/anirudhmenon/Documents/ML.py", line 50, in <module>
model.train(train_model)
File "/Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/tensorflow_estimator/python/estimator/estimator.py", line 360, in train
loss = self._train_model(input_fn, hooks, saving_listeners)
File "/Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/tensorflow_estimator/python/estimator/estimator.py", line 1188, in _train_model
return self._train_model_default(input_fn, hooks, saving_listeners)
File "/Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/tensorflow_estimator/python/estimator/estimator.py", line 1216, in _train_model_default
estimator_spec = self._call_model_fn(features, labels, ModeKeys.TRAIN,
File "/Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/tensorflow_estimator/python/estimator/estimator.py", line 1176, in _call_model_fn
model_fn_results = self._model_fn(features=features, **kwargs)
File "/Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/tensorflow_estimator/python/estimator/canned/linear.py", line 934, in _model_fn
return _linear_model_fn_v2(
File "/Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/tensorflow_estimator/python/estimator/canned/linear.py", line 662, in _linear_model_fn_v2
logits, trainable_variables = _linear_model_fn_builder_v2(
File "/Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/tensorflow_estimator/python/estimator/canned/linear.py", line 599, in _linear_model_fn_builder_v2
logits = linear_model(features)
File "/Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/keras/src/utils/traceback_utils.py", line 65, in error_handler
return fn(*args, **kwargs)
File "/Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/keras/src/engine/training.py", line 569, in __call__
return super().__call__(*args, **kwargs)
File "/Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/keras/src/engine/base_layer_v1.py", line 838, in __call__
outputs = call_fn(cast_inputs, *args, **kwargs)
File "/Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/tensorflow_estimator/python/estimator/canned/linear.py", line 1668, in call
return self.layer(features)
File "/Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/keras/src/engine/base_layer_v1.py", line 838, in __call__
outputs = call_fn(cast_inputs, *args, **kwargs)
File "/Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/tensorflow_estimator/python/estimator/canned/linear.py", line 1489, in call
for column in self._feature_columns:
File "/Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/tensorflow_estimator/python/estimator/canned/linear.py", line 1496, in call
weighted_sum = fc_v2._create_weighted_sum( # pylint: disable=protected-access
Node: 'linear/linear_model/linear/linear_model/linear/linear_model/age/Cast'
Cast string to float is not supported
[[{{node linear/linear_model/linear/linear_model/linear/linear_model/age/Cast}}]]
Original stack trace for 'linear/linear_model/linear/linear_model/linear/linear_model/age/Cast':
File "/Users/anirudhmenon/Documents/ML.py", line 50, in <module>
model.train(train_model)
File "/Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/tensorflow_estimator/python/estimator/estimator.py", line 360, in train
loss = self._train_model(input_fn, hooks, saving_listeners)
File "/Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/tensorflow_estimator/python/estimator/estimator.py", line 1188, in _train_model
return self._train_model_default(input_fn, hooks, saving_listeners)
File "/Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/tensorflow_estimator/python/estimator/estimator.py", line 1216, in _train_model_default
estimator_spec = self._call_model_fn(features, labels, ModeKeys.TRAIN,
File "/Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/tensorflow_estimator/python/estimator/estimator.py", line 1176, in _call_model_fn
model_fn_results = self._model_fn(features=features, **kwargs)
File "/Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/tensorflow_estimator/python/estimator/canned/linear.py", line 934, in _model_fn
return _linear_model_fn_v2(
File "/Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/tensorflow_estimator/python/estimator/canned/linear.py", line 662, in _linear_model_fn_v2
logits, trainable_variables = _linear_model_fn_builder_v2(
File "/Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/tensorflow_estimator/python/estimator/canned/linear.py", line 599, in _linear_model_fn_builder_v2
logits = linear_model(features)
File "/Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/keras/src/utils/traceback_utils.py", line 65, in error_handler
return fn(*args, **kwargs)
File "/Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/keras/src/engine/training.py", line 569, in __call__
return super().__call__(*args, **kwargs)
File "/Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/keras/src/engine/base_layer_v1.py", line 838, in __call__
outputs = call_fn(cast_inputs, *args, **kwargs)
File "/Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/tensorflow_estimator/python/estimator/canned/linear.py", line 1668, in call
return self.layer(features)
File "/Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/keras/src/engine/base_layer_v1.py", line 838, in __call__
outputs = call_fn(cast_inputs, *args, **kwargs)
File "/Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/tensorflow_estimator/python/estimator/canned/linear.py", line 1489, in call
for column in self._feature_columns:
File "/Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/tensorflow/python/autograph/operators/control_flow.py", line 454, in for_stmt
for_fn(iter_, extra_test, body, get_state, set_state, symbol_names, opts)
File "/Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/tensorflow/python/autograph/operators/control_flow.py", line 505, in _py_for_stmt
body(target)
File "/Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/tensorflow/python/autograph/operators/control_flow.py", line 471, in protected_body
original_body(protected_iter)
File "/Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/tensorflow_estimator/python/estimator/canned/linear.py", line 1496, in call
weighted_sum = fc_v2._create_weighted_sum( # pylint: disable=protected-access
File "/Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/tensorflow/python/feature_column/feature_column_v2.py", line 2297, in _create_weighted_sum
return _create_dense_column_weighted_sum(
File "/Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/tensorflow/python/feature_column/feature_column_v2.py", line 2307, in _create_dense_column_weighted_sum
tensor = column.get_dense_tensor(transformation_cache, state_manager)
File "/Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/tensorflow/python/feature_column/feature_column_v2.py", line 2756, in get_dense_tensor
return transformation_cache.get(self, state_manager)
File "/Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/tensorflow/python/feature_column/feature_column_v2.py", line 2516, in get
transformed = column.transform_feature(self, state_manager)
File "/Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/tensorflow/python/feature_column/feature_column_v2.py", line 2729, in transform_feature
return self._transform_input_tensor(input_tensor)
File "/Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/tensorflow/python/feature_column/feature_column_v2.py", line 2704, in _transform_input_tensor
return math_ops.cast(input_tensor, dtypes.float32)
File "/Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/tensorflow/python/util/traceback_utils.py", line 150, in error_handler
return fn(*args, **kwargs)
File "/Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/tensorflow/python/util/dispatch.py", line 1176, in op_dispatch_handler
return dispatch_target(*args, **kwargs)
File "/Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/tensorflow/python/ops/math_ops.py", line 1018, in cast
x = gen_math_ops.cast(x, base_type, name=name)
File "/Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/tensorflow/python/ops/gen_math_ops.py", line 2014, in cast
_, _, _op, _outputs = _op_def_library._apply_op_helper(
File "/Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/tensorflow/python/framework/op_def_library.py", line 795, in _apply_op_helper
op = g._create_op_internal(op_type_name, inputs, dtypes=None,
File "/Users/anirudhmenon/Library/Python/3.9/lib/python/site-packages/tensorflow/python/framework/ops.py", line 3381, in _create_op_internal
ret = Operation.from_node_def(
I could not find any solutions on the web
Edit: This is the code, a slightly modefied version of the official sample code on the tensorflow docs.
from __future__ import absolute_import, division, print_function, unicode_literals
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from IPython.display import clear_output
from six.moves import urllib
import tensorflow.compat.v2.feature_column as fc
import tensorflow as tf
# Load dataset.
dftrain = pd.read_csv('https://storage.googleapis.com/tf-datasets/titanic/train.csv')
dfeval = pd.read_csv('https://storage.googleapis.com/tf-datasets/titanic/eval.csv')
# Convert 'age' column to string type
dftrain['age'] = dftrain['age'].astype(str)
dfeval['age'] = dfeval['age'].astype(str)
y_train = dftrain.pop('survived')
y_eval = dfeval.pop('survived')
clear_output()
CATEGORICAL_COLUMNS = ['sex', 'n_siblings_spouses', 'parch', 'class', 'deck',
'embark_town', 'alone']
NUMERIC_COLUMNS = ['age', 'fare']
feature_columns = []
for feature_name in CATEGORICAL_COLUMNS:
unique = dftrain[feature_name].unique()
feature_columns.append(tf.feature_column.categorical_column_with_vocabulary_list(feature_name, unique))
for feature_name in NUMERIC_COLUMNS:
feature_columns.append(tf.feature_column.numeric_column(feature_name, dtype=tf.float32))
def make_input_fn(label_df, data_df, num_epochs=30, batch_size=627):
def input_fn():
ds = tf.data.Dataset.from_tensor_slices((dict(data_df), label_df))
ds = ds.shuffle(1000)
ds = ds.batch(batch_size).repeat(num_epochs)
return ds
return input_fn
train_model = make_input_fn(y_train, dftrain)
evaluate_model = make_input_fn(y_eval, dfeval, num_epochs=1)
model = tf.estimator.LinearClassifier(feature_columns=feature_columns)
model.train(train_model)
stats = model.evaluate(evaluate_model)
clear_output()
print(stats['accuracy'])