Tensorflow throwing error after previously working ok

I successfully installed the tensorflow environment within Knime and then tested the “KNIME Deep Learning - TensorFlow - Train a MLP” example and it worked fine, even adapted it to an own dataset.
(04_Analytics > 14_Deep_Learning > 03_Tensorflow > 02_Training_Tensorflow_MLP)

So far so good. This was about a week ago.
Now, it suddenly won’t run.
The DL Python Network Creator node throws this error:
AttributeError: module ‘tensorflow’ has no attribute ‘placeholder’
placeholder stems from x = tf.placeholder(tf.float32, shape=(None,num_inputs), name=‘input’)

I haven’t changed anything in my setup, no updates to conda / python nor Knime (extensions).

This is under Win10, Knime 4.2 with Python 3.6.10 for the TF2 python env.
Tested this in Linux, Knime 4.2 , with Python 3.8.3

I suspect it’s something “doh, stupid”, but what? Anyone have an idea/suggestion?

Hi @docminus2,
tf.placeholder is only available in TensorFlow 1 and the example is for TensorFlow 1 (TensorFlow 1 and 2 and not compatible).

To use TensorFlow 1 go to the “Python Deep Learning” preference page and choose ‘Keras’ for the ‘Library used for the “DL Python” scripting nodes’. TensorFlow 1 is available in the environment for Keras.

If you want to use TensorFlow 2: There are also examples for TensorFlow 2 on the KNIME Hub.

1 Like

ah, indeed @bwilhelm, thanks. I was pretty sure I ran the environmet set to TF and not Keras, but maybe I did change it unknowingly.
(I also tried the trick with
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior() )
but that didn’t help either.
But, yes, Keras worked.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.