将张量转换为numpy数组时发生FailedPreconditionError()

时间:2018-08-24 17:48:27

标签: python numpy tensorflow keras keras-layer

我试图通过在Keras中创建自定义图层来执行自定义卷积操作。

但是,我得到一个FailedPreconditionError()

这是我为call函数编写的代码是...

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是<tf.Tensor 'max_pooling2d_1/transpose_1:0' shape=(?, 32, 12, 12) dtype=float32>

循环是我试图实现在论文中发现的自定义过滤器的主要部分。我已经单独设计了过滤器,当输入图像和内核是numpy 2D数组时,它可以工作。我只需要内核是可训练的。

0 个答案:

没有答案
相关问题