關(guān)于Theano和Tensorflow多GPU使用問(wèn)題
我使用的是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).
說(shuō)明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+, 然后通過(guò)gpuarray.preallocate來(lái)指定。
補(bǔ)充知識(shí):pytorch網(wǎng)絡(luò)輸入圖片通道在前在后(channel_first和channel_last)的問(wèn)題
剛開(kāi)始學(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使用問(wèn)題就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
在Linux上安裝Python的Flask框架和創(chuàng)建第一個(gè)app實(shí)例的教程
這篇文章主要介紹了在Linux上安裝Python的Flask框架和創(chuàng)建第一個(gè)app實(shí)例,包括創(chuàng)建一個(gè)HTML模版和利用Jinja2模板引擎來(lái)做渲染的步驟,需要的朋友可以參考下2015-03-03
Python疫情確診折線圖實(shí)現(xiàn)數(shù)據(jù)可視化實(shí)例詳解
數(shù)據(jù)可視化是指用圖形或表格的方式來(lái)呈現(xiàn)數(shù)據(jù)。圖表能夠清楚地呈現(xiàn)數(shù)據(jù)性質(zhì),?以及數(shù)據(jù)間或?qū)傩蚤g的關(guān)系,可以輕易地讓人看圖釋義。用戶通過(guò)探索圖(Exploratory?Graph)可以了解數(shù)據(jù)的特性、尋找數(shù)據(jù)的趨勢(shì)、降低數(shù)據(jù)的理解門(mén)檻2022-09-09
python實(shí)現(xiàn)帶聲音的摩斯碼翻譯實(shí)現(xiàn)方法
這篇文章主要介紹了python實(shí)現(xiàn)帶聲音的摩斯碼翻譯實(shí)現(xiàn)方法,涉及pygame模塊操作及摩斯碼實(shí)現(xiàn)技巧,需要的朋友可以參考下2015-05-05
Flask進(jìn)階之構(gòu)建RESTful?API和數(shù)據(jù)庫(kù)交互操作
這篇文章主要為大家介紹了Flask進(jìn)階之構(gòu)建RESTful API和數(shù)據(jù)庫(kù)交互操作示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-08-08
python Hypothesis生成和執(zhí)行大量的測(cè)試用例
Hypothesis是一個(gè)基于屬性的測(cè)試(property-based testing)庫(kù),它能夠幫助我們生成和執(zhí)行大量的測(cè)試用例,與傳統(tǒng)的單元測(cè)試相比,屬性測(cè)試更加靈活和全面,能夠發(fā)現(xiàn)更多的邊界情況和潛在的錯(cuò)誤2024-01-01
Python讀取圖片為16進(jìn)制表示簡(jiǎn)單代碼
這篇文章主要介紹了Python讀取圖片為16進(jìn)制表示簡(jiǎn)單代碼,具有一定借鑒價(jià)值,需要的朋友可以參考下2018-01-01

