• Register
0 votes
3.1k views

Problem :

I am new to Python and Tensorflow so I just simply typed the following code :

import tensorflow as tf
print(tf.__version__)
# Build a dataflow graph.
c = tf.constant([[1.0, 2.0], [3.0, 4.0]])
d = tf.constant([[1.0, 1.0], [0.0, 1.0]])
e = tf.matmul(c, d)
# Constructing a `Session` to execute the graph.
sess = tf.compat.v1.Session()
# Executing the graph and storing the value that `e` represents in `result`.
result = sess.run(e)

But it is giving me following error:

2.0.0-beta1
I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
Traceback (most recent call last):
  File "/Users/yupng/Documents/Dissertation/kmnist/kminst_v1.0.py", line 14, in <module>
    result = sess.run(e)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 950, in run
    run_metadata_ptr)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1098, in _run
    raise RuntimeError('The Session graph is empty.  Add operations to the '
RuntimeError: The Session graph is empty.  Add operations to the graph before calling run().
Process finished with exit code 1

How can I fix this error?

6 5 3
6,930 points

1 Answer

0 votes

Solution :

The TF 2.0 supports eager execution it means you need not explicitly create the session and run the code in it. So the simplest solution is as follows:

import tensorflow as tf
print(tf.__version__)
# Building a dataflow graph.
c = tf.constant([[1.0, 2.0], [3.0, 4.0]])
d = tf.constant([[1.0, 1.0], [0.0, 1.0]])
e = tf.matmul(c, d)
print(e)

The output as below:

2.0.0-beta1
tf.Tensor(
[[1. 3.]
 [3. 7.]], shape=(2, 2), dtype=float32)

But if you want you can use the session as follows:

import tensorflow as tf
print(tf.__version__)
# Constructing a `Session` to execute the graph.
with tf.compat.v1.Session() as sess:
  # Build a dataflow graph.
  c = tf.constant([[1.0, 2.0], [3.0, 4.0]])
  d = tf.constant([[1.0, 1.0], [0.0, 1.0]])
  e = tf.matmul(c, d)
  # Executing the graph and storing the value that `e` represents in `result
  result = sess.run(e)
  print(result)

which gives

2.0.0-beta1
[[1. 3.]
 [3. 7.]]
9 7 4
38,600 points

Related questions

1 vote
2 answers 215 views
215 views
Problem : I am beginner to Ancaconda3 and Tensorflow. I have also recently installed Ancaconda3 and Tensorflow. But if I try to import the Tensorflow in the python shell then I often face the below error: ModuleNotFoundError: No module named 'numpy.core._multiarray_umath ... also installed on my box and it can be very successfully imported in the python. Please note currently I am using Windows10.
asked Apr 22 stewart 4k points
0 votes
2 answers 66 views
66 views
Problem : I have recently installed the cuda 8.0 and cuda 9.0 in the Gpu support system. I encountered the below error while importing from the keras module. It says it is unable to load the native tensorflow runtime. I have received the error log as below: Traceback ... is, Cuda compilation tools, release 8.0, V8.0.61 Is it the clash between two cuda versions? Have anyone solved this before?
asked Feb 18 mphil 2.3k points
1 vote
1 answer 103 views
103 views
Problem : I am beginner to Python. Currently if I try to use the request module to have the urls text then I often face below Error: Traceback (most recent call last):  File "/usr/local/lib/python3.6/site-packages/requests-2.18.1-py3.5.egg/requests/adapters.py" ... to get the url's text to parse it. Please find below my line of code for your reference: mytext = requests.get(detail_path).mytext
asked May 2 stewart 4k points
0 votes
1 answer 287 views
287 views
Problem : I have just downloaded Python and Visual Studio & trying to test the debugging feature for a simple "Hello World" script but I'm receiving this error: failed to launch the python process, please validate the path 'python' Could someone please tell me how to fix this?
asked Oct 21, 2019 peterlaw 6.9k points
0 votes
1 answer 487 views
487 views
Problem : I want to learn the Machine Learning but I am unabe to resolve below error. My Specs : · Mac High Sierra 10.13.2 · Python3.4.5 · Numpy1.13.3 Used below Command: $ python3 -c "import jupyter, matplotlib, numpy, pandas, scipy, sklearn" I am ... to import pandas from the source directory, you may need to run 'python setup.py build_ext --inplace --force' to build the C extensions first.
asked Dec 4, 2019 alecxe 7.5k points