I use tensorflow 2.1 with customize layer as follow:
class Mylayer(KL.layer):
def __init__(self, name):
super(Mylayer, self).__init__(name)
self.conv = KL.Conv2D(32)
def call(self, inputs):
outputs = self.conv(inputs)
np.save('outputs.npy', outputs)
return outputs
However, whether I decorate tf.function at train_step or not, np.save says cannot convert a symbolic tensor to numpy array. If I change to np.save('outputs.txt', outputs.numpy()) without using tf.function, it shows that tensor object has no attribute numpy. Also, call() function seems to be called twice with symbolic tensor in first time and eager tensor in second time when not using tf.function.
How do I save the tensor value inside call()?