Keras: AttributeError: module 'tensorflow' has no attribute 'placeholder'

Created on 27 Feb 2018  Â·  3Comments  Â·  Source: keras-team/keras

Hello,
I am relatively new but I did search everywhere for a solution to my problem but can't find any answers
anywhere. I run Windows 10 with Anaconda3 and Python 3 and Tensor flow as a backend to Keras. The
first program I tried worked very well but just today non of my Keras programs work. I get the same
error message for all of my programs: AttributeError: module 'tensorflow' has no attribute 'placeholder'
I don't even know how to get started to fix this kind of error? If anyone could help, it would be a
lifesaver for a science project for my son.
Ray Van Raamsdonk

keras2.py

import numpy as np
from keras.models import Sequential
from keras.layers.core import Activation, Dense
training_data = np.array([[0,0],[0,1],[1,0],[1,1]], "float32")
target_data = np.array([[0],[1],[1],[0]], "float32")
model = Sequential()
model.add(Dense(3, input_dim=2, activation='sigmoid'))
model.add(Dense(1, activation='sigmoid'))
model.compile(loss='mean_squared_error', optimizer='adam', metrics=['binary_accuracy'])
model.fit(training_data, target_data, epochs=5000, verbose=2)

Get the weights

for layer in model.layers:
weights = layer.get_weights() # list of numpy arrays
print(model.predict(training_data))


import keras2

Using TensorFlow backend.

AttributeError Traceback (most recent call last)
in ()
----> 1 import keras2

~\keras2.py in ()
1 #keras2.py
2 import numpy as np
----> 3 from keras.models import Sequential
4 from keras.layers.core import Activation, Dense
5 training_data = np.array([[0,0],[0,1],[1,0],[1,1]], "float32")

c:\users\ray van\anaconda3\envs\tensorflowlib\site-packages\keras__init__.py in ()
1 from __future__ import absolute_import
2
----> 3 from . import utils
4 from . import activations
5 from . import applications

c:\users\ray van\anaconda3\envs\tensorflowlib\site-packages\keras\utils__init__.py in ()
4 from . import data_utils
5 from . import io_utils
----> 6 from . import conv_utils
7
8 # Globally-importable utils.

c:\users\ray van\anaconda3\envs\tensorflowlib\site-packages\keras\utils\conv_utils.py in ()
7 from six.moves import range
8 import numpy as np
----> 9 from .. import backend as K
10
11

c:\users\ray van\anaconda3\envs\tensorflowlib\site-packages\kerasbackend__init__.py in ()
81 elif _BACKEND == 'tensorflow':
82 sys.stderr.write('Using TensorFlow backend.n')
---> 83 from .tensorflow_backend import *
84 else:
85 raise ValueError('Unknown backend: ' + str(_BACKEND))

c:\users\ray van\anaconda3\envs\tensorflowlib\site-packages\kerasbackend\tensorflow_backend.py in ()
3 from __future__ import print_function
4
----> 5 import tensorflow as tf
6 from tensorflow.python.training import moving_averages
7 from tensorflow.python.ops import tensor_array_ops

~\tensorflow.py in ()
16 plt.scatter(xs, ys)
17
---> 18 X = tf.placeholder(tf.float32, shape=(None,), name="x")
19 Y = tf.placeholder(tf.float32, shape=(None,), name="y")
20 w = tf.Variable([0., 0.], name="parameter", trainable=True)

AttributeError: module 'tensorflow' has no attribute 'placeholder'

Most helpful comment

This happened once to me too, but a long time ago. I suggest you uninstall keras and tensorflow, update all packages in anaconda and then reinstall tensorflow and keras. As much as remember, it worked for me at that time.
Let us know if it works.

All 3 comments

This happened once to me too, but a long time ago. I suggest you uninstall keras and tensorflow, update all packages in anaconda and then reinstall tensorflow and keras. As much as remember, it worked for me at that time.
Let us know if it works.

Thank you very much Sai Raj, I will do that.


From: Sai Raj Kishore notifications@github.com
Sent: February 27, 2018 9:39 AM
To: keras-team/keras
Cc: RayVanRaamsdonk; Author
Subject: Re: [keras-team/keras] AttributeError: module 'tensorflow' has no attribute 'placeholder' (#9501)

This happened once to me too, but a long time ago. I suggest you uninstall keras and tensorflow, update all packages in anaconda and then reinstall tensorflow and keras. As much as remember, it worked for me at that time.
Let us know if it works.

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHubhttps://github.com/keras-team/keras/issues/9501#issuecomment-368809264, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AhO-mqThPRAXOvxlQ5GUfqqReJijM52Nks5tY81ggaJpZM4SUhTV.

It could also be a problem when you call your script or folder 'tensorflow' or 'keras'. It imports your script instead of a real keras.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zygmuntz picture zygmuntz  Â·  3Comments

amityaffliction picture amityaffliction  Â·  3Comments

farizrahman4u picture farizrahman4u  Â·  3Comments

oweingrod picture oweingrod  Â·  3Comments

MarkVdBergh picture MarkVdBergh  Â·  3Comments