I am trying to do a custom convolution operation by creating a custom layer in Keras.
However, I am getting a FailedPreconditionError()
This is the code I wrote for the call
function is...
def call(self, x):
kern_x,kern_y = self.kernel.get_shape().as_list()
img_x,img_y = x.get_shape().as_list()[2:4]
activation_map = np.random.random((img_x - kern_x + 1, img_y - kern_y + 1))
img = tf.Session().run(tf.Variable(x,validate_shape=False)) #this is where I am getting the error
kern = tf.Session().run(tf.constant(self.kernel))
for i in range(activation_map.shape[0]):
for j in range(activation_map.shape[1]):
activation_map[i][j] = fn1(fn2(img[i:i+kern_x,j:j+kern_y],kern))
return tf.convert_to_tensor(fuzzy_activation_map, np.float32)
x is a <tf.Tensor 'max_pooling2d_1/transpose_1:0' shape=(?, 32, 12, 12) dtype=float32>
The loops are the main part where I am trying to implement a custom filter that I found in a paper. I have separately designed the filter and it works when the input image and the kernel are numpy 2D arrays. I just need the kernel to be trainable.