转自:https://www.jb51.net/article/187172.htm
#新建一个打印层。
class PrintLayer(tf.keras.layers.Layer):
def __init__(self, **kwargs): #初始化方法,不须改变
super(PrintLayer, self).__init__(**kwargs)
def call(self, x): # 调用该层时执行的方法
x = tf.compat.v1.Print(x,[x],message="x is: ",summarize=65536)
#调用tf的Print方法打印tensor方法,第一个参数为输入的x,第二个参数为要输出的参数,summarize参数为输出的元素个数。
# 一定要返回tf.Print()函数返回的变量,不要直接使用传入的变量。
return x;