I'm new using KNIME, and I'm getting error messages when trying to execute the "KNIME Deep Learning - Train MNIST classifier" example.
I already installed Anaconda, Python 3.7, TensorFlow 2.0.0 and KNIME extensions.
The first one is:
module 'tensorflow' has no attribute 'placeholder' Traceback (most
recent call last): File "", line 21, in
AttributeError: module 'tensorflow' has no attribute 'placeholder'
After that, I found some tutorials and I edited the code in "DL Python Network Creator" like this:
(I added a # to comment line 3, and added lines from 4 to 9)
1 # variable name of the output network: output_network
2
3 # import tensorflow as tf
4 import tensorflow.compat.v1 as tf
5 from TFModel import TFModel
6
7 tf.compat.v1.disable_eager_execution()
8 tf.disable_v2_behavior()
9 sess = tf.compat.v1.Session()
input_shape = (None, 28, 28, 1)
num_classes = 10
# Create a graph
graph = tf.Graph()
# Set the graph as default -> Create every tensor in this graph
with graph.as_default():
# Create an input tensor
x = tf.placeholder(tf.float32, shape=input_shape, name='input')
# Define the graph
# Convolutional Layer #1
conv1 = tf.layers.conv2d(inputs=x, filters=32, kernel_size=[5, 5],
padding="same", activation=tf.nn.relu)
# Pooling Layer #1
pool1 = tf.layers.max_pooling2d(inputs=conv1, pool_size=[2, 2], strides=2)
# Convolutional Layer #2 and Pooling Layer #2
conv2 = tf.layers.conv2d(inputs=pool1, filters=64, kernel_size=[5, 5],
padding="same", activation=tf.nn.relu)
pool2 = tf.layers.max_pooling2d(inputs=conv2, pool_size=[2, 2], strides=2)
# Dense Layer
pool2_flat = tf.reshape(pool2, [-1, 7 * 7 * 64])
dense = tf.layers.dense(inputs=pool2_flat, units=512, activation=tf.nn.relu)
# Create an output tensor
y = tf.layers.dense(dense, num_classes, activation=tf.nn.softmax, name='output')
# Create the output network
output_network = TFModel(inputs={'input': x}, outputs={'output': y}, graph=graph)
And then I got the second error message (line 44 = last line of the code):
Traceback (most recent call last): File "", line 44, in
File "C:Program
FilesKNIMEpluginsorg.knime.dl.tensorflow_4.2.0.v202006241028pyTFModel.py",
line 110, in init
self._save_saved_model(self._sm_path) File "C:Program FilesKNIMEpluginsorg.knime.dl.tensorflow_4.2.0.v202006241028pyTFModel.py",
line 130, in _save_saved_model
with tf.Session(graph=self.graph) as sess: AttributeError: module 'tensorflow' has no attribute 'Session'
My question is: What can I do to solve this issue, since I already tried to reinstall, to update, to downgrade tensorflow (and many other actions), and nothing helped?
I also tried to execute the example available with KERAS (which uses Keras Network Learner) instead of using the example with TensorFlow (which uses DL Python Network Learner).
Do you have any suggestion?
Thanks!!
question from:
https://stackoverflow.com/questions/66053523/how-to-solve-error-integrating-knime-and-python-tensorflow-error