好湿?好紧?好多水好爽自慰,久久久噜久噜久久综合,成人做爰A片免费看黄冈,机机对机机30分钟无遮挡

主頁 > 知識庫 > 詳解tf.device()指定tensorflow運行的GPU或CPU設備實現

詳解tf.device()指定tensorflow運行的GPU或CPU設備實現

熱門標簽:400電話辦理費用收費 千呼ai電話機器人免費 高德地圖標注字母 深圳網絡外呼系統代理商 申請辦個400電話號碼 騰訊地圖標注有什么版本 外呼系統前面有錄音播放嗎 鎮江人工外呼系統供應商 柳州正規電銷機器人收費

在tensorflow中,我們可以使用 tf.device() 指定模型運行的具體設備,可以指定運行在GPU還是CUP上,以及哪塊GPU上。

設置使用GPU

使用 tf.device('/gpu:1') 指定Session在第二塊GPU上運行:

import tensorflow as tf
 
with tf.device('/gpu:1'):
  v1 = tf.constant([1.0, 2.0, 3.0], shape=[3], name='v1')
  v2 = tf.constant([1.0, 2.0, 3.0], shape=[3], name='v2')
  sumV12 = v1 + v2
 
  with tf.Session(config=tf.ConfigProto(log_device_placement=True)) as sess:
    print sess.run(sumV12)

ConfigProto() 中參數 log_device_placement=True  會打印出執行操作所用的設備,以上輸出:


如果安裝的是GPU版本的tensorflow,機器上有支持的GPU,也正確安裝了顯卡驅動、CUDA和cuDNN,默認情況下,Session會在GPU上運行:

import tensorflow as tf
 
v1 = tf.constant([1.0, 2.0, 3.0], shape=[3], name='v1')
v2 = tf.constant([1.0, 2.0, 3.0], shape=[3], name='v2')
sumV12 = v1 + v2
 
with tf.Session(config=tf.ConfigProto(log_device_placement=True)) as sess:
  print sess.run(sumV12)

默認在GPU:0上執行:


設置使用cpu

tensorflow中不同的GPU使用/gpu:0和/gpu:1區分,而CPU不區分設備號,統一使用 /cpu:0

import tensorflow as tf
 
with tf.device('/cpu:0'):
  v1 = tf.constant([1.0, 2.0, 3.0], shape=[3], name='v1')
  v2 = tf.constant([1.0, 2.0, 3.0], shape=[3], name='v2')
  sumV12 = v1 + v2
 
  with tf.Session(config=tf.ConfigProto(log_device_placement=True)) as sess:
    print sess.run(sumV12)

到此這篇關于詳解tf.device()指定tensorflow運行的GPU或CPU設備實現的文章就介紹到這了,更多相關tensorflow運行GPU或CPU內容請搜索腳本之家以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持腳本之家!

您可能感興趣的文章:
  • tensorflow 利用expand_dims和squeeze擴展和壓縮tensor維度方式
  • TensorFlow低版本代碼自動升級為1.0版本
  • TensorFlow的環境配置與安裝方法
  • TensorFlow2.0使用keras訓練模型的實現
  • 解決tensorflow模型壓縮的問題_踩坑無數,總算搞定

標簽:哈爾濱 海南 烏蘭察布 郴州 合肥 烏蘭察布 平頂山 大慶

巨人網絡通訊聲明:本文標題《詳解tf.device()指定tensorflow運行的GPU或CPU設備實現》,本文關鍵詞  詳解,tf.device,指定,tensorflow,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《詳解tf.device()指定tensorflow運行的GPU或CPU設備實現》相關的同類信息!
  • 本頁收集關于詳解tf.device()指定tensorflow運行的GPU或CPU設備實現的相關信息資訊供網民參考!
  • 推薦文章