I'm trying to construct a Keras layer which mimics NumPy prebuilt tile function like ([np.tile][1]). I've tried the following code but it didn't work
import tensorflow as tf
from tensorflow import keras
from keras import Input
class Tile(Layer):
def __init__(self,repeat, **kwargs):
self.repeat = repeat
super(Tile,self).__init__(**kwargs)
def call(self, x):
return np.tile(x,self.repeat)
input= Input(shape= (3,))
repeat = (1,2)
x = Tile(repeat)(input)
model = keras.Model(input,x)
print(model(tf.ones(3,)))
error output:
---> x = Tile(repeat)(input)
NotImplementedError: Cannot convert a symbolic Tensor (Placeholder:0) to a numpy array. This error may indicate that you're trying to pass a Tensor to a NumPy call, which is not supported
I think the issue relates to the unkown dimension of the batch size but I don't know how to handle it. Can anyone help please ?