Anaconda安装Keras

创建环境

创建名为Keras的环境

pc@ubuntu2:~$ conda create --name keras python=3.6
Solving environment: done
......
#
# To activate this environment, use:
# > source activate keras
#
# To deactivate an active environment, use:
# > source deactivate
#

进入环境

查看已创建的环境,进入名为Keras的环境

pc@ubuntu2:~$ conda info --envs
# conda environments:
#
base                  *  /home/pc/anaconda3
keras                    /home/pc/anaconda3/envs/keras

pc@ubuntu2:~$ source activate keras

安装Keras库

(keras) pc@ubuntu2:~$ conda install keras
······
Downloading and Extracting Packages
mkl-2018.0.3         | 198.7 MB  | ################################################################################################################# | 100% 
Preparing transaction: done
Verifying transaction: done
Executing transaction: done

(keras) pc@ubuntu2:~$ python
Python 3.6.7 |Anaconda, Inc.| (default, Oct 23 2018, 19:16:44) 
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from keras.models import Sequential
Using TensorFlow backend.
>>> 

安装keras成功

与pycharm连接

创建项目目录

pc@ubuntu2:~/UserData/wy/projects$ mkdir LSTM
pc@ubuntu2:~/UserData/wy/projects$ ll
total 16
drwxrwxr-x 4 pc pc 4096 Dec 14 16:07 ./
drwxrwxr-x 3 pc pc 4096 Dec  6 14:49 ../
drwxrwxr-x 2 pc pc 4096 Dec 14 16:07 LSTM/
drwxrwxr-x 2 pc pc 4096 Dec  6 14:52 RNN/

添加远程部署环境

从RUN—>Deployment->Configuration进去给项目单独部署


添加远程部署环境

配置部署地址

配置部署地址

配置部署文件映射

配置部署文件映射

配置远程编译环境

添加ssh远程连接

添加ssh远程连接

连接信息

远程连接用户和密码

配置远程编译环境目录和远程项目目录

配置远程编译环境目录和远程项目目录

keras使用GPU

keras使用TensorFlow作为后端,使用上述安装命令conda install keras会将TensorFlow的cpu版本作为依赖包下载下来,因此运行程序时默认使用的是CPU。

  • 使用CPU的日志例子,
PyDev console: starting.
Python 3.6.7 |Anaconda, Inc.| (default, Oct 23 2018, 19:16:44) 
[GCC 7.3.0] on linux
runfile('/home/pc/UserData/wy/keras/LSTM/6.Building the LSTM model.py', wdir='/home/pc/UserData/wy/keras/LSTM')
Using TensorFlow backend.
2018-12-14 22:47:01.057923: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX AVX2 FMA
2018-12-14 22:47:01.067905: I tensorflow/core/common_runtime/process_util.cc:69] Creating new thread pool with default inter op setting: 2. Tune using inter_op_parallelism_threads for best performance.
Month=1, Predicted=322.961307, Expected=339.700000
Month=2, Predicted=359.407819, Expected=440.400000
Month=3, Predicted=340.123599, Expected=315.900000
Month=4, Predicted=386.167338, Expected=439.300000
Month=5, Predicted=329.620121, Expected=401.300000
Month=6, Predicted=405.771963, Expected=437.400000
Month=7, Predicted=438.331251, Expected=575.500000
Month=8, Predicted=400.997520, Expected=407.600000
Month=9, Predicted=470.708216, Expected=682.000000
Month=10, Predicted=573.164068, Expected=475.300000
Month=11, Predicted=585.886681, Expected=581.300000
Month=12, Predicted=527.363607, Expected=646.900000
Test RMSE: 92.996

使用GPU

安装TensorFlow的GPU版本,则会自动检测并使用GPU

conda install tensorflow-gpu

  • 使用GPU的日志例子
PyDev console: starting.
Python 3.6.7 |Anaconda, Inc.| (default, Oct 23 2018, 19:16:44) 
[GCC 7.3.0] on linux
runfile('/home/pc/UserData/wy/keras/LSTM/6.Building the LSTM model.py', wdir='/home/pc/UserData/wy/keras/LSTM')
Using TensorFlow backend.
2018-12-17 09:41:29.733813: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX AVX2 FMA
2018-12-17 09:41:33.649586: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1432] Found device 0 with properties: 
name: GeForce RTX 2080 Ti major: 7 minor: 5 memoryClockRate(GHz): 1.605
pciBusID: 0000:04:00.0
totalMemory: 10.73GiB freeMemory: 10.53GiB
2018-12-17 09:41:33.906894: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1432] Found device 1 with properties: 
name: GeForce RTX 2080 Ti major: 7 minor: 5 memoryClockRate(GHz): 1.605
pciBusID: 0000:08:00.0
totalMemory: 10.73GiB freeMemory: 10.53GiB
2018-12-17 09:41:34.216963: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1432] Found device 2 with properties: 
name: GeForce RTX 2080 Ti major: 7 minor: 5 memoryClockRate(GHz): 1.605
pciBusID: 0000:85:00.0
totalMemory: 10.73GiB freeMemory: 10.53GiB
2018-12-17 09:41:34.503535: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1432] Found device 3 with properties: 
name: GeForce RTX 2080 Ti major: 7 minor: 5 memoryClockRate(GHz): 1.605
pciBusID: 0000:89:00.0
totalMemory: 10.73GiB freeMemory: 10.53GiB
2018-12-17 09:41:34.504071: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1511] Adding visible gpu devices: 0, 1, 2, 3
2018-12-17 09:41:36.161357: I tensorflow/core/common_runtime/gpu/gpu_device.cc:982] Device interconnect StreamExecutor with strength 1 edge matrix:
2018-12-17 09:41:36.161410: I tensorflow/core/common_runtime/gpu/gpu_device.cc:988]      0 1 2 3 
2018-12-17 09:41:36.161418: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1001] 0:   N N N N 
2018-12-17 09:41:36.161423: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1001] 1:   N N N N 
2018-12-17 09:41:36.161427: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1001] 2:   N N N N 
2018-12-17 09:41:36.161431: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1001] 3:   N N N N 
2018-12-17 09:41:36.162345: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1115] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 10168 MB memory) -> physical GPU (device: 0, name: GeForce RTX 2080 Ti, pci bus id: 0000:04:00.0, compute capability: 7.5)
2018-12-17 09:41:36.163036: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1115] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:1 with 10168 MB memory) -> physical GPU (device: 1, name: GeForce RTX 2080 Ti, pci bus id: 0000:08:00.0, compute capability: 7.5)
2018-12-17 09:41:36.163583: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1115] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:2 with 10168 MB memory) -> physical GPU (device: 2, name: GeForce RTX 2080 Ti, pci bus id: 0000:85:00.0, compute capability: 7.5)
2018-12-17 09:41:36.164005: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1115] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:3 with 10168 MB memory) -> physical GPU (device: 3, name: GeForce RTX 2080 Ti, pci bus id: 0000:89:00.0, compute capability: 7.5)
Month=1, Predicted=283.869118, Expected=339.700000
Month=2, Predicted=317.888545, Expected=440.400000
Month=3, Predicted=305.633642, Expected=315.900000
Month=4, Predicted=365.284169, Expected=439.300000
Month=5, Predicted=302.728278, Expected=401.300000
Month=6, Predicted=369.501726, Expected=437.400000
Month=7, Predicted=405.976962, Expected=575.500000
Month=8, Predicted=358.590047, Expected=407.600000
Month=9, Predicted=435.379599, Expected=682.000000
Month=10, Predicted=356.173705, Expected=475.300000
Month=11, Predicted=440.317673, Expected=581.300000
Month=12, Predicted=381.672660, Expected=646.900000
Test RMSE: 139.765

参考链接

Linux下使用anaconda安装Keras
python – 如何检查keras是否使用gpu版本的tensorflow?

你可能感兴趣的:(Anaconda安装Keras)