Tensorflow2.0-HelloWord

300 阅读1分钟

源码

import tensorflow as tf
# tensorflow 2.0 不在有Session 需要这样处理
tf.compat.v1.disable_eager_execution()

# 定义常量操作 hello
hello = tf.constant("Hello TensorFlow")
# 创建一个会话
sess = tf.compat.v1.Session()
# 执行常量操作 hello 并打印到标准输出
print(sess.run(hello))

输出

2021-05-10 01:03:24.797692: I tensorflow/compiler/jit/xla_cpu_device.cc:41] Not creating XLA devices, tf_xla_enable_xla_devices not set
2021-05-10 01:03:24.797925: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX2 FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2021-05-10 01:03:24.798973: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:196] None of the MLIR optimization passes are enabled (registered 0 passes)
b'Hello TensorFlow'