本文整理汇总了Python中tensorflow.disable_eager_execution方法的典型用法代码示例。如果您正苦于以下问题:Python tensorflow.disable_eager_execution方法的具体用法?Python tensorflow.disable_eager_execution怎么用?Python tensorflow.disable_eager_execution使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow
的用法示例。
在下文中一共展示了tensorflow.disable_eager_execution方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _setup_tfgraph
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import disable_eager_execution [as 别名]
def _setup_tfgraph(*args):
import tensorflow as tf
tf.disable_eager_execution()
tf.reset_default_graph()
from delira.models import AbstractTfGraphNetwork
from delira.training.backends.tf_graph.utils import \
initialize_uninitialized
class Model(AbstractTfGraphNetwork):
def __init__(self):
super().__init__()
self.dense = tf.keras.layers.Dense(1, activation="relu")
data = tf.placeholder(shape=[None, 1],
dtype=tf.float32)
labels = tf.placeholder_with_default(
tf.zeros([tf.shape(data)[0], 1]), shape=[None, 1])
preds_train = self.dense(data)
preds_eval = self.dense(data)
self.inputs["data"] = data
self.inputs["labels"] = labels
self.outputs_train["pred"] = preds_train
self.outputs_eval["pred"] = preds_eval
model = Model()
initialize_uninitialized(model._sess)
return model
示例2: setUp
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import disable_eager_execution [as 别名]
def setUp(self) -> None:
import tensorflow as tf
tf.reset_default_graph()
if "_eager" in self._testMethodName:
tf.enable_eager_execution()
else:
tf.disable_eager_execution()
示例3: test_pytorch_in_tensorflow_eager_mode
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import disable_eager_execution [as 别名]
def test_pytorch_in_tensorflow_eager_mode():
tf.enable_eager_execution()
tfe = tf.contrib.eager
def pytorch_expr(a, b):
return 3 * a + 4 * b * b
x = tfpyth.eager_tensorflow_from_torch(pytorch_expr)
assert tf.math.equal(x(tf.convert_to_tensor(1.0), tf.convert_to_tensor(3.0)), 39.0)
dx = tfe.gradients_function(x)
assert all(tf.math.equal(dx(tf.convert_to_tensor(1.0), tf.convert_to_tensor(3.0)), [3.0, 24.0]))
tf.disable_eager_execution()
示例4: test_forward_atan2
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import disable_eager_execution [as 别名]
def test_forward_atan2():
"""test operator tan """
tf.disable_eager_execution()
np_data_1 = np.random.uniform(1, 100, size=(2, 3, 5)).astype(np.float32)
np_data_2 = np.random.uniform(1, 100, size=(2, 3, 5)).astype(np.float32)
tf.reset_default_graph()
in_data_1 = tf.placeholder(tf.float32, (2, 3, 5), name="in_data_1")
in_data_2 = tf.placeholder(tf.float32, (2, 3, 5), name="in_data_2")
tf.atan2(in_data_1, in_data_2, name="atan2")
compare_tf_with_tvm([np_data_1, np_data_2], ['in_data_1:0', 'in_data_2:0'], 'atan2:0')
示例5: setUp
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import disable_eager_execution [as 别名]
def setUp(self) -> None:
if check_for_tf_graph_backend():
import tensorflow as tf
tf.disable_eager_execution()
from delira.training import TfGraphExperiment
config = DeliraConfig()
config.fixed_params = {
"model": {},
"training": {
"losses": {
"CE":
tf.losses.softmax_cross_entropy},
"optimizer_cls": tf.train.AdamOptimizer,
"optimizer_params": {"learning_rate": 1e-3},
"num_epochs": 2,
"metrics": {"mae": mean_absolute_error},
"lr_sched_cls": None,
"lr_sched_params": {}}
}
model_cls = DummyNetworkTfGraph
experiment_cls = TfGraphExperiment
else:
config = None
model_cls = None
experiment_cls = None
len_train = 100
len_test = 50
self._test_cases = [
{
"config": config,
"network_cls": model_cls,
"len_train": len_train,
"len_test": len_test,
"key_mapping": {"data": "data"},
}
]
self._experiment_cls = experiment_cls
super().setUp()
示例6: test_load_save
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import disable_eager_execution [as 别名]
def test_load_save(self):
import tensorflow as tf
tf.disable_eager_execution()
from delira.io.tf import load_checkpoint, save_checkpoint
from delira.models import AbstractTfGraphNetwork
from delira.training.backends import initialize_uninitialized
import numpy as np
class DummyNetwork(AbstractTfGraphNetwork):
def __init__(self, in_channels, n_outputs):
super().__init__(in_channels=in_channels, n_outputs=n_outputs)
self.net = self._build_model(in_channels, n_outputs)
@staticmethod
def _build_model(in_channels, n_outputs):
return tf.keras.models.Sequential(
layers=[
tf.keras.layers.Dense(
64,
input_shape=in_channels,
bias_initializer='glorot_uniform'),
tf.keras.layers.ReLU(),
tf.keras.layers.Dense(
n_outputs,
bias_initializer='glorot_uniform')])
net = DummyNetwork((32,), 1)
initialize_uninitialized(net._sess)
vars_1 = net._sess.run(tf.global_variables())
save_checkpoint("./model", model=net)
net._sess.run(tf.initializers.global_variables())
vars_2 = net._sess.run(tf.global_variables())
load_checkpoint("./model", model=net)
vars_3 = net._sess.run(tf.global_variables())
for var_1, var_2 in zip(vars_1, vars_2):
with self.subTest(var_1=var_1, var2=var_2):
self.assertTrue(np.all(var_1 != var_2))
for var_1, var_3 in zip(vars_1, vars_3):
with self.subTest(var_1=var_1, var_3=var_3):
self.assertTrue(np.all(var_1 == var_3))