Название: Deep Learning for Physical Scientists
Автор: Edward O. Pyzer-Knapp
Издательство: John Wiley & Sons Limited
Жанр: Химия
isbn: 9781119408352
isbn:
Task: Install Anaconda, and use the instructions below to ensure that you have TensorFlow installed on your system
2.3.2.1 Installing TensorFlow
2.3.2.1.1 Without GPU
Neural network training can be significantly accelerated through the use of graphical processing units (GPUs), however they are not strictly necessary. When using smaller architectures and/or working with small amounts of data, a typical central processing unit (CPU) will be sufficient. As such, GPU acceleration will not be required for many of the tasks in this book. Installing Tensorflow without CPU involves a single conda install command:
$> conda install –c conda-forge tensorflow
2.3.2.1.2 With GPU
To make use of TensorFlow's GPU acceleration, you will need to ensure that you have a compute unified device architecture (CUDA)‐capable GPU and all of the required drivers installed on your system. More information on setting up your system for GPU support can be found here: https://www.tensorflow.org/install/gpu
If you are using Linux, you can greatly simplify the configuration process by using the TensorFlow Docker image with GPU support: https://www.tensorflow.org/install/docker
Once you have the prerequisites installed, you can install TensorFlow via:
$> pip install tensorflow
We recommend sticking to conda install commands to ensure package compatibility with your conda environment, however a few earlier examples made use of TensorFlow 1's low‐level application programming interface (API) to illustrate lower‐level concepts. For compatibility, the earlier low‐level API can be used by including the following at the top of your script:
import tensorflow.compat.v1 as tf tf.compat.v1.disable_eager_execution()
This has been included in the code examples wherever necessary.
Note: with the latest version of TensorFlow, this command will install TensorFlow with both CPU and GPU (if available) support.
2.4 Jupyter Notebooks
Jupyter notebooks provide a method to easily create interactive documents capable of hosting and running Python code. This is a great way to work for many scientific applications, allowing you to incorporate descriptive text alongside executable code – helping others to understand and reproduce your work. In this way, they are an excellent tool for collaboration, and can be used to build living documents in which code can be updated, and visualisations can be easily rerun with new data. To use Jupyter notebooks, you will need to first install Jupyter by running:
$> conda install notebook
2.4.1 Why Use a Notebook?
Standard Python scripts have their advantages – the code can be contained within a single file that can easily be run and debugged, without the need to step through and run multiple cells of code. Comments can be added to describe blocks of code, and docstrings can be used to provide more comprehensive descriptions of the script's functionality. So why use a notebook?
While Python scripts have a number of advantages while writing code, there are several shortfalls for their use in sharing your work. Comments and docstrings easily become overwhelming when detailed descriptions are required – turning a clean script into an awkward mess of comments and code blocks. This can make it difficult for others to read and understand what's going on. Furthermore, it does not allow you to incorporate plotting or other visualisations alongside your text. This is where notebooks come in.
Notebooks allow you to create a well‐structured document that incorporates executable code. The structuring allows you to create a comprehensive, flowing document – in the same way that you would for a paper or report. Unlike a traditional document, notebooks are enriched by their ability to incorporate executable code; code that can be used to run real experiments alongside the text and/or to produce interactive data visualisations. This is particularly important for sharing code and facilitating usability – providing a far more intuitive method of sharing code than a collection of Python scripts.
2.4.2 Starting a Jupyter Notebook Server
To use Jupyter notebooks, you will need to run the Jupyter notebook server. This can be done simply by executing the following:
$> jupyter notebook
It is recommended that you execute this from the directory you wish to work from, as this makes accessing existing project content and creating new content easy. Once the above command is executed, Jupyter should prompt your browser to open Jupyter's web User interface (UI), taking you to a page that looks like this:
You can then click “new,” which will give the option of creating a new file.
To create a new Python notebook, simple click on the Python option (in this case, Python 3). You will then be presented with a new empty notebook.
The Jupyter notebook is connected to an iPython kernel, which will allow you to execute Python code in code blocks, such as the block above. Once you have written the code you would like to execute, simply click “run” in the Jupyter UI, or hit shift + enter on your keyboard to execute the cell. Jupyter also has another type of block – markdown blocks – which we will explore in the next section.
2.4.3 Adding Markdown to Notebooks
Markdown helps to add structure to documents and improve readability. As with typical markdown, you can easily specify headings and subheadings, as demonstrated in the following example:
# Heading 1 ## Heading 2 ### Heading 3
This code produces the following:
You can also embolden or italicise your text:
**Here is an example of emboldening** and *italicization*.
Bullet points or numbered lists can also easily be used:
* СКАЧАТЬ