日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

tensorflow tf.device() (返回指定要用于新创建的操作的默认设备的上下文管理器)

發布時間:2025/3/20 编程问答 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 tensorflow tf.device() (返回指定要用于新创建的操作的默认设备的上下文管理器) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
@tf_export("device") def device(device_name_or_function):"""Wrapper for `Graph.device()` using the default graph.使用默認圖形的“ Graph.device()”包裝器。See`tf.Graph.device`for more details.Args:device_name_or_function: The device name or function to use inthe context.在上下文中使用的設備名稱或功能。Returns:A context manager that specifies the default device to use for newlycreated ops.一個上下文管理器,它指定要用于新創建的操作的默認設備。Raises:RuntimeError: If eager execution is enabled and a function is passed in.如果啟用了急切執行并傳遞了函數。"""if context.executing_eagerly():# TODO(agarwal): support device functions in EAGER mode.if callable(device_name_or_function):raise RuntimeError("tf.device does not support functions when eager execution ""is enabled.")return context.device(device_name_or_function)else:return get_default_graph().device(device_name_or_function)

示例:

# -*- coding: utf-8 -*- """ @File : 191208_test_Eager_execution_once_cls.py @Time : 2019/12/8 12:25 @Author : Dontla @Email : sxana@qq.com @Software: PyCharm """from timeit import timeit import tensorflow as tfwith tf.device("CPU:0"):x = tf.random_uniform([1000, 1000])print(x.device) # /device:CPU:0print(type(x.device)) # <class 'str'>

總結

以上是生活随笔為你收集整理的tensorflow tf.device() (返回指定要用于新创建的操作的默认设备的上下文管理器)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。