當前位置: 首頁>>代碼示例>>Python>>正文


Python tensorflow.disable_eager_execution方法代碼示例

本文整理匯總了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 
開發者ID:delira-dev,項目名稱:delira,代碼行數:32,代碼來源:test_abstract_models.py

示例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() 
開發者ID:delira-dev,項目名稱:delira,代碼行數:9,代碼來源:test_tf.py

示例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() 
開發者ID:BlackHC,項目名稱:tfpyth,代碼行數:16,代碼來源:test_adapters.py

示例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') 
開發者ID:apache,項目名稱:incubator-tvm,代碼行數:12,代碼來源:test_forward.py

示例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() 
開發者ID:delira-dev,項目名稱:delira,代碼行數:45,代碼來源:test_tf_graph.py

示例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)) 
開發者ID:delira-dev,項目名稱:delira,代碼行數:51,代碼來源:test_tf.py


注:本文中的tensorflow.disable_eager_execution方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。