關于Theano和Tensorflow多GPU使用問題
我使用的是tensorflow-gpu (1.2.1)和Theano (0.9.0),2個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不能自動支持多GPU,需要自己指定一個,只能在一個上面跑, 需要指定一個設備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內存不夠,要調小輸入或網絡單元。
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來指定。
補充知識:pytorch網絡輸入圖片通道在前在后(channel_first和channel_last)的問題
剛開始學習pytorch卷積神經網絡的時候,網絡輸入要求是(batch,3,32,32),我們如果想要測試自己電腦上的圖片格式為(32,32,3)。即網絡要求channel_first,本地圖片是channel_last,此時我們只需要使用numpy中的np.transpose()函數(shù)調整下通道的順序即可。
代碼如下:
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)
以上這篇關于Theano和Tensorflow多GPU使用問題就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
Python爬取數(shù)據(jù)并寫入MySQL數(shù)據(jù)庫的實例
今天小編就為大家分享一篇Python爬取數(shù)據(jù)并寫入MySQL數(shù)據(jù)庫的實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-06-06
python中itertools模塊zip_longest函數(shù)詳解
itertools模塊包含創(chuàng)建高效迭代器的函數(shù),這些函數(shù)的返回值不是list,而是iterator(可迭代對象),可以用各種方式對數(shù)據(jù)執(zhí)行循環(huán)操作,今天我們來詳細探討下zip_longest函數(shù)2018-06-06
Python 通過requests實現(xiàn)騰訊新聞抓取爬蟲的方法
今天小編就為大家分享一篇Python 通過requests實現(xiàn)騰訊新聞抓取爬蟲的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-02-02
PyTorch數(shù)據(jù)讀取的實現(xiàn)示例
這篇文章主要介紹了PyTorch數(shù)據(jù)讀取的實現(xiàn)示例,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2021-03-03
Python 限制線程的最大數(shù)量的方法(Semaphore)
今天小編就為大家分享一篇Python 限制線程的最大數(shù)量的方法(Semaphore),具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-02-02
Python實現(xiàn)Sqlite將字段當做索引進行查詢的方法
這篇文章主要介紹了Python實現(xiàn)Sqlite將字段當做索引進行查詢的方法,涉及Python針對sqlite數(shù)據(jù)庫索引操作的相關技巧,需要的朋友可以參考下2016-07-07
python二分法查找算法實現(xiàn)方法【遞歸與非遞歸】
這篇文章主要介紹了python二分法查找算法實現(xiàn)方法,結合實例形式分析了Python使用遞歸與非遞歸算法實現(xiàn)二分查找的相關操作技巧,需要的朋友可以參考下2019-12-12

