0

Code:

import numpy as np
import tensorflow as tf


a3dim = np.array([[[1,2],[3,4]],
                  [[5,6],[7,8]]
                 ])

print("a3dim Shape: ", a3dim.shape)

tf_t=tf.convert_to_tensor(a3dim,dtype=tf.float64)

print('tf_t : ',tf_t)
print('tf_t[0][0][0] : ',tf_t[0][0][0])
print('tf_t[1][1][1] : ',tf_t[1][1][1])

print('run(tf_t) : \n', tf.run(tf_t))

When I run this program, I have the following error:

Error:

AttributeError                            Traceback (most recent call last)
<ipython-input-9-3506c45f6784> in <module>()
     15 print('tf_t[1][1][1] : ',tf_t[1][1][1])
     16 
---> 17 print('run(tf_t) : \n', tf.run(tf_t))

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

How do I solve this tensorflow issue? Is it a version problem?

2 Answers 2

1

you have to first create a session to run tf_t then something like session.run(tf_t) would work.

Sign up to request clarification or add additional context in comments.

1 Comment

added with tf_t.Session() as tfs print('run(tf_t) : \n', tfs.run(tf_t)) I have now as error: File "<ipython-input-34-19330f20e031>", line 17 with tf_t.Session() as tfs ^ SyntaxError: invalid syntax
0
import numpy as np
import tensorflow as tf


a3dim = np.array([[[1,2],[3,4]],
                  [[5,6],[7,8]]
                 ])

print("a3dim Shape: ", a3dim.shape)

tf_t=tf.convert_to_tensor(a3dim,dtype=tf.float64)

print('tf_t : ',tf_t)
print('tf_t[0][0][0] : ',tf_t[0][0][0])
print('tf_t[1][1][1] : ',tf_t[1][1][1])
sess=tf.Session()#create session
print('run(tf_t) : \n', sess.run(tf_t))
sess.close()#close session

Tensorflow needs graph and Session to compute. The first step of the startup graph is to create a Session object. If there are no creation parameters, the Session builder will start the default graph. Session manages all resources of the TensorFlow program runtime. The Session needs to be closed after all calculations are completed to help the system recycle resources, otherwise the problem of resource leakage may occur.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.