tensorflow tf.device() (返回指定要用于新创建的操作的默认设备的上下文管理器)
生活随笔
收集整理的這篇文章主要介紹了
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() (返回指定要用于新创建的操作的默认设备的上下文管理器)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Jupyter notebook Ipy
- 下一篇: pycharm shadows name