關(guān)于Theano和Tensorflow多GPU使用問題
我使用的是tensorflow-gpu (1.2.1)和Theano (0.9.0),2個(gè)4G顯存Nvidia Quadro M2000 GPU。
1. theano: ValueError: Could not infer context from inputs
THEANO_FLAGS="contexts=dev0->cuda0;dev1->cuda1,gpuarray.preallocate=0.95,mode=FAST_RUN,floatX=float32,on_unused_input=warn" python config.py
ERROR (theano.gof.opt): SeqOptimizer apply <theano.gpuarray.opt.GraphToGPU object at 0xdfe69210>
ERROR: SeqOptimizer apply <theano.gpuarray.opt.GraphToGPU object at 0xdfe69210>
ERROR (theano.gof.opt): Traceback:
ERROR: Traceback:
ERROR (theano.gof.opt): Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/theano/gof/opt.py", line 235, in apply
sub_prof = optimizer.optimize(fgraph)
File "/usr/lib/python2.7/site-packages/theano/gof/opt.py", line 87, in optimize
ret = self.apply(fgraph, *args, **kwargs)
File "/usr/lib/python2.7/site-packages/theano/gpuarray/opt.py", line 322, in apply
target = infer_context_name(*fgraph.inputs)
File "/usr/lib/python2.7/site-packages/theano/gpuarray/basic_ops.py", line 122, in infer_context_name
raise ValueError("Could not infer context from inputs")
ValueError: Could not infer context from inputs
theano不能自動(dòng)支持多GPU,需要自己指定一個(gè),只能在一個(gè)上面跑, 需要指定一個(gè)設(shè)備device=cuda0。
支持多GPU, 需要自己編程,參考http://deeplearning.net/software/theano/tutorial/using_multi_gpu.html#
2. tensorflow: ResourceExhaustedError: OOM when allocating tensor with
theano: MemoryError: Error allocating 1440000000 bytes of device memory (out of memory).
說明GPU內(nèi)存不夠,要調(diào)小輸入或網(wǎng)絡(luò)單元。
3. theano切換成新的GPU backend
WARNING (theano.sandbox.cuda): The cuda backend is deprecated and will be removed in the next release (v0.10)
theano 0.9.0從cuda backend切換gpuarray backend,需要安裝python2-Cython-0.25+和libgpuarray-0.6.3+, 然后通過gpuarray.preallocate來指定。
補(bǔ)充知識(shí):pytorch網(wǎng)絡(luò)輸入圖片通道在前在后(channel_first和channel_last)的問題
剛開始學(xué)習(xí)pytorch卷積神經(jīng)網(wǎng)絡(luò)的時(shí)候,網(wǎng)絡(luò)輸入要求是(batch,3,32,32),我們?nèi)绻胍獪y(cè)試自己電腦上的圖片格式為(32,32,3)。即網(wǎng)絡(luò)要求channel_first,本地圖片是channel_last,此時(shí)我們只需要使用numpy中的np.transpose()函數(shù)調(diào)整下通道的順序即可。
代碼如下:
import numpy as np import cv2 path = r"C:\Users\X_man\Desktop\image\cat.jpg" image = cv2.imread(path,0) image = cv2.resize(image,(32,32)) image = cv2.cvtColor(image,cv2.COLOR_GRAY2BGR) print(image.shape)
(32,32,3)
image = np.transpose(image,(2,0,1))
print(image.shape)
(3,32,32)
以上這篇關(guān)于Theano和Tensorflow多GPU使用問題就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Python爬取數(shù)據(jù)并寫入MySQL數(shù)據(jù)庫(kù)的實(shí)例
今天小編就為大家分享一篇Python爬取數(shù)據(jù)并寫入MySQL數(shù)據(jù)庫(kù)的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-06-06
Python3實(shí)現(xiàn)Web網(wǎng)頁(yè)圖片下載
這篇文章主要介紹了Python3通過request.urlopen實(shí)現(xiàn)Web網(wǎng)頁(yè)圖片下載,感興趣的小伙伴們可以參考一下2016-01-01
python中itertools模塊zip_longest函數(shù)詳解
itertools模塊包含創(chuàng)建高效迭代器的函數(shù),這些函數(shù)的返回值不是list,而是iterator(可迭代對(duì)象),可以用各種方式對(duì)數(shù)據(jù)執(zhí)行循環(huán)操作,今天我們來詳細(xì)探討下zip_longest函數(shù)2018-06-06
Python 通過requests實(shí)現(xiàn)騰訊新聞抓取爬蟲的方法
今天小編就為大家分享一篇Python 通過requests實(shí)現(xiàn)騰訊新聞抓取爬蟲的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-02-02
PyTorch數(shù)據(jù)讀取的實(shí)現(xiàn)示例
這篇文章主要介紹了PyTorch數(shù)據(jù)讀取的實(shí)現(xiàn)示例,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-03-03
Python 限制線程的最大數(shù)量的方法(Semaphore)
今天小編就為大家分享一篇Python 限制線程的最大數(shù)量的方法(Semaphore),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-02-02
Python實(shí)現(xiàn)Sqlite將字段當(dāng)做索引進(jìn)行查詢的方法
這篇文章主要介紹了Python實(shí)現(xiàn)Sqlite將字段當(dāng)做索引進(jìn)行查詢的方法,涉及Python針對(duì)sqlite數(shù)據(jù)庫(kù)索引操作的相關(guān)技巧,需要的朋友可以參考下2016-07-07
python二分法查找算法實(shí)現(xiàn)方法【遞歸與非遞歸】
這篇文章主要介紹了python二分法查找算法實(shí)現(xiàn)方法,結(jié)合實(shí)例形式分析了Python使用遞歸與非遞歸算法實(shí)現(xiàn)二分查找的相關(guān)操作技巧,需要的朋友可以參考下2019-12-12

