Commit 80e08121 authored by Carsten Eie Frigaard's avatar Carsten Eie Frigaard
Browse files

added_new_kears_install_process

parent f787be98
%% Cell type:markdown id: tags:
# ITMAL Demo
## Installing Keras
## Installing Keras and Tensorflow for Anaconda 2021.11
REVISIONS| |
---------| |
2018-03-25| CEF, initial.
2020-03-05| CEF, F20 ITMAL update.
2020-03-06| CEF, investigated Anaconda 2019.10 on Windows and updated GPU server notes.
2021-10-12| CEF, updated for ITMAL E21.
2021-03-23| CEF, updated for SWMAL F22, rewrote install method for Keras via environments.
2022-03-23| CEF, updated for SWMAL F22, rewrote install method for Keras via environments.
2022-03-25| CEF, elaboreated on conda and pip, and added pip install and screenshots.
### Installing Keras and Tensorflow for Anaconda 2021.11
### About Anaconda Package Managers
Anaconda comes with two different package managers: `conda` and `pip`
* `conda` is the prefered package manager, that will check new package installation for compability with existing packages. While this pre-compability-check is nice in theory, it often turns out, that it becomes impossible to install a given package due to incompabilities with one or more other packages. Even more annoing, the simple install of a package may take hours to complete.
* `pip` is a simpler package mangager, that comes with most Python distributions. It does none of the compability-checks when installing; it just installs whatever you ask it to (and incompabilites may then creep in in the run-time enviroment).
Normally you would try to install whatever you need via `conda` and when it breaks down due to to many broken dependencies (trying with 'flexible solve' etc. for hours), you just continue with `pip`.
### installing Keras via CONDA
Keras will not install under Anaconda version 2021.11. It ends up in a endless package-conflict, when installing under `conda`.
(This is a new finding for the particular version 2021.11, and previous version did not have this tensorflow install problem...but typically only a Keras install problem).
<img src="https://itundervisning.ase.au.dk/SWMAL/L06/Figs/Screenshot_conda_install_keras_tensorflow_conflicts.png" alt="WARNING: could not get image from server." style="height:250px" style="width:350px">
(This is a new finding for the particular version 2021.11, and previous version did not have this tensorflow install problem, but typically only a Keras install problem).
The root-cause of the problem must be missing check when packageing the Anaconda, failing to find the set of conflicts we see, when installing `tensorflow` in the set of default installe packages that comes with the Anaconda distribution.
#### 1) Prepare and Ceate a new Environment
So, one solution is to create a new conda environment, and from this install `scikit-learn` and `tensorflow` and `keras`,
Later we need a package called `nb_conda_kernels`, let us install this before we create and activate the new enviroment
```bash
> conda install nb_conda_kernels
(base)> conda install nb_conda_kernels
```
Now, let us call our enviroment `swmal` and create it by running
```bash
> conda create --name swmal
(base)> conda create --name swmal
```
<img src="https://itundervisning.ase.au.dk/SWMAL/L06/Figs/Screenshot_conda_install_keras_tensorflow_create_env.png" alt="WARNING: could not get image from server." style="height:250px" style="width:350px">
and then activate it via
```bash
> conda activate swmal
(base)> conda activate swmal
```
<img src="https://itundervisning.ase.au.dk/SWMAL/L06/Figs/Screenshot_conda_install_keras_tensorflow_activate_env.png" alt="WARNING: could not get image from server." style="height:250px" style="width:350px">
#### 2) Install Needed Packages
Now we got a clean state enviroment and we need to install the packages needed for `scikit-learn` and `tensorflow`, but this is as easy as
```bash
> conda install scikit-learn tensorflow keras nb_conda_kernels
(swmal)> conda install scikit-learn tensorflow keras nb_conda_kernels
```
(Notice that the package `nb_conda_kernels` also needs to be installed in this new enviroment.)
<img src="https://itundervisning.ase.au.dk/SWMAL/L06/Figs/Screenshot_conda_install_keras_tensorflow_installing.png" alt="WARNING: could not get image from server." style="height:250px" style="width:350px">
Notice that the package `nb_conda_kernels` also needs to be installed in this new enviroment, and it actually also installes the jupyter notebook packages.
#### 3) Launching Jupyter-Notebooks in the new Enviroment
There are two `keras` interfaces, the stand-alone `keras.` and then a similar interface already build into `tensorflow.keras`, you could use both, but direct access via the stand-alone inteface may be the most obvious.
There are two `keras` interfaces, the stand-alone `keras`, and then a similar interface already build into `tensorflow.keras`. You could use both, but direct access via the stand-alone inteface may be the most obvious.
```bash
(swmal)> jupyter-notebook
```
<img src="https://itundervisning.ase.au.dk/SWMAL/L06/Figs/Screenshot_conda_install_keras_tensorflow_notebook.png" alt="WARNING: could not get image from server." style="height:250px" style="width:350px">
#### 4) Testing the New Enviroment Setup
Lets see the version installed in the new `swmal` environment via the `Versions()` function found in the `itmallib`
%% Cell type:code id: tags:
``` python
from libitmal import versions
versions.Versions()
```
%% Output
Python version: 3.9.7.
Scikit-learn version: 1.0.2.
Keras version: 2.6.0
Tensorflow version: 2.6.0
Tensorflow.keras version: 2.6.0
Opencv2 version: 4.5.5
%% Cell type:markdown id: tags:
The `Versions()` function should print whatever version you installed, or produce a warning, if the package is not installed at all.
For my current Windows/Anaconda setup I got the versions, Yours may differ slightly
```
Python version: 3.9.7.
Scikit-learn version: 1.0.2.
Keras version: 2.6.0
Tensorflow version: 2.6.0
Tensorflow.keras version: 2.6.0
```
#### 5) Wrapping It All Up in a BAT File
To make development easy, a BAT (Windows batch or script file) shold be created. This should ease the launch of Jupyter-Notebooks and the BAT file could be put in a icon placed on the taskbar or similar.
The BAT-file should contain the followin text lines, an notice that you must changex
```
ECHO OFF
REM my-jupyter-notebook
REM Version: 0.1
REM 2022-03-23: CEF, inital version
echo MY-JUPYTER-NOTEBOOK launcher..
SET USER=au204573
@CALL "%C:\Users\%USER%\Anaconda3\condabin\conda.bat" activate swmal %*
REM note book start in this directory, you may change it:
cd \
jupyter-notebook
echo DONE
```
%% Cell type:markdown id: tags:
### Installing Keras via PIP
If `conda` fails, or you just want to proceede quickly, then install everything in the base environment via pip
```bash
> pip install keras tensorflow
```
<img src="https://itundervisning.ase.au.dk/SWMAL/L06/Figs/Screenshot_pip_install_tensorflow.png
" alt="WARNING: could not get image from server." style="height:250px" style="width:350px">
and then just launch the jupyter-notebook in the default (base) environment.
NOTE: this pip install needs testing and verification --- please report if it does not work on your PC!
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment