• Register
0 votes
3.6k 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

Please log in or register to answer this question.

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 565 views
565 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, 2020 stewart 4k points
0 votes
2 answers 85 views
85 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, 2020 mphil 2.3k points
1 vote
1 answer 209 views
209 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, 2020 stewart 4k points
0 votes
1 answer 648 views
648 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
0 votes
1 answer 468 views
468 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 14 views
14 views
Problem: I've install Python 3.4 and Python 3.6 on my local machine successfully, but am unable to install packages with pip3. When I execute pip3 install <package>, I get the following SSL related error: pip is configured with locations that require TLS/SSL, ... matching distribution found for <package> How can I fix my Python3.x install so that I can install packages with pip install <package>?
asked Jan 9 Mashhoodch 5.6k points
0 votes
1 answer 19 views
19 views
Problem : I just installed Python 3.5 and upon running the following code pip install mysql-python I am getting an error, which says: error: Microsoft Visual C++ 14.0 is required (Unable to find vcvarsall.bat) I have used the following lines of code to my PATH C:\ ... (x86)\Microsoft Visual Studio 12.0\VC; C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC My PC has 64bit window 7 setup.
asked Oct 8, 2020 sikandar 2.4k points
0 votes
1 answer 5.7K views
5.7K views
Problem : I am getting following error: pytesseract.pytesseract.tesseractnotfounderror: tesseract is not installed or it's not in your path
asked Nov 7, 2019 peterlaw 6.9k points
1 vote
0 answers 18 views
18 views
v = tf.Variable(0) update = tf.compat.v1.assign(v, v+1) init_op = tf.compat.v1.global_variables_initializer() tf.compat.v1.disable_eager_execution() with tf.compat.v1.Session() as session: session.run(init_op) print(session.run(v)) for _ in range(3): session.run(update) print(session.run(v))
asked Jun 21, 2020 roshan
1 vote
2 answers 280 views
280 views
Problem : I am beginner to numpy. I am trying to execute my code but I am facing below error. &ldquo;Valueerror: all the input arrays must have same number of dimensions&rdquo;. I want to have my all the arrays with a same shape. I am trying to fix above error from past couple of days but still unable to fix it. I am looking for some help in fixing above error.
asked Apr 4, 2020 morrisBson 3.2k points