0 下载并安装miniconda
bash Miniconda3-latest-Linux-x86_64.sh 执行安装 • 1
一股YES,安装成功,但是会发现不存在。
pip list Command 'pip' not found, but can be installed with: sudo apt install python-pip
此时,我们对终端进行重启即可
1.首先安装anaconda 2.bash Anaconda安装包 3.在终端输入anaconda(确保已经安装完成) 4.终端输入vim ~/.bashrc 5.点击i 6.在最后一行输入export PATH=/home/XXX/anaconda3/bin:$PATH 7.按 Esc :wq保存退出 8. 在终端输入source ~/.bashrc 更新配置文件 9. 新建环境:在命令行输入conda create -n 虚拟环境名 python=2.7/3.6…(conda install --yes --file requirements.txt) 10. 激活环境:source activate 虚拟环境名 11. 查看所有环境:终端输入 conda env list
1. 安装环境
首先看系统的版本
查看cudnn版本
cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2 lihuanyu@zyg-dgx:~$ cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2 #define CUDNN_MAJOR 7 #define CUDNN_MINOR 3 #define CUDNN_PATCHLEVEL 1 -- #define CUDNN_VERSION (CUDNN_MAJOR * 1000 + CUDNN_MINOR * 100 + CUDNN_PATCHLEVEL) #include "driver_types.h"
查看cuda版本
lihuanyu@zyg-dgx:~$ nvcc -V nvcc: NVIDIA (R) Cuda compiler driver Copyright (c) 2005-2018 NVIDIA Corporation Built on Sat_Aug_25_21:08:01_CDT_2018 Cuda compilation tools, release 10.0, V10.0.130
2 创建lihuanyu环境
1 创建环境,这一过程需要下载东西,速度相对较慢。 conda create -n lihuanyu python=3.6 2 激活进入环境 conda activate lihuanyu 3 查看环境 conda info -e 4 删除环境 conda remove -n lihuanyu --all 5 添加清华镜像 5.1 conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/ 5.2 conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/ 5.3 conda config --set show_channel_urls yes 5.4 conda config --remove channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/ 删除 6. 退出环境 conda deactivate
3. 安装tesorflow-gpu
1 安装最新版本tensorflow-gpu 2.6.0
pip install tensorflow-gpu
利用清华镜像安装2.2.0
pip install tensorflow-gpu==2.2.0 -i https://pypi.tuna.tsinghua.edu.cn/simple • 1
查看GPU能用吗?
import tensorflow as tf tf.__version__ import tensorflow as tf tf.test.is_gpu_available()
4. 安装keras
pytho对应关系
pip install keras==2.3.1 export LD_LIBRARY_PATH="/usr/local/cuda-10.1b64:$LD_LIBRARY_PATH"
5 切换cuda
export PATH="/usr/local/cuda-10.1/bin:$PATH" export LD_LIBRARY_PATH="/usr/local/cuda-10.1b64:$LD_LIBRARY_PATH" • 1 • 2
6. 测试文件(源于官方例程)
测试文件
""" Title: Simple MNIST convnet Author: [fchollet](https://twitter.com/fchollet) Date created: 2015/06/19 Last modified: 2020/04/21 Description: A simple convnet that achieves ~99% test accuracy on MNIST. """ """ ## Setup """ import numpy as np from tensorflow import keras from tensorflow.keras import layers """ ## Prepare the data """ # Model / data parameters num_classes = 10 input_shape = (28, 28, 1) # the data, split between train and test sets (x_train, y_train), (x_test, y_test) = keras.datasets.mnist.load_data() # Scale images to the [0, 1] range x_train = x_train.astype("float32") / 255 x_test = x_test.astype("float32") / 255 # Make sure images have shape (28, 28, 1) x_train = np.expand_dims(x_train, -1) x_test = np.expand_dims(x_test, -1) print("x_train shape:", x_train.shape) print(x_train.shape[0], "train samples") print(x_test.shape[0], "test samples") # convert class vectors to binary class matrices y_train = keras.utils.to_categorical(y_train, num_classes) y_test = keras.utils.to_categorical(y_test, num_classes) """ ## Build the model """ model = keras.Sequential( [ keras.Input(shape=input_shape), layers.Conv2D(32, kernel_size=(3, 3), activation="relu"), layers.MaxPooling2D(pool_size=(2, 2)), layers.Conv2D(64, kernel_size=(3, 3), activation="relu"), layers.MaxPooling2D(pool_size=(2, 2)), layers.Flatten(), layers.Dropout(0.5), layers.Dense(num_classes, activation="softmax"), ] ) model.summary() """ ## Train the model """ batch_size = 128 epochs = 15 model.compile(loss="categorical_crossentropy", optimizer="adam", metrics=["accuracy"]) model.fit(x_train, y_train, batch_size=batch_size, epochs=epochs, validation_split=0.1) """ ## Evaluate the trained model """ score = model.evaluate(x_test, y_test, verbose=0) print("Test loss:", score[0]) print("Test accuracy:", score[1])
结果为