1

That is my second time going through the whole installation process of tensorflow (gpu). This time when I run in cmd activate tensorflow and then if I feed in the python interpreter the following test code:

# Creates a graph.
a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
c = tf.matmul(a, b)
# Creates a session with log_device_placement set to True.
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
# Runs the op.
print(sess.run(c))

(The Source)

It successfully recognizes the GPU and runs the matrices functions on it. When I open the Anaconda Spyder IDE though, and run the same test in the same way the interpreter says the code was being run on the CPU. How can I fix that? What may cause it? I am running on Win 10.

Any help will be of great use, thank you in advance.

Kind regards, Konny

KDX2
  • 945
  • 2
  • 14
  • 31
  • What do you mean when you open the spyder env? Is this a different environment? – JCooke Jun 28 '17 at 13:43
  • I meant the Spyder IDE, will edit that. – KDX2 Jun 28 '17 at 13:43
  • 2
    Not used it but are you sure that it is using the correct interpreter? – JCooke Jun 28 '17 at 13:44
  • There are 2 consoles - Python one and a IPython one (which also interpretes python code). I run the test in the pure Python console. Before that I tried to execute some deep learning code but it went far too slow and when I did the same check as in the cmd I realized the code is being indeed executed on the CPU by Spyder's integrated Python console. – KDX2 Jun 28 '17 at 13:48
  • 1
    Your spyder configuration is likely pointing to the wrong environment. You could take a look at this https://stackoverflow.com/a/30170469/1451311 for discussions of launching spyder from your environment, or https://stackoverflow.com/questions/28190500/virtualenv-ipython-in-spyder-not-working discusses configuring your default environment from the spyder GUI – mgilbert Jun 28 '17 at 13:51
  • Yeah looks like you're not using the right environment. I use pycharm so can't be of too much help but in pycharm you set a python interpreter for your project. So I point it at the python.exe in my environment folder in .../envs/env_name/ That way it picks up all my environment packages etc. which include the correct installation of tensorflow. Perhaps you've got tensorflow cpu in root or early in your path that spyder is finding and using? – JCooke Jun 28 '17 at 13:58
  • I met the same issue under ubuntu 16.04 with anaconda using spyder or starting a script from a terminal. – Jean-Pat Aug 09 '17 at 09:54

1 Answers1

1

It is not the best solution on the planet but the following worked for me: 1. Open cmd. 2. Input activate tensorflow 3. Input spyder 4. Leave it load everything. Now the test above shows that indeed tensorflow is running on the GPU. It is not a good solution because each opening of spyder must happen this way. For now this works. Yes, it's pointing to the wrong tensorflow environment by default. My problem is that I don't know where the one running in cmd is located on my computer. When I manage to solve this out I will update the answer.

KDX2
  • 945
  • 2
  • 14
  • 31
  • Did you by any chance installed the cpu-only version of tensorflow in the past? – GPhilo Jun 28 '17 at 14:03
  • @GPhilo yes, I did. I instilled it through pip from spyder as far as I remember, then I removed it and I checked that it can't load tensorflow, it couldn't. So, the removing was successfull. Then I installed the tensorflow-gpu, the cuda, upgraded the nvidia drivers and got a cudNN 5.1 because 6.0 wasn't working. I remember that conda has some virtual envts and maybe in them I have installed another copies of tensorflow, so that the kernel binds to it, not to the gpu one. I'll try to just get rid of these environments and try to `conda create -n tensorflow-gpu` to see what I can get from there – KDX2 Jun 28 '17 at 14:18
  • I think your CPU-only tensorflow is somehow still in there somewhere. The Spyder shortcut you use to open the IDE is the one with the environment name? (e.g. if your env is MyTensorEnv it'd be `Spyder (MyTensorEnv)` if you installed anaconda's package in the env when you created it) – GPhilo Jun 28 '17 at 14:34