Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
RayVanRaamsdonk opened this issue Feb 27, 2018 · 3 comments
Closed

Comments

@RayVanRaamsdonk
Copy link

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\tensorflow\lib\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\tensorflow\lib\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\tensorflow\lib\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\tensorflow\lib\site-packages\keras\backend_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\tensorflow\lib\site-packages\keras\backend\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'

@sairajk
Copy link

sairajk commented Feb 27, 2018

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.

@RayVanRaamsdonk
Copy link
Author

RayVanRaamsdonk commented Feb 27, 2018 via email

@innkka
Copy link

innkka commented Mar 9, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants