当前位置: 首页>>代码示例>>Python>>正文


Python tensorflow.enable_eager_execution方法代码示例

本文整理汇总了Python中tensorflow.enable_eager_execution方法的典型用法代码示例。如果您正苦于以下问题:Python tensorflow.enable_eager_execution方法的具体用法?Python tensorflow.enable_eager_execution怎么用?Python tensorflow.enable_eager_execution使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tensorflow的用法示例。


在下文中一共展示了tensorflow.enable_eager_execution方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import enable_eager_execution [as 别名]
def main(_):
  logging.set_verbosity(FLAGS.log_level)

  if FLAGS.tf_eager:
    tf.enable_eager_execution()

  if FLAGS.tf_xla:
    tf.config.optimizer.set_jit(True)

  _setup_gin()

  # Setup output directory
  output_dir = FLAGS.output_dir or _default_output_dir()
  trax.log("Using --output_dir %s" % output_dir)
  output_dir = os.path.expanduser(output_dir)

  # If on TPU, let JAX know.
  if FLAGS.use_tpu:
    jax.config.update("jax_platform_name", "tpu")

  trax.train(output_dir=output_dir) 
开发者ID:yyht,项目名称:BERT,代码行数:23,代码来源:trainer.py

示例2: main

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import enable_eager_execution [as 别名]
def main():
    tf.enable_eager_execution()


    subreddit_based_sim_dfs(subreddits=subs, treat_strength=beta0, con_strength=beta1, noise_level=gamma, setting=mode, seed=0,
                            base_output_dir=base_output_dir)



    # print(itr.get_next()["token_ids"].name)
    # for i in range(1000):
    #     sample = itr.get_next()

    #
    # print(np.unique(df['year']))
    # print(df.groupby(['year'])['buzzy_title'].agg(np.mean))
    # print(df.groupby(['year'])['theorem_referenced'].agg(np.mean))
    # print(df.groupby(['year'])['accepted'].agg(np.mean)) 
开发者ID:blei-lab,项目名称:causal-text-embeddings,代码行数:20,代码来源:array_from_dataset.py

示例3: main

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import enable_eager_execution [as 别名]
def main(_):
  # Enables eager context for TF 1.x. TF 2.x will use eager by default.
  # This is used to conveniently get a representative dataset generator using
  # TensorFlow training input helper.
  tf.enable_eager_execution()

  converter = tf.lite.TFLiteConverter.from_saved_model(
      FLAGS.saved_model_dir,
      input_arrays=[FLAGS.input_name],
      output_arrays=[FLAGS.output_name])
  # Chooses a tf.lite.Optimize mode:
  # https://www.tensorflow.org/api_docs/python/tf/lite/Optimize
  converter.optimizations = [tf.lite.Optimize.OPTIMIZE_FOR_LATENCY]
  converter.representative_dataset = tf.lite.RepresentativeDataset(
      representative_dataset_gen)
  if FLAGS.require_int8:
    converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS_INT8]

  tflite_buffer = converter.convert()
  tf.gfile.GFile(FLAGS.output_tflite, "wb").write(tflite_buffer)
  print("tflite model written to %s" % FLAGS.output_tflite) 
开发者ID:artyompal,项目名称:tpu_models,代码行数:23,代码来源:post_quantization.py

示例4: _setup_tfeager

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import enable_eager_execution [as 别名]
def _setup_tfeager(*args):
        import tensorflow as tf
        tf.enable_eager_execution()
        tf.reset_default_graph()
        from delira.models.backends.tf_eager import AbstractTfEagerNetwork

        class Model(AbstractTfEagerNetwork):
            def __init__(self):
                super().__init__()

                self.dense = tf.keras.layers.Dense(1, activation="relu")

            def call(self, x: tf.Tensor):
                return {"pred": self.dense(x)}

        return Model() 
开发者ID:delira-dev,项目名称:delira,代码行数:18,代码来源:test_abstract_models.py

示例5: test_resize_upsample_tf

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import enable_eager_execution [as 别名]
def test_resize_upsample_tf(self):
    if BACKEND != 'tensorflow':
      return
    import tensorflow as tf
    tf.enable_eager_execution()
    from VSR.Backend.TF.Util import upsample

    Im = Image.open(URL)
    for X in [Im, Im.convert('L')]:
      w = X.width
      h = X.height
      for ss in [2, 3, 4, 5, 6]:
        GT = X.resize([w * ss, h * ss], Image.BICUBIC)
        gt = np.asarray(GT, dtype='float32') / 255
        x = tf.constant(np.asarray(X), dtype='float32') / 255
        y = upsample(x, ss).numpy().clip(0, 1)
        self.assertGreaterEqual(self.psnr(y, gt), 30, f"{X.mode}, {ss}") 
开发者ID:LoSealL,项目名称:VideoSuperResolution,代码行数:19,代码来源:image_test.py

示例6: test_resize_downsample_tf

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import enable_eager_execution [as 别名]
def test_resize_downsample_tf(self):
    if BACKEND != 'tensorflow':
      return
    import tensorflow as tf
    tf.enable_eager_execution()
    from VSR.Backend.TF.Util import downsample

    Im = Image.open(URL)
    for X in [Im, Im.convert('L')]:
      w = X.width
      h = X.height
      for ss in [2, 4, 6, 8]:
        w_ = w - w % ss
        h_ = h - h % ss
        X = X.crop([0, 0, w_, h_])
        GT = X.resize([w_ // ss, h_ // ss], Image.BICUBIC)
        gt = np.asarray(GT, dtype='float32') / 255
        x = tf.constant(np.asarray(X), dtype='float32') / 255
        y = downsample(x, ss).numpy().clip(0, 1)
        self.assertGreaterEqual(self.psnr(y, gt), 30, f"{X.mode}, {ss}") 
开发者ID:LoSealL,项目名称:VideoSuperResolution,代码行数:22,代码来源:image_test.py

示例7: test_kgcn_runs

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import enable_eager_execution [as 别名]
def test_kgcn_runs(self):
        tf.enable_eager_execution()

        graph = GraphsTuple(nodes=tf.convert_to_tensor(np.array([[1, 2, 0], [1, 0, 0], [1, 1, 0]], dtype=np.float32)),
                            edges=tf.convert_to_tensor(np.array([[1, 0, 0], [1, 0, 0]], dtype=np.float32)),
                            globals=tf.convert_to_tensor(np.array([[0, 0, 0, 0, 0]], dtype=np.float32)),
                            receivers=tf.convert_to_tensor(np.array([1, 2], dtype=np.int32)),
                            senders=tf.convert_to_tensor(np.array([0, 1], dtype=np.int32)),
                            n_node=tf.convert_to_tensor(np.array([3], dtype=np.int32)),
                            n_edge=tf.convert_to_tensor(np.array([2], dtype=np.int32)))

        thing_embedder = ThingEmbedder(node_types=['a', 'b', 'c'], type_embedding_dim=5, attr_embedding_dim=6,
                                       categorical_attributes={'a': ['a1', 'a2', 'a3'], 'b': ['b1', 'b2', 'b3']},
                                       continuous_attributes={'c': (0, 1)})

        role_embedder = RoleEmbedder(num_edge_types=2, type_embedding_dim=5)

        kgcn = KGCN(thing_embedder, role_embedder, edge_output_size=3, node_output_size=3)

        kgcn(graph, 2) 
开发者ID:graknlabs,项目名称:kglib,代码行数:22,代码来源:core_IT.py

示例8: main

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import enable_eager_execution [as 别名]
def main():
    tf.enable_eager_execution()
    tf.app.run(main=train) 
开发者ID:spotify,项目名称:spotify-tensorflow,代码行数:5,代码来源:main.py

示例9: main

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import enable_eager_execution [as 别名]
def main():
    # Enable eager execution for DataFrame endpoint
    import tensorflow as tf
    tf.enable_eager_execution()

    # Set up training data
    train_data_dir = get_data_dir("train")
    train_data = os.path.join(train_data_dir, "part-*")
    schema_path = os.path.join(train_data_dir, "_inferred_schema.pb")

    df_train_data = next(Datasets.dataframe.examples_via_schema(train_data,
                                                                schema_path,
                                                                batch_size=1024))

    # the feature keys are ordered alphabetically for determinism
    label_keys = sorted([l for l in set(df_train_data.columns) if l.startswith("class_name")])
    feature_keys = sorted(set(df_train_data.columns).difference(label_keys))

    label = df_train_data[label_keys].apply(transform_labels, axis=1)
    features = df_train_data[feature_keys]

    # Build model
    from sklearn.linear_model import LogisticRegression
    model = LogisticRegression(multi_class="multinomial", solver="newton-cg")
    model.fit(features, label)

    # Set up eval data
    eval_data_dir = get_data_dir("eval")
    eval_data = os.path.join(eval_data_dir, "part-*")
    df_eval_data = next(Datasets.dataframe.examples_via_schema(eval_data,
                                                               schema_path,
                                                               batch_size=1024))

    eval_label = df_eval_data[label_keys].apply(transform_labels, axis=1)
    eval_features = df_eval_data[feature_keys]

    # Evaluate model
    score = model.score(eval_features, eval_label)
    print("Score is %f" % score) 
开发者ID:spotify,项目名称:spotify-tensorflow,代码行数:41,代码来源:main.py

示例10: set_backend

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import enable_eager_execution [as 别名]
def set_backend(backend):
    global _backend, _func_dict
    if _backend is not None:
        raise RuntimeError('Backend is already specified')
    if type(backend) is not int or backend < 0 or backend > 4:
        raise ValueError('value of backend not valid')

    _backend = backend
    if backend is TENSORFLOW:
        from .tensorflow_ops import func_dict
    elif backend is TENSORFLOW_EAGER:
        import tensorflow as tf
        tf_version = tf.__version__.split('.')
        if int(tf_version[0]) < 1:
            raise RuntimeError('Tensorflow version too low')
        if int(tf_version[0]) == 1 and int(tf_version[1]) < 7:
            raise RuntimeError('Tensorflow version too low')
        tf.enable_eager_execution()
        from .tensorflow_eager_ops import func_dict
    elif backend is TENSORFLOW_KERAS:
        import tensorflow as tf
        from .tensorflow_keras_ops import func_dict
    elif backend is PYTORCH:
        from .pytorch_ops import func_dict
    elif backend is KERAS:
        from .keras_ops import func_dict
    _func_dict = func_dict
    if _func_dict is None:
        raise RuntimeError('Backend %s is not supported' % backend) 
开发者ID:negrinho,项目名称:deep_architect,代码行数:31,代码来源:backend.py

示例11: setUp

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import enable_eager_execution [as 别名]
def setUp(self) -> None:
        tf.compat.v1.reset_default_graph()
        tf.compat.v1.enable_eager_execution()
        print("Eager Execution:", tf.executing_eagerly()) 
开发者ID:kpe,项目名称:bert-for-tf2,代码行数:6,代码来源:test_extend_segments.py

示例12: setUpClass

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import enable_eager_execution [as 别名]
def setUpClass(cls):
        tf.enable_eager_execution()

        argv = [
            '--gqa-paths',  'input_data/raw/test.yaml',
            '--input-dir', 'input_data/processed/test',
            '--limit', '100',
            '--predict-holdback', '0.1',
            '--eval-holdback', '0.1',
        ]

        args = get_args(argv=argv)
        cls.args = args

        build(args) 
开发者ID:Octavian-ai,项目名称:shortest-path,代码行数:17,代码来源:build_test.py

示例13: main

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import enable_eager_execution [as 别名]
def main():
    tf.enable_eager_execution()

    buzzy_title_based_sim_dfs(treat_strength=beta0, con_strength=beta1, noise_level=gamma, setting=mode, seed=0,
                            base_output_dir=base_output_dir) 
开发者ID:blei-lab,项目名称:causal-text-embeddings,代码行数:7,代码来源:array_from_dataset.py

示例14: map_func

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import enable_eager_execution [as 别名]
def map_func(x):
        x['a'] = x['a'] * 10
        return x

    # tf.enable_eager_execution() 
开发者ID:csmliu,项目名称:STGAN,代码行数:7,代码来源:memory_data.py

示例15: enable_eager

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import enable_eager_execution [as 别名]
def enable_eager(self):
        tf.enable_eager_execution() 
开发者ID:sharadmv,项目名称:deepx,代码行数:4,代码来源:tensorflow.py


注:本文中的tensorflow.enable_eager_execution方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。