當前位置:
首頁 >
tensorflow tf.enable_eager_execution()(立即执行操作,不添加到稍后在“ tf.Session”中执行的图)
發布時間:2025/3/19
48
豆豆
生活随笔
收集整理的這篇文章主要介紹了
tensorflow tf.enable_eager_execution()(立即执行操作,不添加到稍后在“ tf.Session”中执行的图)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
@tf_export("enable_eager_execution")
def enable_eager_execution(config=None,device_policy=None,execution_mode=None):"""Enables eager execution for the lifetime of this program.在此程序的生命周期內啟用急切執行。Eager execution provides an imperative interface to TensorFlow. With eagerexecution enabled, TensorFlow functions execute operations immediately (asopposed to adding to a graph to be executed later in a `tf.Session`) andreturn concrete values (as opposed to symbolic references to a node in acomputational graph).急切的執行為TensorFlow提供了必要的接口。 啟用急切執行后,TensorFlow函數立即執行操作(與添加到稍后在“ tf.Session”中執行的圖相反)并返回具體值(與對計算圖中的節點的符號引用相反)。For example:tf.enable_eager_execution()# After eager execution is enabled, operations are executed as they are# defined and Tensor objects hold concrete values, which can be accessed as# numpy.ndarray`s through the numpy() method.啟用急切執行后,將按定義的方式執行操作,并且Tensor對象保留具體值,可通過numpy()方法以numpy.ndarray的形式訪問這些值。# 斷言,如果斷言不正確,就會拋出assertion errorassert tf.multiply(6, 7).numpy() == 42Eager execution cannot be enabled after TensorFlow APIs have been used tocreate or execute graphs. It is typically recommended to invoke this functionat program startup and not in a library (as most libraries should be usableboth with and without eager execution).在使用TensorFlow API創建或執行圖形之后,無法啟用急切執行。 通常建議在程序啟動時而不是在庫中調用此函數(因為大多數庫在有急執行或無急切執行的情況下都可用)。Args:config: (Optional.) A `tf.ConfigProto` to use to configure the environmentin which operations are executed. Note that `tf.ConfigProto` is alsoused to configure graph execution (via `tf.Session`) and many optionswithin `tf.ConfigProto` are not implemented (or are irrelevant) wheneager execution is enabled.tf.ConfigProto用于配置執行操作的環境。 請注意,`tf.ConfigProto`還用于配置圖形執行(通過`tf.Session`),并且在啟用急切執行時,`tf.ConfigProto`中的許多選項未實現(或不相關)。device_policy: (Optional.) Policy controlling how operations requiringinputs on a specific device (e.g., a GPU 0) handle inputs on a differentdevice (e.g. GPU 1 or CPU). When set to None, an appropriate value will bepicked automatically. The value picked may change between TensorFlowreleases.控制需要特定設備(例如GPU 0)上的輸入的操作如何處理不同設備(例如GPU 1或CPU)上的輸入的策略。 設置為“無”時,將自動選擇適當的值。 在TensorFlow版本之間選擇的值可能會變化。Valid values:- tf.contrib.eager.DEVICE_PLACEMENT_EXPLICIT: raises an error if theplacement is not correct.- tf.contrib.eager.DEVICE_PLACEMENT_WARN: copies the tensors which are noton the right device but logs a warning.- tf.contrib.eager.DEVICE_PLACEMENT_SILENT: silently copies the tensors.Note that this may hide performance problems as there is no notificationprovided when operations are blocked on the tensor being copied betweendevices.- tf.contrib.eager.DEVICE_PLACEMENT_SILENT_FOR_INT32: silently copiesint32 tensors, raising errors on the other ones.-tf.contrib.eager.DEVICE_PLACEMENT_EXPLICIT:如果放置位置不正確,則會引發錯誤。-tf.contrib.eager.DEVICE_PLACEMENT_WARN:復制不在正確設備上的張量,但會記錄警告。-tf.contrib.eager.DEVICE_PLACEMENT_SILENT:靜默復制張量。請注意,這可能會隱藏性能問題,因為在設備之間復制張量時,如果操作被阻止,則不會提供任何通知。-tf.contrib.eager.DEVICE_PLACEMENT_SILENT_FOR_INT32:靜默復制int32張量,從而在其他張量上產生錯誤。execution_mode: (Optional.) Policy controlling how operations dispatched areactually executed. When set to None, an appropriate value will be pickedautomatically. The value picked may change between TensorFlow releases.Valid values:控制實際執行調度的操作的策略。 設置為“無”時,將自動選擇適當的值。 在TensorFlow版本之間選擇的值可能會變化。- tf.contrib.eager.SYNC: executes each operation synchronously.- tf.contrib.eager.ASYNC: executes each operation asynchronously. Theseoperations may return "non-ready" handles.-tf.contrib.eager.SYNC:同步執行每個操作。-tf.contrib.eager.ASYNC:異步執行每個操作。 這些操作可能會返回“未就緒”句柄。Raises:ValueError: If eager execution is enabled after creating/executing aTensorFlow graph, or if options provided conflict with a previous callto this function.如果在創建/執行TensorFlow圖后啟用了急切執行,或者提供的選項與對該函數的先前調用沖突。"""if context.default_execution_mode != context.EAGER_MODE:return enable_eager_execution_internal(config=config,device_policy=device_policy,execution_mode=execution_mode,server_def=None)
總結
以上是生活随笔為你收集整理的tensorflow tf.enable_eager_execution()(立即执行操作,不添加到稍后在“ tf.Session”中执行的图)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 计算机中 什么是同步执行和异步执行?
- 下一篇: tensorflow tf.device