Lonely Caption 2020-09-25 09:05 采纳率: 0%
浏览 1015

请问如何将Tensor类型转换为EagerTensor类型呢?

请问在TF2.0中如何将Tensor类型转换为EagerTensor类型呢?

本人尝试过tf.py_function()这个方法,可是该方法中自定义的函数未被调用

代码如下

   def showTensor(self, inputs, output):
        a = inputs.numpy()
        b = output.numpy()
        print(b)
        print(a)
        print(type(a))
        print(a.shape)
        return a

    def Myshow_all(self, inputs, output):
        y = tf.py_function(self.showTensor, [inputs, output], tf.float32)
        print(y)
        print(type(y))
        print(y.shape)
        return y

    def _pooling_function(self, inputs, pool_size, strides,
                          padding, data_format):
        output = K.pool2d(inputs, pool_size, strides,
                          padding, data_format,
                          pool_mode='max')
        a = self.Myshow_all(inputs, output)
        print(a)
        print(type(a))
        print(a.shape)
        return output

tf.py_function跑着没问题 但是showTensor这个函数却未执行
求大佬解惑。

本人尝试的第二种方法是使用tf.init_scope():

但是inputs始终是Tensor而不是EagerTensor,尽管环境已由静态变为动态。

            with tf.init_scope():
                print(tf.executing_eagerly())
                a=tf.convert_to_tensor(np.ones([2, 3]))
                print(type(inputs))
                print(type(a))

本人小白,已经卡一个星期了,求高人解惑。

万分感谢!!!

  • 写回答

3条回答 默认 最新

  • 莫陌莫墨 2021-05-18 11:20
    关注

    解决了吗?遇到童颜的的问题

    评论

报告相同问题?

悬赏问题

  • ¥15 MATLAB怎么通过柱坐标变换画开口是圆形的旋转抛物面?
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿