Tutorial 1: Getting start

基础安装配置

Anaconda或Miniconda

按官网文档下载安装1

创建新的python沙盘

打开命令行终端 Anaconda Powershell Prompt,并输入以下代码:

conda create -n dl01s tensorflow-gpu keras-gpu
# 如果是Windows系统,则需要指定一个python的早期版本,因为cudatoolkit cudnn可能不兼容:
# conda create -n dl01s python=3.6 tensorflow-gpu keras-gpu
# 如果在一台没有GPU的电脑上,输入:
# conda create -n dl01s tensorflow keras
conda activate dl01s
conda install -c conda-forge matplotlib opencv jupyterlab jupyter

python -c 'import keras; print(keras.__version__)'
python -c 'from tensorflow.python.client import device_lib; print(device_lib.list_local_devices())'
安装 graphviz (可选)

官网2下载graphviz并安装,安装时选择将程序添加到系统路径。

继续在 Anaconda 命令行输入如下代码:

conda install -c conda-forge pydot
安装其他可选包

Anaconda 命令行输入如下代码:

conda install -c conda-forge sklearn pandas seaborn
conda install -c conda-forge lightgbm mlxtend xgboost
验证安装是否成功

首先打开 JupyterLab

cd code-data
jupyter lab

程序会自动跳转到默认浏览器。 新建一個命令行来测试是否成功:

``` in JupyterLab:
import keras
keras.__version__

from tensorflow.python.client import device_lib
print(device_lib.list_local_devices())

Prepare GPU

Google Colab

Install Google Colab into your Google Drive

In Google Drive interface: New -> More -> Connect more apps, then search colaboratory. Then create a new colab document: New -> More -> Google Colaboratory.

See some welcome introduction here7.

Then you are ready to go:

!pip install tensorflow

import tensorflow as tf
print(tf.__version__)

If you want to use the GPU/TPU, click Runtime -> Change runtime type

!pip install tensorflow-gpu
Build a deep neural network

Try some examples from the official site here8.

Or, the TensorFlow Hub lets you search and discover hundreds of trained, ready-to-deploy machine learning models in one place. See here9.

Get more from Colab

Try Colab Pro for $9.99/month. Rich people trade money for efficiency.

Trouble shootings

OMP: Error #15: Initializing libiomp5.dylib, but found libiomp5.dylib already initialized

Solution:

conda install nomkl

  1. https://docs.anaconda.com/anaconda/install↩︎

  2. https://graphviz.org/download↩︎

  3. https://developer.nvidia.com/cuda-gpus↩︎

  4. https://developer.nvidia.com/cuda-downloads↩︎

  5. https://developer.nvidia.com/cudnn↩︎

  6. https://docs.nvidia.com/deeplearning/cudnn/install-guide/index.html#install-windows↩︎

  7. https://colab.research.google.com/notebooks/welcome.ipynb↩︎

  8. https://keras.io/examples↩︎

  9. https://tfhub.dev↩︎