BrainVoyager v22.0

Installing and Enabling Python

In BrainVoyager 22 Python plays an important function: Besides being the primary interpreted language (next to JavaScript) to enable users to writie analysis scripts as well as to program new functionality, Python is also necessary for executing the code cells in the new BrainVoyager notebooks. Furthermore, Python is also used in the background to run the newly introduced deep learning (DL) based segmentation tool. The DNN segmentator uses a trained deep neural network (DNN) that has been implemented in Google's TensorFlow machine learning platform programmed in Python.

BrainVoyager is based on a standard (CPython) Python runtime environment as it is available directly from Python's home page Python.org or from distributions that focus on data science such as Anaconda. To enhance flexibility, Python support is now enabled via an isolated plugin, which is only launched when needed the first time. With this new approach BrainVoyager now lets you chose any (compatible) Python on your disk after starting BrainVoyager. The made choice is then stored permanently in BV's settings but you can switch to another Python on disk at any moment in time. At present, BrainVoyager supports Python 3.6 only but Python 3.8 support will be added soon (planned for v22.2). While downloading Python 3.6 from Python.org is one possible way to get the right Python version (recommended for BrainVoyager 21), it is now recommended to use the data sceince oriented distribution Anaconda (actually Miniconda, see below) since it provides an elegant means to setup environments for multiple Python versions in an elegant way. Using environments allows, for example, a user to use a different Python (e.g. Python 3.7) with a different set of modules (or different versions of the same modules) independently from the specific needs for BrainVoyager. While one could go with Anaconda coming with hundreds of modules, we recommend Miniconda since it starts with a minimal Python implementation to which just the needed packages can be added. Miniconda plays also nice with already installed Python versions: You do not need to uninstall other Python installations or packages in order to use conda, the package and environment manager of Miniconda. Even if you already have a system Python or another Python installation (e.g. from Python.org), you do not need to uninstall, remove, or change any of them before using conda. Another advantage to use a miniconda environment with a specific name (see below) is that BrainVoyager will auto-detect it.

Python Installation Using Miniconda

Here are the recommended steps to setup Python using Miniconda:

1. Install Miniconda

If not yet installed, download the latest 3.x (not 2.7) version from the Miniconda page. Make sure that you download the 64-bit version for your operating system:

2. Create a Python Environment for BV

Note that the installed Python version will be newer (likely 3.8 or higher) than the version (3.6) currently supported by BrainVoyager. This is no problem since miniconda allows us to create environments that may have different versions of Python. Now open a Terminal window (macOS, Linux) or open the 'Anaconda Prompt (Miniconda3)' Prompt from the Windows Start menu and type the following from the active base environment:

> conda update conda

This command is executed just to ensure that the package manager conda is up-to-data. Now we create an environment containing Python 3.6 (required for BV) as well as basic data science libraries:

> conda create -n env_bv python=3.6 numpy=1.16.4 scipy=1.3.0 matplotlib=3.1.1

Note that the name of the created environment is 'env_bv' (environment for use with BrainVoyager) that will be automatically detected when enabling Python in BrainVoyager (see below).

3. Add TensorFlow to Enable DNN Segmentator

To install TensorFlow (TF) into our created environment, we first need to activate it:

> conda activate env_bv

With the activated environment, commands like 'python' or 'pip' will use the correct (3.6) version. We will use the standard Python package installerpipto install TensorFlow (the first line just ensures that 'pip' is up-to-date):

> python -m pip install --upgrade pip

> python -m pip install tensorflow==2.0.0

Since the DNN for brain segmentation was developed with TF 2.0, it is recommended to add the '==2.0.0' part, but everything should also work with the latest TF version. Note that this installation does not install GPU support for TensorFlow. GPU acceleration is available for Linux and Windows with NVIDIA cards (for details see below). The last step to do is the installation of the nibabel library that is used to read and write NIfTI files from Python:

> python -m pip install nibabel

While this completes the necessary steps for BrainVoyager, you can move on to test whether everything works as expected, i.e. whether the created environment uses Python 3.6. To launch Python from the activated 'env_bv' environment, type 'python' (plus 'Return' key) in the Terminal. You should get a message that you are running a Python 3.6.x version and then a standard Python prompt '>>>' ready to receive your Python commands. To exit the Python interpreter type 'exit()' followed by 'Return'. Note that you can leave the 'env-bv' environment by entering 'conda deactivate' which will bring you back to the base (e.g. Python 3.8) environment.

Selecting a Python Version in BrainVoyager

After starting BrainVoyager, click the Select Python 3.6 on Disk item in the Python menu.

SelectPython

This will open the Select Python On Disk dialog:

SelectPyDlg

The section Auto-detected Python 3.6 locations lists all 3.6 Python versions that BrainVoyager found on disk using heuristic search for Miniconda environments, the Python.org Python installation and the operating system installed version (on Linux). After a standard setup, you should find here the 'env_bv' environment as well as other environments you might have created. In the example above three Python3.6 installations were found, two in miniconda environments and one installed from Python.org.

You can simply select one of auto-detected Python versions and then click the Choose button. The selected Python version will then be shown in the Folder text field inside the Selected Python 3.6 location section. In case the miniconda Python 3.6 'env_bv' environment has been created, BrainVoyager will select this version as default. If you have a Python 3.6 on disk that was not detected, you can also use the Select Manually button to specify another version as the one to be used by BrainVoyager. Note that the program ensures that you select a Python 3.6 version by asking for a 'python3.6m' or 'python36' name in a sub-folder ('bin' or 'lib') inside the respective Python folder.

After selecting the desired version, click the OK button. BrainVoyager will keep your choice permanently so you only need to go back to this dialog in case you want to switch to another Python version. When running a Python script or when executing a code cell in a BrainVoyager notebook, the selected Python version will automatically be launched on first use and will then be available throughout a BrainVoyager session. You can also test whether the selected Python version runs successfully by clicking the Initialize Python item in the Python menu. To test whether BrainVoyager uses the specified Python, you can open and run the notebook 'Test Selected Python.bvnb' that is available in the 'Documents/BrainVoyager/Notebooks' folder after BrainVoyager installation.

Note. Make sure that the Pyton version you select contains the minimal set of modules as described above. If, for example, the 'numpy' and 'matplotlib' librarires are not installed, the Python cells in BrainVoyager notebooks will print an error message since these libraries are assumed to be present for provided functionality (e.g. embedding of matplotlib images). When using the DNN Segmentator, tensorflow must be properly installed, otherwise an error message will be printed in the Python Console panel.

Note. After Python is initialized and used, you can no longer switch to another Python version on disk in the current session. If you want to use another Python version, you must first close BrainVoyager and launch it before another Python can be chosen on disk.

GPU-Accelerated TensorFlow

GPU support for TensorFlow requires a modern graphics card from NVIDIA supporting CUDA. Support is available for Ubuntu Linux and Windows 10. While the setup on Linux is rather easy, the setup on Windows requires specific versions of NVIDIA drivers and libraries that need to be compatible. For general help to enable GPU support for TensorFlow, please consult the GPU Support web page. There are also several helpful blog pages about installing TensorFlow 2.x on Windows 10, such as this simple guide. If you have any questions, please consult our support team.

The documentation below may help to setup GPU support on Windows 10, but inote that t is specific for CUDA 10.0 and you might want to use a newer version.

- cuda_10.0.130_411.31_win10.exe          # Easy GUI installation after download

- cudnn-10.0-windows10-x64-v7.6.5.32.zip  # manual install necessary!
after extraction, files need to be copied as described here:
https://docs.nvidia.com/deeplearning/sdk/cudnn-install/index.html
but note that used cuda version in path names likely different (we use 10.0)
From web site:
Your CUDA directory path is referred to as C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2
Your cuDNN directory path is referred to as <installpath>
Navigate to your <installpath> directory containing cuDNN.
Unzip the cuDNN package.
cudnn-10.2-windows7-x64-v7.6.5.32.zip
or
cudnn-10.2-windows10-x64-v7.6.5.32.zip
Copy the following files into the CUDA Toolkit directory.
Copy <installpath>\cuda\bin\cudnn64_7.6.5.32.dll to C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2\bin.
Copy <installpath>\cuda\ include\cudnn.h to C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2\include.
Copy <installpath>\cuda\lib\x64\cudnn.lib to C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2\lib\x64.
Set the following environment variables to point to where cuDNN is located. To access the value of the $(CUDA_PATH) environment variable, perform the following steps:

Open a command prompt from the Start menu.
Type Run and hit Enter.
Issue the control sysdm.cpl command.
Select the Advanced tab at the top of the window.
Click Environment Variables at the bottom of the window.
Ensure the following values are set:
Variable Name: CUDA_PATH
Variable Value: C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2


Copyright © 2020 Rainer Goebel. All rights reserved.