Closed whk6688 closed 2 years ago
Hi,
thank you for reporting this! Could you please tell us your operating system, the tfdf version and the tensorflow version you're using?
tensorflow-decision-forests 0.2.7
can you help me?
Hi @whk6688,
This error could to indicate that TensorFlow is running in TensorFlow v1 compatibility mode, while TF-DF training is only compatible with TensorFlow v2.
Is it possible that your python env or that other libraries loaded in your colab kernel are depending on TensorFlow v1 (and therefore load TensorFlow with v1 compatibility mode)?
Things to try:
Can you restart your notebook runtime (for example, if you are using colab, this is Menu: Runtime > Restart runtime) and re-run your example while making sure not other library is imported before.
Can you run the following code in a notebook cell:
a = tf.Variable(False, trainable=False, name="is_trained")
if a:
print("A is true")
else:
print("A is false")
yes, i have other projects which use tf v1. when i install tensorflow_decision_forests, it seems install tf v2 automatically. can you tell me how to forbid tf v1? thanks
the result is : 'A is true'
I believe that pip's --force-reinstall might be what you're looking force. Since this is more of a Python question, I'll close this discussion for now.
Traceback (most recent call last): File "mydf.py", line 29, in
model.fit(x=train_ds)
File "/home/wanghaikuan/anaconda3/envs/python37/lib/python3.7/site-packages/tensorflow_decision_forests/keras/core.py", line 1535, in fit
class_weight=class_weight)
File "/home/wanghaikuan/anaconda3/envs/python37/lib/python3.7/site-packages/tensorflow_decision_forests/keras/core.py", line 1668, in _fit_implementation
iterator)
File "/home/wanghaikuan/anaconda3/envs/python37/lib/python3.7/site-packages/tensorflow/python/training/tracking/base.py", line 587, in _method_wrapper
result = method(self, *args, **kwargs)
File "/home/wanghaikuan/anaconda3/envs/python37/lib/python3.7/site-packages/tensorflow/python/util/traceback_utils.py", line 153, in error_handler
raise e.with_traceback(filtered_tb) from None
File "/home/wanghaikuan/anaconda3/envs/python37/lib/python3.7/site-packages/tensorflow_decision_forests/keras/core.py", line 1554, in _consumes_training_examples_until_eof
num_examples += self.train_step(data)
File "/home/wanghaikuan/anaconda3/envs/python37/lib/python3.7/site-packages/tensorflow_decision_forests/keras/core.py", line 1027, in train_step
return self.collect_data_step(data, is_training_example=True)
File "/home/wanghaikuan/anaconda3/envs/python37/lib/python3.7/site-packages/tensorflow_decision_forests/keras/core.py", line 1236, in collect_data_step
if not self._is_trained:
tensorflow.python.framework.errors_impl.OperatorNotAllowedInGraphError: Using a symbolic
tf.Tensor
as a Pythonbool
is not allowed: AutoGraph did convert this function. This might indicate you are trying to use an unsupported feature.-------------------------------------------------------- my code is : import numpy as np import pandas as pd import tensorflow as tf import tensorflow_decision_forests as tfdf
print("Found TF-DF v" + tfdf.version)
dataset_path = tf.keras.utils.get_file( "adult.csv", "https://raw.githubusercontent.com/google/yggdrasil-decision-forests/" "main/yggdrasil_decision_forests/test_data/dataset/adult.csv")
dataset_df = pd.read_csv(dataset_path) # "df" for Pandas's DataFrame.
print("First 3 examples:") print(dataset_df.head(3))
test_indices = np.random.rand(len(dataset_df)) < 0.30 test_ds_pd = dataset_df[test_indices] train_ds_pd = dataset_df[~test_indices] print(f"{len(train_ds_pd)} examples in training" f", {len(test_ds_pd)} examples for testing.")
train_ds = tfdf.keras.pd_dataframe_to_tf_dataset(train_ds_pd, label="income") test_ds = tfdf.keras.pd_dataframe_to_tf_dataset(test_ds_pd, label="income")
model = tfdf.keras.RandomForestModel(verbose=2) model.fit(x=train_ds)
i need you help, thanks