3

I am trying to study Keras library and I tried to run this example from https://github.com/fchollet/keras/tree/master/examples

'''Trains a simple deep NN on the MNIST dataset.
Gets to 98.40% test accuracy after 20 epochs
(there is *a lot* of margin for parameter tuning).
2 seconds per epoch on a K520 GPU.
'''

from __future__ import print_function
import numpy as np
np.random.seed(1337)  # for reproducibility

from keras.datasets import mnist
from keras.models import Sequential
from keras.layers.core import Dense, Dropout, Activation
from keras.optimizers import SGD, Adam, RMSprop
from keras.utils import np_utils


batch_size = 128
nb_classes = 10
nb_epoch = 20

# the data, shuffled and split between train and test sets
(X_train, y_train), (X_test, y_test) = mnist.load_data()

X_train = X_train.reshape(60000, 784)
X_test = X_test.reshape(10000, 784)
X_train = X_train.astype('float32')
X_test = X_test.astype('float32')
X_train /= 255
X_test /= 255
print(X_train.shape[0], 'train samples')
print(X_test.shape[0], 'test samples')

# convert class vectors to binary class matrices
Y_train = np_utils.to_categorical(y_train, nb_classes)
Y_test = np_utils.to_categorical(y_test, nb_classes)

model = Sequential()
model.add(Dense(512, input_shape=(784,)))
model.add(Activation('relu'))
model.add(Dropout(0.2))
model.add(Dense(512))
model.add(Activation('relu'))
model.add(Dropout(0.2))
model.add(Dense(10))
model.add(Activation('softmax'))

model.summary()

model.compile(loss='categorical_crossentropy',
              optimizer=RMSprop(),
              metrics=['accuracy'])

history = model.fit(X_train, Y_train,
                    batch_size=batch_size, nb_epoch=nb_epoch,
                    verbose=1, validation_data=(X_test, Y_test))
score = model.evaluate(X_test, Y_test, verbose=0)
print('Test score:', score[0])
print('Test accuracy:', score[1])

and than I got this error https://docs.google.com/document/d/1bo24LXbfK-NzqOBmblqM5KL91P3L3FMD1Wzq-Z5VMq0/edit?usp=sharing

I'm running windows 10 64bit with amd gpu, python 3.5 and keras in the latest version

3 Answers3

2

The error clearly says that it cannot find g++.exe. Theano requires a C++ compiler to generate and compile C++ code in order to accelerate execution of the code, but seems you don't have such compiler.

So either install g++ (maybe from a MinGW install) and configure the paths to the g++.exe binary in theano's configuration or disable theano's C++ code generator in the configuration.

Dr. Snoopy
  • 55,122
  • 7
  • 121
  • 140
2

Unfortunately, Keras and Theano don't work well with Python 3 on Windows. The problem you have is connected with the fact that you have to add libpython libraries to your C++ Windows Compiler and connect it with your Python installation which could be quite harsh when you have Python 3.5 installed. I would rather advice you to install it on Python 2. Here you have an exact instruction how to do it :

How do I install Keras and Theano in Anaconda Python on Windows?

Community
  • 1
  • 1
Marcin Możejko
  • 39,542
  • 10
  • 109
  • 120
  • Is this windows specific? I have been using Keras/Theano with python3 on Linux and it works perfectly fine. – Dr. Snoopy May 05 '16 at 23:48
  • 1
    Yes - it's Windows specific. Once I spent over a week trying to install Theano / Keras alongside Python 3. I found that it's because of changes in mingw python library. There are some problems with consistency of a default windows compiler and python c / c++ libraries. It's not worth spending too much time concentrating on that if you could just install Python 2. – Marcin Możejko May 06 '16 at 00:25
2

Tutorial: Theano install on Windows 7, 8, 10 Hello Everyone,

This post is a step by step tutorial on installing Theano for Windows 7, 8, and 10. It uses Theano, CUDA, and Anaconda.

Anaconda is a package manager for python that simplifies setting up python environments and installing dependencies. If you really don't want to use Anaconda, check out my older post here.

Let's get to it:

  1. Make sure your computer has a compatible CUDA graphics card: https://developer.nvidia.com/cuda-gpus

  2. Download CUDA https://developer.nvidia.com/cuda-downloads (I downloaded Cuda 7.5)

  3. While that's downloading, head to https://www.visualstudio.com/en-us/downloads/download-visual-studio-vs.aspx and get Visual Studio 2013 (the community version). Download and install, this will install the needed C++ compilers Couple of notes here, my install needed 7GB and took ~20 minutes to install Install CUDA ~7 minutes Note: Nsight won't install for older versions of Visual Studio if you don't have them, no worries

  4. I restarted this is windows after all...

  5. Check CUDA Navigate to C:\ProgramData\NVIDIA Corporation\CUDA Samples\v7.0\1_Utilities\deviceQuery and open the vs2013.sln file Use CTRL+F5 to run the device check and keep the cmd window open Make sure you Pass the test, otherwise there is a problem

  6. Download and setup Anaconda https://www.continuum.io/downloads. The Python 3.5 installer is fine Install it, it will take awhile ~5-10 minutes

  7. Download Theano https://github.com/Theano/Theano, Download Zip at the bottom right Extract

  8. Open CMD prompt Setup a new conda environment that uses python 3.5 conda create -n name_of_your_environment python=3.5

  9. Activate your conda environment and install dependencies activate name_of_your_environment conda install numpy scipy mingw libpython

  10. Navigate to Theano extracted folder /Theano-master

  11. Use python setup.py install This automatically uses 2to3 conversion

  12. We need to add some system variables

Right click Computer -> properties -> advanced system settings -> environment variables

Add a new system variable

Name = THEANO_FLAGS

Value = floatX=float32,device=gpu,nvcc.fastmath=True

Also add Visual Studio's c++ compiler to the path

Add ;pathToYourVSInstallation\VC\bin\

  1. Final check

Open another CMD prompt (you'll need to close the old one because it doesn't have the system variables)

activate name_of_your_environment

python

import theano

You should see something like

Using gpu device 0: Quadro K1100M (CNMeM is disabled) Now you'll be able to use Theano when you activate your conda environment.

Note: For pycharm users, PyCharm does not automatically activate the conda environment for you (bug submitted here). What you can do is just create a .bat file with these contents: call activate env_name path_to_pycharm\bin\pycharm64.exe

Worked for me, windows 8.1 like a charm.

All thanks to: http://www.islandman93.com/2016/04/tutorial-theano-install-on-windows-7-8.html

Byte_me
  • 111
  • 5