Skip to content
This repository has been archived by the owner on Jul 10, 2021. It is now read-only.

Commit

Permalink
Support for using the GPU by default, then falling back to the CPU if…
Browse files Browse the repository at this point in the history
… none is found.
  • Loading branch information
Team AiGameDev.com committed Apr 2, 2015
1 parent 62f753a commit 01d92e5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 0 additions & 1 deletion README.rst
Expand Up @@ -12,7 +12,6 @@ Upcoming Features

* An example that covers hand-written digit recognition from the MNIST dataset.
* Better error checking for the layer specifications, useful messages otherwise.
* Support for automatically using the GPU, with manually specified CPU fallback.
* Use pylearn2's monitoring code to stop training upon detecting convergence.


Expand Down
10 changes: 8 additions & 2 deletions sknn/mlp.py
Expand Up @@ -2,13 +2,16 @@

__all__ = ['MultiLayerPerceptronRegressor', 'MultiLayerPerceptronClassifier']


import os
import logging
log = logging.getLogger('sknn')

# By default, we force Theano to use a GPU and fallback to CPU, using 32-bits.
# This must be done in the code before Theano is imported for the first time.
os.environ['THEANO_FLAGS'] = "device=gpu,floatX=float32"
import theano

import numpy
import theano
import sklearn.base
import sklearn.preprocessing

Expand Down Expand Up @@ -322,6 +325,9 @@ def predict(self, X):
y = numpy.zeros((X.shape[0], self.unit_counts[-1]))
self.initialize(X, y)

if X.dtype != numpy.float32:
X = X.astype(numpy.float32)

if self.is_convolution:
X = numpy.array([X]).transpose(1,2,3,0)

Expand Down

0 comments on commit 01d92e5

Please sign in to comment.