TF2.0中,在最大池化层的源码当中使用了tf.py_function(),自定义了一个函数,想将Tensor转为Numpy矩阵从而进行一些操作,然而程序运行时,却将自定义的函数忽略掉了,自定义函数中的print()函数未作输出,返回值为<unknow>,如果py_function()中的参数写错了,系统还是会报错的,说明py_function()这个函数运行了,但是自定义的函数未运行,这是为什么呢,是缺少修饰器么。
def Myshow_all(self,inputs):
def showTensor(inputs):
a=inputs.numpy()
print(a)
return a
y=tf.py_function(showTensor,[inputs],tf.float32)
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)
print(a)
print(a.shape)
return output