Anaconda安裝Keras

創(chuàng)建環(huán)境

創(chuàng)建名為Keras的環(huán)境

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
#

進(jìn)入環(huán)境

查看已創(chuàng)建的環(huán)境,進(jìn)入名為Keras的環(huán)境

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連接

創(chuàng)建項目目錄

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/

添加遠(yuǎn)程部署環(huán)境

從RUN—>Deployment->Configuration進(jìn)去給項目單獨(dú)部署


添加遠(yuǎn)程部署環(huán)境

配置部署地址

配置部署地址

配置部署文件映射

配置部署文件映射

配置遠(yuǎn)程編譯環(huán)境

添加ssh遠(yuǎn)程連接

添加ssh遠(yuǎn)程連接

連接信息

遠(yuǎn)程連接用戶和密碼

配置遠(yuǎn)程編譯環(huán)境目錄和遠(yuǎn)程項目目錄

配置遠(yuǎn)程編譯環(huán)境目錄和遠(yuǎn)程項目目錄

keras使用GPU

keras使用TensorFlow作為后端,使用上述安裝命令conda install keras會將TensorFlow的cpu版本作為依賴包下載下來,因此運(yùn)行程序時默認(rèn)使用的是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?

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容