# Setup TensorFlow, Keras, Theano, Pytorch/torchvision on the CentOS VM

We need to use Keras with TensorFlow as backend for some deep learning projects in the Spark platform we practice data science. The platform we have been using is a CentOS VM running on software based hypervisor called VirtualBox.

Additionally, for future deep learning projects that may use the dataset with Apache Spark, we need to install Theano, Pytorch and Torchvision.

We already have Python 3.6 under virtual environment on Anaconda. Here are the steps:

Enter virtual environment spark

```bash
conda activate spark
```

Upgrade pip

```bash
 pip install pip --upgrade

#Collecting pip
#  Downloading pip-20.1.1-py2.py3-none-any.whl (1.5 MB)
#     |████████████████████████████████| 1.5 MB 2.5 MB/s
#Installing collected packages: pip
#  Attempting uninstall: pip
#    Found existing installation: pip 20.0.2
#    Uninstalling pip-20.0.2:
#      Successfully uninstalled pip-20.0.2
#Successfully installed pip-20.1.1
```

Install TensorFlow

```bash
conda install -c conda-forge tensorflow

#Collecting package metadata (current_repodata.json): done
#Solving environment: done
#
## Package Plan ##
#.....
#  environment location: /opt/hadoop/anaconda3/envs/spark

#  added / updated specs:
#    - tensorflow
#....
#Preparing transaction: done
#Verifying transaction: done
#Executing transaction: done
```

Verify TensorFlow installed successfully

```bash
python -c "import tensorflow"
```

Install Keras

```bash
conda install -c conda-forge keras
#Collecting package metadata (current_repodata.json): done
#Solving environment: done

## Package Plan ##

 # environment location: /opt/hadoop/anaconda3/envs/spark

 # added / updated specs:
 #   - keras


# The following packages will be downloaded:

#    package                    |            build
#    ---------------------------|-----------------
#    keras-2.4.3                |             py_0          30 KB  conda-forge
#    ------------------------------------------------------------
#                                           Total:          30 KB

#The following NEW packages will be INSTALLED:

#  keras              conda-forge/noarch::keras-2.4.3-py_0


# Proceed ([y]/n)? y


#Downloading and Extracting Packages
#keras-2.4.3          | 30 KB     | ################################################################################################################## | 100%
#Preparing transaction: done
#Verifying transaction: done
#Executing transaction: done
```

Verify Keras is installed successfully

```bash
python -c "import keras"
```

Install Theano

```bash
conda install -c anaconda theano
#Collecting package metadata (current_repodata.json): done
#Solving environment: done

## Package Plan ##

#  environment location: /opt/hadoop/anaconda3/envs/spark

#  added / updated specs:
#    - theano

#...

#Preparing transaction: done
#Verifying transaction: done
#Executing transaction: done
```

Install Pytorch

```bash
conda install -c anaconda pytorch
#Collecting package metadata (current_repodata.json): done
#Solving environment: done

## Package Plan ##

#  environment location: /opt/hadoop/anaconda3/envs/spark

#  added / updated specs:
#    - pytorch

#...
#Preparing transaction: done
#Verifying transaction: done
#Executing transaction: done
```

Install Torchvision

```bash
 conda install -c  torchvision
#Collecting package metadata (current_repodata.json): done

## Package Plan ##

#  environment location: /opt/hadoop/anaconda3/envs/spark

#  added / updated specs:
#    - torchvision

#...
#Preparing transaction: done
#Verifying transaction: done
#Executing transaction: done
```

Verify all installation

```bash
python
Python 3.6.10 |Anaconda, Inc.| (default, Mar 25 2020, 23:51:54)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
>>> import keras
>>> import theano
>>> import torch
>>> import torchvision
>>> quit()
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://george-jen.gitbook.io/data-science-and-apache-spark/setup-tensorflow-keras-theano-pytorch-torchvision-on-the-centos-vm.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
