Skip to content

Commit aa47fe0

Browse files
committed
update auto graph.
1 parent 00be3d2 commit aa47fe0

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

17tensorflow/tf2/8autograph.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,22 @@
33
@author:XuMing([email protected])
44
@description:
55
"""
6+
import numpy as np
7+
import tensorflow as tf
8+
from tensorflow.python.ops import control_flow_util
9+
# 1.tf.function装饰器¶
10+
# 当使用tf.function注释函数时,可以像调用任何其他函数一样调用它。 它将被编译成图,这意味着可以获得更快执行,更好地在GPU或TPU上运行或导出到SavedModel。
11+
@tf.function
12+
def simple_nn_layer(x, y):
13+
return tf.nn.softmax(tf.matmul(x, y))
614

15+
16+
x = tf.random.uniform((3, 3))
17+
y = tf.random.uniform((3, 3))
18+
19+
a = simple_nn_layer(x, y)
20+
print(a)
21+
with tf.GradientTape as tape:
22+
logits = a
23+
b = logits
24+
print(b)

0 commit comments

Comments
 (0)