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?

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 197,814评论 5 462
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 83,124评论 2 375
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 144,814评论 0 327
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,924评论 1 268
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 61,815评论 5 358
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,562评论 1 275
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,944评论 3 388
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,582评论 0 254
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,859评论 1 293
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,881评论 2 314
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,700评论 1 328
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,493评论 3 316
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,943评论 3 300
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,115评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,413评论 1 255
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,978评论 2 343
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 41,182评论 2 339

推荐阅读更多精彩内容