제 Macbook Pro 에 GPU 로 가속 할 수 있 는 Theano 를 설치 합 니 다.
12270 단어 딥 러 닝
목적.
최근 딥 러 닝 의 응용 이 매우 뜨 거 워 서 NLP 에 딥 러 닝 을 응용 할 의향 이 있 는 저 는 다양한 오픈 소스 의 딥 러 닝 라 이브 러 리 를 탐색 하려 고 합 니 다.현재 유행 하 는 Python 언어의 딥 러 닝 라 이브 러 리 는 Theano,Google 오픈 소스 의 Tensorflow,keras 등 이 있 습 니 다.
제 가 평소에 사용 하 는 기 계 는 모두 Macbook Pro 이기 때문에 N 카드 가 없고 Intel Iris(TM)Graphics 6100(본인 은 하드웨어 에 대해 잘 모 르 기 때문에 cuda 를 사용 할 수 없고 opencl 라 이브 러 리 만 사용 할 수 있 습 니 다.그래서 GPU 가속 훈련 을 사용 하려 면 이 컴퓨터 의 하드웨어 는 Tensorflow 를 지원 할 수 없습니다.
전제 의존
내 가 사용 하 는 python 버 전 은 2.7 이다.Theano 라 이브 러 리 는 의존 라 이브 러 리 를 g+,numpy,scipy,Cython,BLAS 로 사용 해 야 합 니 다.우 리 는 pip install 로 그들 을 모두 설치 하면 됩 니 다.이것 은 공식 문 서 를 참고 할 수 있다.
Theano 설치
참고:공식 설치 문서:http://deeplearning.net/software/theano/install.html gpuarray 설치 문서:http://deeplearning.net/software/libgpuarray/installation.html
먼저 GPU 라 이브 러 리 설치 하기:
git clone https://github.com/Theano/libgpuarray.git
cd libgpuarray cd
mkdir Build
cd Build
# you can pass -DCMAKE_INSTALL_PREFIX=/path/to/somewhere to install to an alternate location
cmake .. -DCMAKE_BUILD_TYPE=Release # or Debug if you are investigating a crash
make
make install
cd .. # This must be done after libgpuarray is installed as per instructions above.
python setup.py build
python setup.py install python -c "import pygpu;pygpu.test()" Theano 재 설치
터미널 에 입력
pip install --upgrade --no-deps git+git://github.com/Theano/Theano.git (여기 git 의 이유 로 뒤에 언급 된 구덩이 로 말씀 드 리 겠 습 니 다)
이곳 에 기본적으로 설 치 된 모든 라 이브 러 리 입 니 다.
뒤에 테스트 코드(test.py)를 첨부 합 니 다.
from theano import function, config, shared, tensor, sandbox
import numpy
import time
vlen = 10 * 30 * 768 # 10 x #cores x # threads per core
iters = 1000
rng = numpy.random.RandomState(22)
x = shared(numpy.asarray(rng.rand(vlen), config.floatX))
f = function([], tensor.exp(x))
print(f.maker.fgraph.toposort())
t0 = time.time()
for i in range(iters):
r = f()
t1 = time.time()
print("Looping %d times took %f seconds" % (iters, t1 - t0))
print("Result is %s" % (r,))
if numpy.any([isinstance(x.op, tensor.Elemwise) and
('Gpu' not in type(x.op).__name__)
for x in f.maker.fgraph.toposort()]):
print('Used the cpu')
else:
print('Used the gpu') 직접 실행 하면 다음 과 같은 정보 가 표 시 됩 니 다.
$python test.py
[Elemwise{exp,no_inplace}(<TensorType(float64, vector)>)]
Looping 1000 times took 1.492254 seconds
Result is [ 1.23178032 1.61879341 1.52278065 ..., 2.20771815 2.29967753
1.62323285]
Used the cpu
$python test.py
[Elemwise{exp,no_inplace}(<TensorType(float64, vector)>)]
Looping 1000 times took 1.492254 seconds
Result is [ 1.23178032 1.61879341 1.52278065 ..., 2.20771815 2.29967753
1.62323285]
Used the cpu 위 프로그램 을 시작 할 수 있 는 프로그램 은 cpu 를 통 해 실 행 됩 니 다.gpu 를 사용 하지 않 았 습 니 다.그럼 gpu 는 어떻게 사용 하나 요?이때 우 리 는 환경 변 수 를 더 해 야 한다.libgpuarray 가 설치 되 어 있 기 때문에 theano 는 opencl 을 지원 할 수 있 습 니 다.)실행 명령:1.OpenCL 과 CPU 사용:
$THEANO_FLAGS=device=opencl0:0 python test.py
Mapped name None to device opencl0:0: Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz
[GpuElemwise{exp,no_inplace}((float32, (False,))>), HostFromGpu(gpuarray)(GpuElemwise{exp,no_inplace}.0)]
Looping 1000 times took 1.65111804008 seconds
Result is [ 1.23178029 1.61879325 1.52278078 ..., 2.20771813 2.29967737
1.62323272]
Used the gpu
chenyutongdeMacBook-Pro:dl_test Derrick$ THEANO_FLAGS=device=opencl0:0,floatX=float32 python theano_test.py
Mapped name None to device opencl0:0: Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz
[GpuElemwise{exp,no_inplace}((float32, (False,))>), HostFromGpu(gpuarray)(GpuElemwise{exp,no_inplace}.0)]
Looping 1000 times took 1.72186207771 seconds
Result is [ 1.23178029 1.61879325 1.52278078 ..., 2.20771813 2.29967737
1.62323272]
Used the gpu 코드 는'used the gpu'를 표시 하지만 실제로는 CPU 를 사용 하 는 것 으로 보인다.
$ THEANO_FLAGS=device=opencl0:1,floatX=float32 python theano_test.py
Mapped name None to device opencl0:1: Intel(R) Iris(TM) Graphics 6100
[GpuElemwise{exp,no_inplace}((float32, (False,))>), HostFromGpu(gpuarray)(GpuElemwise{exp,no_inplace}.0)]
Looping 1000 times took 1.09479188919 seconds
Result is [ 1.23178029 1.61879337 1.52278066 ..., 2.20771813 2.29967761
1.62323284]
Used the gpu 이 프로그램 이 내 맥 북 프로 의 그래 픽 카드 를 사용 한 것 이 마음 에 들 었 다.
부 딪 힌 구덩이
처음에 나 는 공식 튜 토리 얼 에 따라 설치 했다.Theano 를 설치 할 때 사용 하 는 명령 은 pip install theano 였 다.이 명령 은 theano 가 발표 한 최신 버 전 입 니 다.주의 하 세 요.발 표 된 버 전 입 니 다.제 가 썼 을 때 는 v 0.8.2 였 지만 github 에서 위탁 관리 하 는 코드 는 v 0.9.0 버 전 입 니 다.libgpuarray 역시 원본 코드 를 다운로드 하여 컴 파일 하여 설치 하 였 습 니 다.버 전 은-9998(왜 이렇게 정의 하 는 지 잘 모 르 겠 습 니 다)이 설치 되 었 을 때 THEANO 를 실행 합 니 다.FLAGS=device=opencl0:1,floatX=float32 python theano_test.py 명령 에서 이러한 오류 가 발생 했 습 니 다.
Wrong major API version for gpuarray:-9998 Make sure Theano and libgpuarray/pygpu are in sync. 그래서 우리 구 글 은 이러한 오 류 를 찾 았 습 니 다.질문 을 찾 지 못 했 습 니 다.소스 코드(github 에 있 는 것 도 있 고 다른 사이트 도 있 습 니 다)는 소스 코드 만 찾 아 볼 수 있 습 니 다.어디서 튀 어 나 온 오 류 를 볼 수 있 습 니 다.이 사이트 의 코드 에 나타 난 것 은-1000 버 전이 필요 한 것 으로 밝 혀 졌 으 며,github 에 서 는 공식 적 으로 최신 버 전 은-9998 이다.그래서 내 가 설치 한 테 아 노 가 최신 버 전이 아니 라 고 의심 했다.theano.test()명령 을 사용 하여 버 전 을 본 후,과연 v 0.8.2 가 설치 되 어 있 습 니 다.그래서 제 가 나중에 썼어 요.
pip install --upgrade --no-deps git+git://github.com/Theano/Theano.git 명령 하면 돼.
참고:http://codechina.org/2016/04/how-to-install-theano-on-mac-os-x-ei-caption-with-opencl-support/ http://deeplearning.net/software/theano/tutorial/using_gpu.html#using-gpu http://deeplearning.net/software/libgpuarray/installation.html http://deeplearning.net/software/theano/install.html https://github.com/Theano/Theano
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
caffe 데이터 구조 깊이 학습 (4) - blob 데이터 구조 blob. hpp 파일 상세 해석이 줄 은 shape 벡터 를 통 해 Blob 의 모양 을 바 꾸 는 또 다른 변형 함 수 를 정의 합 니 다. 이 줄 은 Blob 모양 의 함 수 를 읽 고 구성원 변수 shape 로 돌아 가 는 것 을 정의 합 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.