Keras is an open-source software library that provides a Python interface for artificial neural networks. Keras acts as an interface for the TensorFlow library.
Keras is python based neural network library, so python must be installed on your machine. If python is properly installed on your machine, then open your terminal and type python, you could see the response similar as specified below,
Python 3.8.4 (tags/v3.8.4:dfa645a, Jul 13 2020, 16:46:45) [MSC v.1924 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>>
As of now, the version is ‘3.8.4’. If Python is not installed, you can install it from here
Follow below steps to properly install Keras on your system.
Step 1: Create virtual environment
Virtualenv is used to manage Python packages for different projects. It is always recommended to use a virtual environment while developing Python applications.
Linux or mac OS users, go to your project root directory and type the below command to create virtual environment,
python3 -m venv kerasenv
After executing the above command, “kerasenv” directory is created with bin,lib and include folders in your installation location.
Windows user can use the below command,
py -m venv keras
Step 2: Activate the environment
This step will configure python and pip executables in your shell path.
Now we have created a virtual environment named “kerasvenv”. Move to the folder and type the below command,
$ cd kerasvenv kerasvenv $ source bin/activate
Windows users move inside the “kerasenv” folder and type the below command:
Step 3: Python libraries
Keras depends on the following python libraries.
Hopefully, you have installed all the above libraries on your system. If these libraries are not installed, then use the below command to install .
pip install numpy pandas matplotlib scipy
It is an open source machine learning library. It is used for classification, regression and clustering algorithms. Before moving to the installation, it requires the following −
- Python version 3.5 or higher
- NumPy version 1.11.0 or higher
- SciPy version 0.17.0 or higher
- joblib 0.11 or higher.
Now, we install scikit-learn using the below command −
pip install -U scikit-learn
Seaborn is an amazing library that allows you to easily visualize your data. Use the below command to install:
pip pip install seaborninstall -U scikit-learn
Keras Installation Using Python
As of now, we have completed basic requirements for the installtion of Kera. Now, install the Keras using same procedure as specified below:
pip install keras
Quit virtual environment
After finishing all your changes in your project, then simply run the below command to quit the environment
If anaconda is not installed, then visit the official link, www.anaconda.com/distribution and choose download based on your OS.
Create a new conda environment
Launch anaconda prompt, this will open base Anaconda environment. Let us create a new conda environment. This process is similar to virtualenv. Type the below command in your conda terminal:
conda create --name PythonCPU
If you want, you can create and install modules using GPU also. In this tutorial, we follow CPU instructions.
Activate conda environment
To activate the environment, use the below command:
Spyder is an IDE for executing python applications. Let us install this IDE in our conda environment using the below command:
conda install spyder
Install python libraries
We have already known the python libraries numpy, pandas, etc., needed for keras. You can install all the modules by using the below syntax
conda install -c anaconda <module-name>
For example, you want to install pandas −
conda install -c anaconda pandas
Like the same method, try it yourself to install the remaining modules.
Now, everything looks good so you can start keras installation using the below command:
conda install -c anaconda keras