Cast string to float is not supported / Failed to convert a NumPy array to a Tensor (Unsupported object type float)
y-sheng opened this issue · comments
Hi,
I am trying to train an autokeras model using a mixed-type of data including float, int and object (category). After running for several successful trails, it crashed with an error message saying either 'Cast string to float is not supported' or 'Failed to convert a NumPy array to a Tensor (Unsupported object type float)'.
I have tried using StructuredDataRegressor and AutoModel, both gave me this error.
I am using autokeras version 1.0.20 on windows in jupyter notebook, using the following lines:
au_try = ak.AutoModel(inputs = ak.StructuredDataInput(),
outputs=ak.RegressionHead(loss='mse',
metrics=[tf.keras.metrics.MeanAbsolutePercentageError()]),
tuner='bayesian',
overwrite=True,
max_trials=100)
The data I am using for training is a csv dataframe containing the following columns and their dtypes:
A category
B float64
C int64
D category
E category
F float64
Could you advise what I should do with this issue, please? Many thanks
I received a similar error when I had tensorflow 2.11.0 installed. The offending line was:
tf.cast(self.weight_decay, variable.dtype)
where self.weight_decay = 'AdamWeightDecay'
and variable.dtype = tf.float32
. I don't have a re-producing script to run but, I hit this when running StructuredDataClassifier.fit
.
Rolling back to tensorflow 2.10.1
resolved this issue for me.
Full stacktrace
``` Out[2]: 'AdamWeightDecay' Out[3]: 2022-12-06 11:32:24.139522: W tensorflow/core/framework/op_kernel.cc:1807] OP_REQUIRES failed at cast_op.cc:121 : UNIMPLEMENTED: Cast string to float is not supported 2022-12-06 11:32:24.141576: W tensorflow/core/framework/op_kernel.cc:1807] OP_REQUIRES failed at cast_op.cc:121 : UNIMPLEMENTED: Cast string to float is not supported Traceback (most recent call last): File "~/repo/.venv/lib/python3.8/site-packages/autokeras/utils/utils.py", line 101, in run_with_adaptive_batch_size history = func(x=x, validation_data=validation_data, **fit_kwargs) File "~/repo/.venv/lib/python3.8/site-packages/autokeras/utils/utils.py", line 89, in batch_size, lambda **kwargs: model.fit(**kwargs), **fit_kwargs File "~/repo/.venv/lib/python3.8/site-packages/keras/utils/traceback_utils.py", line 70, in error_handler raise e.with_traceback(filtered_tb) from None File "~/repo/.venv/lib/python3.8/site-packages/tensorflow/python/eager/execute.py", line 52, in quick_execute tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name, tensorflow.python.framework.errors_impl.UnimplementedError: Graph execution error:Detected at node 'Cast_5' defined at (most recent call last):
File "/Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers/pydev/pydevd.py", line 2141, in
main()
File "/Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers/pydev/pydevd.py", line 2132, in main
globals = debugger.run(setup['file'], None, None, is_module)
File "/Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers/pydev/pydevd.py", line 1441, in run
return self._exec(is_module, entry_point_fn, module_name, file, globals, locals)
File "/Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers/pydev/pydevd.py", line 1448, in _exec
pydev_imports.execfile(file, globals, locals) # execute the script
File "/Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "/repo/qcaan/classifier.py", line 54, in /repo/qcaan/classifier.py", line 41, in train
train(Classifier.AUTO_KERAS)
File "
train_results = classifier.train()
File "/repo/qcaan/classifier.py", line 21, in train/repo/qcaan/classifiers/autokeras.py", line 108, in train
return autokeras.train()
File "
ak_classifier.fit(
File "/repo/.venv/lib/python3.8/site-packages/autokeras/tasks/structured_data.py", line 326, in fit/repo/.venv/lib/python3.8/site-packages/autokeras/tasks/structured_data.py", line 139, in fit
history = super().fit(
File "
history = super().fit(
File "/repo/.venv/lib/python3.8/site-packages/autokeras/auto_model.py", line 292, in fit/repo/.venv/lib/python3.8/site-packages/autokeras/engine/tuner.py", line 193, in search
history = self.tuner.search(
File "
super().search(
File "/repo/.venv/lib/python3.8/site-packages/keras_tuner/engine/base_tuner.py", line 183, in search/repo/.venv/lib/python3.8/site-packages/keras_tuner/engine/tuner.py", line 295, in run_trial
results = self.run_trial(trial, *fit_args, **fit_kwargs)
File "
obj_value = self._build_and_fit_model(trial, *args, **copied_kwargs)
File "/repo/.venv/lib/python3.8/site-packages/autokeras/engine/tuner.py", line 101, in _build_and_fit_model/repo/.venv/lib/python3.8/site-packages/autokeras/utils/utils.py", line 88, in fit_with_adaptive_batch_size
_, history = utils.fit_with_adaptive_batch_size(
File "
history = run_with_adaptive_batch_size(
File "/repo/.venv/lib/python3.8/site-packages/autokeras/utils/utils.py", line 101, in run_with_adaptive_batch_size/repo/.venv/lib/python3.8/site-packages/autokeras/utils/utils.py", line 89, in
history = func(x=x, validation_data=validation_data, **fit_kwargs)
File "
batch_size, lambda **kwargs: model.fit(**kwargs), **fit_kwargs
File "/repo/.venv/lib/python3.8/site-packages/keras/utils/traceback_utils.py", line 65, in error_handler/repo/.venv/lib/python3.8/site-packages/keras/engine/training.py", line 1650, in fit
return fn(*args, **kwargs)
File "
tmp_logs = self.train_function(iterator)
File "/repo/.venv/lib/python3.8/site-packages/keras/engine/training.py", line 1249, in train_function/repo/.venv/lib/python3.8/site-packages/keras/engine/training.py", line 1233, in step_function
return step_function(self, iterator)
File "
outputs = model.distribute_strategy.run(run_step, args=(data,))
File "/repo/.venv/lib/python3.8/site-packages/keras/engine/training.py", line 1222, in run_step/repo/.venv/lib/python3.8/site-packages/keras/engine/training.py", line 1027, in train_step
outputs = model.train_step(data)
File "
self.optimizer.minimize(loss, self.trainable_variables, tape=tape)
File "/repo/.venv/lib/python3.8/site-packages/keras/optimizers/optimizer_experimental/optimizer.py", line 527, in minimize/repo/.venv/lib/python3.8/site-packages/autokeras/keras_layers.py", line 360, in apply_gradients
self.apply_gradients(grads_and_vars)
File "
return super(AdamWeightDecay, self).apply_gradients(
File "/repo/.venv/lib/python3.8/site-packages/keras/optimizers/optimizer_experimental/optimizer.py", line 1140, in apply_gradients/repo/.venv/lib/python3.8/site-packages/keras/optimizers/optimizer_experimental/optimizer.py", line 632, in apply_gradients
return super().apply_gradients(grads_and_vars, name=name)
File "
self._apply_weight_decay(trainable_variables)
File "/repo/.venv/lib/python3.8/site-packages/keras/optimizers/optimizer_experimental/optimizer.py", line 1159, in _apply_weight_decay/repo/.venv/lib/python3.8/site-packages/keras/optimizers/optimizer_experimental/optimizer.py", line 1155, in distributed_apply_weight_decay
File "
for variable in variables:
File "~/repo/.venv/lib/python3.8/site-packages/keras/optimizers/optimizer_experimental/optimizer.py", line 1151, in weight_decay_fn
Node: 'Cast_5'
Cast string to float is not supported
[[{{node Cast_5}}]] [Op:__inference_train_function_333096]
python-BaseException
Process finished with exit code 130 (interrupted by signal 2: SIGINT)
</details>
I received a similar error when I had tensorflow 2.11.0 installed. The offending line was:
tf.cast(self.weight_decay, variable.dtype)
where
self.weight_decay = 'AdamWeightDecay'
andvariable.dtype = tf.float32
. I don't have a re-producing script to run but, I hit this when runningStructuredDataClassifier.fit
.Rolling back to tensorflow
2.10.1
resolved this issue for me.Full stacktrace
Many thanks @erichulburd, using TensorFlow 2.10.1 solved the issue.