最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

解決TensorFlow程序無(wú)限制占用GPU的方法

 更新時(shí)間:2020年06月30日 10:06:57   作者:逃離那片海岸  
這篇文章主要介紹了解決TensorFlow程序無(wú)限制占用GPU的方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧

今天遇到一個(gè)奇怪的現(xiàn)象,使用tensorflow-gpu的時(shí)候,出現(xiàn)內(nèi)存超額~~如果我訓(xùn)練什么大型數(shù)據(jù)也就算了,關(guān)鍵我就寫了一個(gè)y=W*x…顯示如下圖所示:

程序如下:

import tensorflow as tf

w = tf.Variable([[1.0,2.0]])
b = tf.Variable([[2.],[3.]])

y = tf.multiply(w,b)

init_op = tf.global_variables_initializer()

with tf.Session() as sess:
 sess.run(init_op)
 print(sess.run(y))

出錯(cuò)提示:

占用的內(nèi)存越來(lái)越多,程序崩潰之后,整個(gè)電腦都奔潰了,因?yàn)檎麄€(gè)顯卡全被吃了

2018-06-10 18:28:00.263424: I T:\src\github\tensorflow\tensorflow\core\platform\cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
2018-06-10 18:28:00.598075: I T:\src\github\tensorflow\tensorflow\core\common_runtime\gpu\gpu_device.cc:1356] Found device 0 with properties: 
name: GeForce GTX 1060 major: 6 minor: 1 memoryClockRate(GHz): 1.6705
pciBusID: 0000:01:00.0
totalMemory: 6.00GiB freeMemory: 4.97GiB
2018-06-10 18:28:00.598453: I T:\src\github\tensorflow\tensorflow\core\common_runtime\gpu\gpu_device.cc:1435] Adding visible gpu devices: 0
2018-06-10 18:28:01.265600: I T:\src\github\tensorflow\tensorflow\core\common_runtime\gpu\gpu_device.cc:923] Device interconnect StreamExecutor with strength 1 edge matrix:
2018-06-10 18:28:01.265826: I T:\src\github\tensorflow\tensorflow\core\common_runtime\gpu\gpu_device.cc:929]  0 
2018-06-10 18:28:01.265971: I T:\src\github\tensorflow\tensorflow\core\common_runtime\gpu\gpu_device.cc:942] 0: N 
2018-06-10 18:28:01.266220: I T:\src\github\tensorflow\tensorflow\core\common_runtime\gpu\gpu_device.cc:1053] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 4740 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1060, pci bus id: 0000:01:00.0, compute capability: 6.1)
2018-06-10 18:28:01.331056: E T:\src\github\tensorflow\tensorflow\stream_executor\cuda\cuda_driver.cc:936] failed to allocate 4.63G (4970853120 bytes) from device: CUDA_ERROR_OUT_OF_MEMORY
2018-06-10 18:28:01.399111: E T:\src\github\tensorflow\tensorflow\stream_executor\cuda\cuda_driver.cc:936] failed to allocate 4.17G (4473767936 bytes) from device: CUDA_ERROR_OUT_OF_MEMORY
2018-06-10 18:28:01.468293: E T:\src\github\tensorflow\tensorflow\stream_executor\cuda\cuda_driver.cc:936] failed to allocate 3.75G (4026391040 bytes) from device: CUDA_ERROR_OUT_OF_MEMORY
2018-06-10 18:28:01.533138: E T:\src\github\tensorflow\tensorflow\stream_executor\cuda\cuda_driver.cc:936] failed to allocate 3.37G (3623751936 bytes) from device: CUDA_ERROR_OUT_OF_MEMORY
2018-06-10 18:28:01.602452: E T:\src\github\tensorflow\tensorflow\stream_executor\cuda\cuda_driver.cc:936] failed to allocate 3.04G (3261376768 bytes) from device: CUDA_ERROR_OUT_OF_MEMORY
2018-06-10 18:28:01.670225: E T:\src\github\tensorflow\tensorflow\stream_executor\cuda\cuda_driver.cc:936] failed to allocate 2.73G (2935238912 bytes) from device: CUDA_ERROR_OUT_OF_MEMORY
2018-06-10 18:28:01.733120: E T:\src\github\tensorflow\tensorflow\stream_executor\cuda\cuda_driver.cc:936] failed to allocate 2.46G (2641714944 bytes) from device: CUDA_ERROR_OUT_OF_MEMORY
2018-06-10 18:28:01.800101: E T:\src\github\tensorflow\tensorflow\stream_executor\cuda\cuda_driver.cc:936] failed to allocate 2.21G (2377543424 bytes) from device: CUDA_ERROR_OUT_OF_MEMORY
2018-06-10 18:28:01.862064: E T:\src\github\tensorflow\tensorflow\stream_executor\cuda\cuda_driver.cc:936] failed to allocate 1.99G (2139789056 bytes) from device: CUDA_ERROR_OUT_OF_MEMORY
2018-06-10 18:28:01.925434: E T:\src\github\tensorflow\tensorflow\stream_executor\cuda\cuda_driver.cc:936] failed to allocate 1.79G (1925810176 bytes) from device: CUDA_ERROR_OUT_OF_MEMORY
2018-06-10 18:28:01.986180: E T:\src\github\tensorflow\tensorflow\stream_executor\cuda\cuda_driver.cc:936] failed to allocate 1.61G (1733229056 bytes) from device: CUDA_ERROR_OUT_OF_MEMORY
2018-06-10 18:28:02.043456: E T:\src\github\tensorflow\tensorflow\stream_executor\cuda\cuda_driver.cc:936] failed to allocate 1.45G (1559906048 bytes) from device: CUDA_ERROR_OUT_OF_MEMORY
2018-06-10 18:28:02.103531: E T:\src\github\tensorflow\tensorflow\stream_executor\cuda\cuda_driver.cc:936] failed to allocate 1.31G (1403915520 bytes) from device: CUDA_ERROR_OUT_OF_MEMORY
2018-06-10 18:28:02.168973: E T:\src\github\tensorflow\tensorflow\stream_executor\cuda\cuda_driver.cc:936] failed to allocate 1.18G (1263524096 bytes) from device: CUDA_ERROR_OUT_OF_MEMORY
2018-06-10 18:28:02.229387: E T:\src\github\tensorflow\tensorflow\stream_executor\cuda\cuda_driver.cc:936] failed to allocate 1.06G (1137171712 bytes) from device: CUDA_ERROR_OUT_OF_MEMORY
2018-06-10 18:28:02.292997: E T:\src\github\tensorflow\tensorflow\stream_executor\cuda\cuda_driver.cc:936] failed to allocate 976.04M (1023454720 bytes) from device: CUDA_ERROR_OUT_OF_MEMORY
2018-06-10 18:28:02.356714: E T:\src\github\tensorflow\tensorflow\stream_executor\cuda\cuda_driver.cc:936] failed to allocate 878.44M (921109248 bytes) from device: CUDA_ERROR_OUT_OF_MEMORY
2018-06-10 18:28:02.418167: E T:\src\github\tensorflow\tensorflow\stream_executor\cuda\cuda_driver.cc:936] failed to allocate 790.59M (828998400 bytes) from device: CUDA_ERROR_OUT_OF_MEMORY
2018-06-10 18:28:02.482394: E T:\src\github\tensorflow\tensorflow\stream_executor\cuda\cuda_driver.cc:936] failed to allocate 711.54M (746098688 bytes) from device: CUDA_ERROR_OUT_OF_MEMORY

分析原因:

顯卡驅(qū)動(dòng)不是最新版本,用__驅(qū)動(dòng)軟件__更新一下驅(qū)動(dòng),或者自己去下載更新。

TF運(yùn)行太多,注銷全部程序沖洗打開。

由于TF內(nèi)核編寫的原因,默認(rèn)占用全部的GPU去訓(xùn)練自己的東西,也就是像meiguo一樣優(yōu)先政策吧

這個(gè)時(shí)候我們得設(shè)置兩個(gè)方面:

  • 選擇什么樣的占用方式??jī)?yōu)先占用__還是__按需占用
  • 選擇最大占用多少GPU,因?yàn)檎加眠^(guò)大GPU會(huì)導(dǎo)致其它程序奔潰。最好在0.7以下

先更新驅(qū)動(dòng):

再設(shè)置TF程序:

注意:?jiǎn)为?dú)設(shè)置一個(gè)不行!按照網(wǎng)上大神博客試了,結(jié)果效果還是很差(占用很多GPU)

設(shè)置TF:

  • 按需占用
  • 最大占用70%GPU

修改代碼如下:

import tensorflow as tf

w = tf.Variable([[1.0,2.0]])
b = tf.Variable([[2.],[3.]])

y = tf.multiply(w,b)

init_op = tf.global_variables_initializer()

config = tf.ConfigProto(allow_soft_placement=True)
gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.7)
config.gpu_options.allow_growth = True
with tf.Session(config=config) as sess:
 sess.run(init_op)
 print(sess.run(y))

成功解決:

2018-06-10 18:21:17.532630: I T:\src\github\tensorflow\tensorflow\core\platform\cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
2018-06-10 18:21:17.852442: I T:\src\github\tensorflow\tensorflow\core\common_runtime\gpu\gpu_device.cc:1356] Found device 0 with properties: 
name: GeForce GTX 1060 major: 6 minor: 1 memoryClockRate(GHz): 1.6705
pciBusID: 0000:01:00.0
totalMemory: 6.00GiB freeMemory: 4.97GiB
2018-06-10 18:21:17.852817: I T:\src\github\tensorflow\tensorflow\core\common_runtime\gpu\gpu_device.cc:1435] Adding visible gpu devices: 0
2018-06-10 18:21:18.511176: I T:\src\github\tensorflow\tensorflow\core\common_runtime\gpu\gpu_device.cc:923] Device interconnect StreamExecutor with strength 1 edge matrix:
2018-06-10 18:21:18.511397: I T:\src\github\tensorflow\tensorflow\core\common_runtime\gpu\gpu_device.cc:929]  0 
2018-06-10 18:21:18.511544: I T:\src\github\tensorflow\tensorflow\core\common_runtime\gpu\gpu_device.cc:942] 0: N 
2018-06-10 18:21:18.511815: I T:\src\github\tensorflow\tensorflow\core\common_runtime\gpu\gpu_device.cc:1053] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 4740 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1060, pci bus id: 0000:01:00.0, compute capability: 6.1)
[[2. 4.]
 [3. 6.]]

參考資料:

主要參考博客

錯(cuò)誤實(shí)例

到此這篇關(guān)于解決TensorFlow程序無(wú)限制占用GPU的方法 的文章就介紹到這了,更多相關(guān)TensorFlow 占用GPU內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 如何使用python寫截屏小工具

    如何使用python寫截屏小工具

    這篇文章主要介紹了如何使用python寫截屏小工具,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-09-09
  • Python中隱藏的五種實(shí)用技巧分享

    Python中隱藏的五種實(shí)用技巧分享

    這篇文章主要和大家分享五個(gè)Python中隱藏的實(shí)用技巧,文中的示例代碼講解詳細(xì),對(duì)我們學(xué)習(xí)Python有一定的幫助,感興趣的小伙伴可以學(xué)習(xí)一下
    2022-05-05
  • Python可變集合和不可變集合的構(gòu)造方法大全

    Python可變集合和不可變集合的構(gòu)造方法大全

    Python集合分為變集合和不可變集合兩種,本文就詳細(xì)的來(lái)介紹一下這兩種集合的使用,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-12-12
  • Django框架下在URLconf中指定視圖緩存的方法

    Django框架下在URLconf中指定視圖緩存的方法

    這篇文章主要介紹了Django框架下在URLconf中指定視圖緩存的方法,在Python豐富多彩的web框架中,Django是最具人氣的一個(gè),需要的朋友可以參考下
    2015-07-07
  • Python利用Turtle庫(kù)繪制一顆櫻花樹

    Python利用Turtle庫(kù)繪制一顆櫻花樹

    后唐李煜曾說(shuō)道,櫻花落盡春將困,秋千架下歸時(shí)。漏暗斜月遲遲,花在枝。櫻花落盡的時(shí)候春天也將過(guò)去了,秋千架下歸去時(shí)。天上的斜月姍姍來(lái)遲,花還在枝頭。本文將用Python+Turtle繪制一顆櫻花樹,感興趣的可以嘗試一下
    2022-04-04
  • Python機(jī)器學(xué)習(xí)pytorch模型選擇及欠擬合和過(guò)擬合詳解

    Python機(jī)器學(xué)習(xí)pytorch模型選擇及欠擬合和過(guò)擬合詳解

    如何發(fā)現(xiàn)可以泛化的模式是機(jī)器學(xué)習(xí)的根本問(wèn)題,將模型在訓(xùn)練數(shù)據(jù)上過(guò)擬合得比潛在分布中更接近的現(xiàn)象稱為過(guò)擬合,用于對(duì)抗過(guò)擬合的技術(shù)稱為正則化
    2021-10-10
  • Django配置kafka消息隊(duì)列的實(shí)現(xiàn)

    Django配置kafka消息隊(duì)列的實(shí)現(xiàn)

    本文主要介紹了Django配置kafka消息隊(duì)列的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2023-05-05
  • python3實(shí)現(xiàn)Dijkstra算法最短路徑的實(shí)現(xiàn)

    python3實(shí)現(xiàn)Dijkstra算法最短路徑的實(shí)現(xiàn)

    這篇文章主要介紹了python3實(shí)現(xiàn)Dijkstra算法最短路徑的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2021-05-05
  • python中的整除向下取整的操作方法

    python中的整除向下取整的操作方法

    Python中的//是整數(shù)除法運(yùn)算符,用于執(zhí)行向下取整的除法,返回商的整數(shù)部分,不會(huì)四舍五入,它在分治法、索引計(jì)算和整數(shù)運(yùn)算中非常有用,本文給大家介紹python中的整除向下取整的操作方法,感興趣的朋友一起看看吧
    2025-03-03
  • 使用python?itertools實(shí)現(xiàn)計(jì)算雙十一滿減湊單

    使用python?itertools實(shí)現(xiàn)計(jì)算雙十一滿減湊單

    一年一度的雙十一又到了,在這樣一個(gè)日子中,可能遇到一些問(wèn)題,首先是“湊單”問(wèn)題,本文將使用python中的itertools庫(kù)解決這一問(wèn)題,感興趣的可以了解下
    2024-11-11

最新評(píng)論

庆安县| 黔西县| 行唐县| 新宁县| 木兰县| 京山县| 宝鸡市| 酉阳| 翁牛特旗| 景德镇市| 合作市| 萝北县| 闽侯县| 禹城市| 光泽县| 潜江市| 上林县| 保靖县| 永州市| 洞口县| 宜黄县| 资阳市| 佛冈县| 文登市| 讷河市| 阿克| 武功县| 枝江市| 三明市| 凉城县| 蓝田县| 扬中市| 彰化市| 景洪市| 长乐市| 天峻县| 章丘市| 阿克苏市| 韩城市| 七台河市| 宜良县|