How to install theano and keras on ubuntu system

Note: The system is unbuntu14.04LTS, a 32-bit operating system. Python3.4 was previously installed. Now I want to install theano and keras. Proceed as follows:

1 , Install pip

sudo apt-get install python3-setuptools
sudo easy_install3 pip

2 , Install g++

sudo apt-get install g++

Use the above command to install g++. After the installation is complete, you can use g++ -version to check whether the installation is complete. Note that if g++ is not installed, the following error will occur when importing theano:

WARNING (theano.configdefaults): g++ not detected ! Theano will be unable to execute optimized C-implementations (for both CPU and GPU) and will default to Python implementations. Performance will be severely degraded. To remove this warning, set Theano flags cxx to an empty string.
I searched it because theano uses g++ to compile the speed faster. Most of the solutions found on the Internet are installed based on Anaconda. The solution is:

conda install mingw libpython

3 , Install theano

sudo pip3 install theano

This command will automatically download the dependencies required by theano, including numpy, scipy and so on.

4 , Install keras

sudo pip3 install keras

The last thing to note is that the default backend of keras is tensorflow, what we need is theano, so we need to modify the settings. (And tensorflow is installed with pip3, there is no corresponding version on 32-bit systems! It is very complicated to install with source files)

vim ~/.keras/keras.json
{" image_dim_ordering":"tf","epsilon":1e-07,"floatx":"float32","backend":"theano"}

5 , Test theano

import numpy as np 
import time 
import theano 
A = np.random.rand(1000,10000).astype(theano.config.floatX) 
B = np.random.rand(10000,1000).astype(theano.config.floatX) 
np_start = time.time() 
AB = A.dot(B) 
np_end = time.time() 
X,Y = theano.tensor.matrices('XY') 
mf = theano.function([X,Y],X.dot(Y)) 
t_start = time.time() 
tAB =mf(A,B) 
t_end = time.time()print("NP time: %f[s], theano time: %f[s] (times should be close when run on CPU!)"%( 
      np_end-np_start, t_end-t_start))print("Result difference: %f"%(np.abs(AB-tAB).max(),))

to sum up

The above is the installation method of ubuntu system theano and keras introduced by the editor, I hope it will be helpful to you!

Recommended Posts

How to install theano and keras on ubuntu system
How to install JDK and Mysql on Ubuntu 18.04 linux system
How to install Pycharm and Ipython on Ubuntu 16.04/18.04
How to install and configure NATS on Ubuntu 16.04
How to install and configure Gogs on Ubuntu 18.04
How to install and configure Cyberpanel on Ubuntu 18.04
How to install and secure phpMyAdmin on Ubuntu 16.04
How to install and configure ownCloud on Ubuntu 16.04
How to install and configure ownCloud on Ubuntu 16.04
How to install and configure GitLab on Ubuntu 18.04
How to install and use Docker on Ubuntu 20.04
How to install and configure Ansible on Ubuntu 18.04
How to install and use Curl on Ubuntu 18.04
How to install and use Composer on Ubuntu 18.04
How to install and use Wine on Ubuntu 18.04
How to install and secure phpMyAdmin on Ubuntu 16.04
How to install and configure Elasticsearch on Ubuntu 16.04
How to install and configure PostGIS on Ubuntu 14.04
[Practice] How to install python3.6 on Ubuntu system
How to install and use BaasBox on Ubuntu 14.04
How to install and configure VNC on Ubuntu 18.04
How to install and configure Sphinx on Ubuntu 16.04
How to install and configure OrientDB on Ubuntu 14.04
How to install and use PostgreSQL on Ubuntu 16.04
How to install and configure AppScale on Ubuntu 12.04
How to install and use Docker on Ubuntu 16.04
How to install and configure PostGIS on Ubuntu 14.04
How to install Ruby on Ubuntu 20.04
How to install Memcached on Ubuntu 20.04
How to install Java on Ubuntu 20.04
How to install MySQL on Ubuntu 20.04
How to install VirtualBox on Ubuntu 20.04
How to install Elasticsearch on Ubuntu 20.04
How to install Nginx on Ubuntu 20.04
How to install Apache on Ubuntu 20.04
How to install Git on Ubuntu 20.04
How to install Node.js on Ubuntu 16.04
How to install MySQL on Ubuntu 20.04
How to install Vagrant on Ubuntu 20.04
How to install PostgreSQL on Ubuntu 16.04
How to install Git on Ubuntu 20.04
How to install and use MySQL Workbench on Ubuntu 18.04
How to install Memcached on Ubuntu 18.04
How to install Jenkins on Ubuntu 16.04
How to install MemSQL on Ubuntu 14.04
How to install MongoDB on Ubuntu 16.04
How to install Mailpile on Ubuntu 14.04
How to install Skype on Ubuntu 20.04
How to install Jenkins on Ubuntu 20.04
How to install Python 3.8 on Ubuntu 18.04
How to install KVM on Ubuntu 18.04
How to install KVM on Ubuntu 20.04
How to install opencv3.0.0 on ubuntu14.04
How to install Anaconda on Ubuntu 20.04
How to install Jenkins on Ubuntu 18.04
How to install Apache on Ubuntu 20.04
How to install R on Ubuntu 20.04
How to install Moodle on Ubuntu 16.04
How to install Teamviewer on Ubuntu 16.04
How to install MariaDB on Ubuntu 20.04
How to install Nginx on Ubuntu 20.04