1

I'm trying to add an additional loss with add_loss to a hidden layer in my model, and have added it in the call() function for that layer. I want to convert the input to a numpy array, but when I call input.numpy(), it fails with the error:

'AttributeError: 'Tensor' object has no attribute 'numpy''.

I've checked and it doesn't raise this error with other tensors. So there must be symbolic tensors being passed into the call() function as input.

How could I check if the input a symbolic tensor or not?

Here's the layer which I was referring to calling inputs.numpy() raises the error.

class Encoder(layers.Conv2D):
    def __init__(self, filters, kernel_size, **kwargs):
        self.filters=filters
        self.kernel_size=kernel_size
        super(Encoder, self).__init__(filters, kernel_size, **kwargs)
    def call(self, inputs):
        print(inputs.numpy())
        return super(Encoder, self).call(inputs)
Kaveh
  • 4,618
  • 2
  • 20
  • 33

0 Answers0