I have used tensor-flow for ONE day, but there come some troubles, when I import tensor-flow, there would be AttributeError: 'module' object has no attribute 'variable'
I use Windows10, Python 3.5.3, Anaconda-3 4.4.0
here is my test code:
import tensorflow as tf
my_var = tf.Variable(tf.linspace(10.0, 13.0, 4))
with tf.Session() as sess:
print (sess.run(my_var))
I got this error:
Replace 'variable' with 'Variable', for example following code gives error:
initial_value=tf.random.normal(shape=(2,2))
a = tf.variable(initial_value)
print(a)
but this code gives successful output
initial_value=tf.random.normal(shape=(2,2))
a = tf.Variable(initial_value)
print(a)
It looks like you have written a module, random.py, which shadows the standard library's random module. Try renaming the file and check if the error goes away. You can tell it's importing your random.py at the bottom of the stacktrace you posted.
Related
hello so I was trying to resize and rescale my dataset as shown below l but I encountered this error:
AttributeError: module 'keras.layers' has no attribute 'experimental'
resize_and_rescale= tf.keras.Sequential([
layers.experimental.preprocessing.Resizing(IMAGE_SIZE,IMAGE_SIZE),
layers.experimental.preprocessing.Rescaling(1.0/255)
])
actually I tried adding "tf.keras" in front of my layers line and it worked :
resize_and_rescale= tf.keras.Sequential([
tf.keras.layers.experimental.preprocessing.Resizing(IMAGE_SIZE,IMAGE_SIZE),
tf.keras.layers.experimental.preprocessing.Rescaling(1.0/255)])
thank you !
Yes, if it worked by adding tf.keras.layers, even though you have already imported Keras from TensorFlow earlier, then it is most likely an issue with the importation chain of the libraries rather than the actual block of code. Cross-check how you imported the libraries earlier to reduce redundant importing as you might have done now. Also, this will make your code cleaner.
I am trying to run this code:
from pandas.io.parsers.readers import read_table
from tensorflow.python.ops.gen_io_ops import read_file
t_x, t_y = next(valid_gen)
But I always get this error:
AttributeError: module 'tensorflow' has no attribute 'read_file'.
I found that in many comments they mention that the function has been moved into the tensorflow.io module. Any one can help me to resolve this issue ?
Thanks
I am trying to use the library Deepbrain to extract brains from the entire MRIs scan I am using the code
def Reduce_Brain(img):
img_data = img.get_fdata()
prob = ext.run(img)
print(prob)
img = nib.load('ADNI_002_S_0295.nii')
Reduce_Brain(img)
however, when I tried this I got the error module 'tensorflow' has no attribute 'Session' which I found was an error to do with the wrong version of tensorflow so I then changed the library code as said in the other question (see below). but this produced more errors such as module 'tensorflow' has no attribute 'gfile'
Tensorflow 2.0 - AttributeError: module 'tensorflow' has no attribute 'Session'
https://github.com/iitzco/deepbrain
In TF 2.x you should use tf.compat.v1.Session() instead of tf.Session().
Take a look at Migrate_tf2 guide for more information
To get TF 1.x like behaviour in TF 2.0 add below code
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
I am trying to run some code written in tensorflow v1.0 in tensorflow 2.1 library package. So I have to rewrite some of the code. I have been facing some problem with one line of the codes
LOG_DIR='./'
summary_writer = tf.summary.FileWriter(LOG_DIR)
now I understand that in v2.0, tf.summary has been deprecated and I was to write the new code instead
summary_writer = tf.summary.create_file_writer(LOG_DIR)
but whenever i start to run
logdir = summary_writer.get_logdir()
It gives me an error of
AttributeError: 'ResourceSummaryWriter' object has no attribute 'get_logdir'
I search around and found no solution. What can be the problem? Isn't it just stating the LOG_DIR (which I have done)
Regards
I got the same error, after a long struggling with that, I just solved it.
I just modified the core source "~tensorboard/plugins/projector/init.py"
I got rid of lines 'logdir' and pass the log file path to "summary_writer"
------------------ "~tensorboard/plugins/projector/init.py----------------------
enter image description here
------------------ myapp.py--------------------------------
enter image description here
This code runs on Tensorflow v0.12.1, but fails on my new installation on TF v1.0. Is it that this function is deprecated? What's the function I should use? (Tensorflow up and running so I believe it's not a misconfiguration)
File "***.py", line 115, in trainNetwork
readout_action = tf.reduce_sum(tf.mul(readout, a), reduction_indices = 1)
AttributeError: module 'tensorflow' has no attribute 'mul'
The tf.mul() function has been renamed to tf.multiply() in TensorFlow 1.0.
For your kind information , tf.mul, tf.sub and tf.neg were used in the prior version of tensor-flow. They have been deprecated.
You can instead use tf.multiply, tf.subtract and tf.negative.
Thanks.