【问题标题】:Convolution Layer output changes to 1. after passing it through a fully connected layer for every image卷积层的输出变为 1。在通过每个图像的全连接层后
【发布时间】:2015-12-31 12:52:36
【问题描述】:

我使用 theano 构建了一个 CNN。卷积层和隐藏层的代码是:

class HiddenLayer(Layer):

    def __init__(self,n_in,n_out,inp_vector=T.dmatrix(),non_linearity='sigmoid',W=None,b=None):
        Layer.__init__(self,n_in,n_out,W,b)
        self.inp=inp_vector
        out=self.non_lins[non_linearity](inp_vector.dot(self.W.transpose())+self.b)
        self.output=out

class ConvolutionLayer(Layer):
    def __init__(self,W_shape,b_shape,image_shape,inp_vector=T.tensor4(),maxpool=(2,2),non_linearity='tanh',W=None,b=None,flatten=False,batch=1):
        W=theano.shared(numpy.random.standard_normal(W_shape))
        b=theano.shared(numpy.random.random(b_shape))
        Layer.__init__(self,0,0,W,b)
        self.inp=inp_vector
        out=convop.conv2d(input=inp_vector,filters=self.W,filter_shape=W_shape,image_shape=image_shape)
        self.output=self.non_lins[non_linearity](downsample.max_pool_2d(out,maxpool,ignore_border=True)+self.b.dimshuffle('x',0,'x','x'))
        if flatten:
            self.output=self.output.flatten(batch)
        else:
            self.output=self.output

我的神经网络有 5 层。但是为了检查出了什么问题,我剥离了所有其他隐藏层,只保留了连接到卷积层的那个。我观察到卷积层的输出很好,但是经过全连接层后,变成了:

(2, 5000)
[[-1. -1. -1. ..., -1. -1. -1.]
 [-1. -1. -1. ..., -1. -1. -1.]]

这里 2,5000 是隐藏层输出矩阵的形状。网络实现是:

layer0=machinebrain.ConvolutionLayer(image_shape=(2,3,480,640),W_shape=
(2,3,5,5),maxpool=(4,4),b_shape=(2,))
layer1=machinebrain.ConvolutionLayer(image_shape=(2,2,119,159),inp_vector=
layer0.output,maxpool=(2,2),W_shape=(3,2,5,5),b_shape=(3,),flatten=True,batch=2)
layer3=machinebrain.HiddenLayer(inp_vector=layer1.output,
non_linearity='tanh',n_in=13167,n_out=5000)

知道什么可能导致卷积层的输出在通过隐藏层后变为全 1?

【问题讨论】:

    标签: python machine-learning neural-network theano conv-neural-network


    【解决方案1】:

    您的非线性是 tanh,其饱和值为 -1(对应于非常负的输入)和 +1(对应于非常大的正输入)。也许你的层的激活给你提供了非常大的数值?您可以尝试对输入进行全局对比度归一化(零中心并除以标准偏差),以更好地调整输入值。还可以尝试切换到 ReLU 激活甚至线性激活,以检查您从所引用的特定层获得的激活值类型。

    【讨论】:

    • 想通了。这不是输入。我使用了随机初始化的权重。因此,对于非常多的神经元,前一层的激活和当前层的权重之间的点积用于使 tanh 饱和。尝试了 Glorot 统一权重初始化。现在工作正常,
    • 哦,很好。我通常使用 Lasagne 或其他构建在 Theano 之上的框架,默认情况下它们通常具有良好的权重初始化。但最好记住权重初始化的重要性。
    猜你喜欢
    • 2018-07-13
    • 1970-01-01
    • 1970-01-01
    • 2021-11-17
    • 2018-12-22
    • 2017-07-30
    • 1970-01-01
    • 2017-10-06
    • 2021-10-19
    相关资源
    最近更新 更多