博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
深度学习库安装与使用
阅读量:4069 次
发布时间:2019-05-25

本文共 4816 字,大约阅读时间需要 16 分钟。

Theano

windows下

  • Download Anaconda now!
  • conda install mingw libpython
  • pip install theano

Keras

git

Windows下

通过 conda install keraspip install keras直接安装。(会默认的给你安装keras最新版本和所需要的theano)

因为windows版本的tensorflow刚刚才推出,所以目前支持性不太好。但是keras的backend 同时支持tensorflow和theano. 并且默认是tensorflow, 因此在win本上需要更改backend为theano才能运行。Linux中切换backend同理!

  • 将C:\Anaconda2\Lib\site-packages\keras\backend\__init__.py的line 27修改:
# Default backend: TensorFlow.#_BACKEND = 'tensorflow'_BACKEND = 'theano'

then, python-> import keras

  • 出现 tensorflow提示错误的话,需要修改下面的位置的内容: C:\Users\Administrator\.keras\keras.json
{  "image_dim_ordering":"tf",  "epsilon":1e-07,  "floatx":"float32",  "backend":"tensorflow"  }  {      "image_dim_ordering": "tf",       "epsilon": 1e-07,       "floatx": "float32",       "backend": "theano"  }

切换后端

如果你至少运行过一次Keras,你将在下面的目录下找到Keras的配置文件:

~/.keras/keras.json

如果该目录下没有该文件,你可以手动创建一个

文件的默认配置如下:

{"image_dim_ordering":"tf","epsilon":1e-07,"floatx":"float32","backend":"tensorflow"}

将backend字段的值改写为你需要使用的后端:theano或tensorflow,即可完成后端的切换

我们也可以通过定义环境变量KERAS_BACKEND来覆盖上面配置文件中定义的后端:

KERAS_BACKEND=tensorflow python -c "from keras import backend;"Using TensorFlow backend.

keras.json 细节

{    "image_dim_ordering": "tf",    "epsilon": 1e-07,    "floatx": "float32",    "backend": "tensorflow"}

你可以更改以上~/.keras/keras.json中的配置

  • image_dim_ordering:字符串,”tf”或”th”,该选项指定了Keras将要使用的维度顺序,可通过keras.backend.image_dim_ordering()来获取当前的维度顺序。对2D数据来说,tf假定维度顺序为(rows,cols,channels)而th假定维度顺序为(channels, rows, cols)。对3D数据而言,tf假定(conv_dim1, conv_dim2, conv_dim3, channels),th则是(channels, conv_dim1, conv_dim2, conv_dim3)
  • epsilon:浮点数,防止除0错误的小数字
  • floatx:字符串,”float16”, “float32”, “float64”之一,为浮点数精度
  • backend:字符串,所使用的后端,为”tensorflow”或”theano”

win10 bash下配置环境

  • bash Anaconda….sh
  • source ~/.bashrc
  • sudo /home/sun/anaconda2/bin/pip install theano
  • sudo /home/sun/anaconda2/bin/pip install keras
  • sudo /home/sun/anaconda2/bin/pip install –upgrade gensim

Cuda

安装CUDA

查看系统信息

$ uname -m && cat /etc/*release

验证NVIDIA显卡

$ lspci | grep -i nvidia

安装gcc及g++

就是安装C++开发环境,因为CUDA是基于C/C++开发的,当然现在也支持很多其他语言

$ sudo apt-get install gcc g++

安装linux kernel header及开发包

$ sudo apt-get install linux-headers-$(uname -r)

为了避免出现头文件相关的问题,推荐安装上build-essential:

$ sudo apt-get install build-essential

合并:

$ sudo apt-get install gcc g++ linux-headers-$(uname -r) build-essential -y

官方文档

Installation Instructions:`sudo dpkg -i cuda-repo-ubuntu1604-8-0-local-ga2_8.0.61-1_amd64.deb``sudo apt-get update``sudo apt-get install cuda`

3.6. Ubuntu

1. Perform the pre-installation actions.
2. Install repository meta-data

When using a proxy server with aptitude, ensure that wget is set up to use the

same proxy settings before installing the cuda-repo package.

$ sudo dpkg -i cuda-repo-<distro>_<version>_<architecture>.deb

  1. Update the Apt repository cache

$ sudo apt-get update

  1. Install CUDA

$ sudo apt-get install cuda

  1. Perform the post-installation actions

验证

重启显卡

root@dluta914:/etc/network# systemctl status nvidia-persistenced.service

驱动

apt install software-properties-common –> add-apt-repository ppa:graphics-drivers/ppa(可选)

apt install ubuntu-drivers-common –> ubuntu-drives list –> ubuntu-drivers autoinstall

nvidia-detector

root@dluta914:/etc/network# nvidia-smiWed Mar 15 16:06:11 2017+-----------------------------------------------------------------------------+| NVIDIA-SMI 378.13                 Driver Version: 378.13                    ||-------------------------------+----------------------+----------------------+| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC || Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. ||===============================+======================+======================||   0  Tesla K20c          Off  | 0000:03:00.0     Off |                    0 || 40%   48C    P0    57W / 225W |      0MiB /  4742MiB |     95%      Default |+-------------------------------+----------------------+----------------------++-----------------------------------------------------------------------------+| Processes:                                                       GPU Memory ||  GPU       PID  Type  Process name                               Usage      ||=============================================================================||  No running processes found                                                 |+-----------------------------------------------------------------------------+
cuda

安装:

./cuda*.run

cd ~/NVIDIA_CUDA-8.0_Samples/ –> make all

cd ~/NVIDIA_CUDA-8.0_Samples/1_Utilities/deviceQuery

–> nvcc -I '../../common/inc/' deviceQuery.cpp -o deviceQuery
–> ./deviceQuery

nvcc -V

环境变量

vim /etc/bash.bashrc

export CUDA_HOME=/usr/local/cuda-8.0export PATH=/usr/local/cuda-8.0/bin${PATH:+:${PATH}}export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

vim ~/.bashrc

转载地址:http://xjoji.baihongyu.com/

你可能感兴趣的文章
如何高效利用GitHub
查看>>
环境分支-git版本管理
查看>>
uni-app 全局变量
查看>>
js判断空对象的几种方法
查看>>
java 不用递归写tree
查看>>
springboot2 集成Hibernate JPA 用 声明式事物
查看>>
fhs-framework jetcache 缓存维护之自动清除缓存
查看>>
SpringBoot 动态编译 JAVA class 解决 jar in jar 的依赖问题
查看>>
fhs-framework springboot mybatis 解决表关联查询问题的关键方案-翻译服务
查看>>
ZUUL2 使用场景
查看>>
Spring AOP + Redis + 注解实现redis 分布式锁
查看>>
elastic-job 和springboot 集成干货
查看>>
php开发微服务注册到eureka中(使用sidecar)
查看>>
mybatis mybatis plus mybatis jpa hibernate spring data jpa比较
查看>>
支付宝生活号服务号 用户信息获取 oauth2 登录对接 springboot java
查看>>
CodeForces #196(Div. 2) 337D Book of Evil (树形dp)
查看>>
uva 12260 - Free Goodies (dp,贪心 | 好题)
查看>>
uva-1427 Parade (单调队列优化dp)
查看>>
【设计模式】学习笔记13:组合模式(Composite)
查看>>
hdu 1011 Starship Troopers (树形背包dp)
查看>>