为了效率!!!eager与静态图转换的那些坑
eager模式: | 就是动态图 |
---|---|
调用方法: | tensorflow2.0默认eager模式 |
优点 | Python写法,方便调试 |
缺点 | 比自动图速度慢 |
静 态 图 模 式 : | |
---|---|
调用方法: | 需要在函数上方加上@tf.function装饰 |
优点 | tf写法,速度快 |
缺点 | 不如python写法直观 |
转换方式 | 在头上加@tf.function |
---|
第一个大坑
#调用静态图的例子
@tf.function
def f():
a = tf.constant([[10,10],[11.,1.]])
x = tf.constant([[1.,0.],[0.,1.]])
b = tf.Variable(12.)
y = tf.matmul(a, x)