tfe 在静态图中的使用

编程入门 行业动态 更新时间:2024-10-27 04:36:20

tfe 在静态<a href=https://www.elefans.com/category/jswz/34/1770587.html style=图中的使用"/>

tfe 在静态图中的使用

原文链接: tfe 在静态图中的使用

上一篇: tfe mnist 使用dataset 分类 保存和载入

下一篇: tfe keras 任意大小的灰度转换

通过tf.contrib.eager.py_func可以在静态图运行中使用tfe

参数分别为:

1,用于调用的函数

2,输入的参数,是一个列表

3,输出类型

4,名称

tf.contrib.eager.py_func(func,inp,Tout,name=None
)

在自定义函数中获取数值,并将其求和后返回

完整代码

import tensorflow as tfdef my_py_func(x):# print(x)  # but it's eager!# return 1for i in x:print(i)# tf.Tensor(1.0, shape=(), dtype=float32)# tf.Tensor(2.0, shape=(), dtype=float32)# tf.Tensor(3.0, shape=(), dtype=float32)sum = tf.reduce_sum(x)sum = tf.reduce_sum(x, axis=0)  # sum  tf.Tensor(6.0, shape=(), dtype=float32)return sumx = tf.Variable([1., 2., 3.])print(x)  # <tf.Variable 'Variable:0' shape=(3,) dtype=float32_ref>
with tf.Session() as sess:sess.run(tf.global_variables_initializer())y = tf.contrib.eager.py_func(func=my_py_func, inp=[x], Tout=tf.float32)print(y, y.eval())  # Tensor("EagerPyFunc:0", dtype=float32) 6.0

更多推荐

tfe 在静态图中的使用

本文发布于:2024-03-08 01:17:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1719462.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图中   静态   tfe

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!