Python 神经网络失配中的输入输出形状
我从上面的代码中得到了更为奇怪的行为。 当我每次训练一个示例时,计算的输出形状显示batchsize为2。最重要的是,在我的自定义层调用方法中,我有一个权重矩阵[4000,10],所以你可以预期下一层应该有10个神经元。然而,尽管我添加了多个custo层,每个层都有一个矩阵[4000,10],因此每个层都希望输入[14000]而不是[1,10],但Network仍能成功地执行fp 除此之外,我的compute\u output\u shape方法似乎不会影响它,只要它的形式是(x,x),其中两者都是相同的数字。请你帮忙Python 神经网络失配中的输入输出形状,python,Python,我从上面的代码中得到了更为奇怪的行为。 当我每次训练一个示例时,计算的输出形状显示batchsize为2。最重要的是,在我的自定义层调用方法中,我有一个权重矩阵[4000,10],所以你可以预期下一层应该有10个神经元。然而,尽管我添加了多个custo层,每个层都有一个矩阵[4000,10],因此每个层都希望输入[14000]而不是[1,10],但Network仍能成功地执行fp 除此之外,我的compute\u output\u shape方法似乎不会影响它,只要它的形式是(x,x),其中两者
def call(self, y):
self.y=y
self.z=self.y
self.z= tf.cast(self.z, tf.int32)
self.z=tf.reshape(self.z,[1,4000])
self.h= tf.constant([1,10], tf.int32)
self.z=tf.tile(self.z,self.h)
self.ks2 = tf.Variable(tf.reshape((tf.gather((tf.reshape(self.ks, [-1])),(self.z))), (4000,
10)),trainable=True)
self._trainable_weights = [self.ks2]
self.y= tf.cast(self.y, tf.float64)
self.y=tf.reshape(self.y,[1,4000])
return K.dot(self.y,self.ks2)
def compute_output_shape(self, input_shape):
return (200,200)