test_convolutional.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:deep-coref 作者: clarkkev 项目源码 文件源码
def test_convolution_1d(self):
        nb_samples = 9
        nb_steps = 7
        input_dim = 10
        filter_length = 6
        nb_filter = 5

        weights_in = [np.ones((nb_filter, input_dim, filter_length, 1)), np.ones(nb_filter)]

        input = np.ones((nb_samples, nb_steps, input_dim))
        for weight in [None, weights_in]:
            for border_mode in ['valid', 'full', 'same']:
                for subsample_length in [1, 3]:
                    if border_mode == 'same' and subsample_length != 1:
                        continue
                    for W_regularizer in [None, 'l2']:
                        for b_regularizer in [None, 'l2']:
                            for act_regularizer in [None, 'l2']:
                                layer = convolutional.Convolution1D(
                                    nb_filter, filter_length, weights=weight,
                                    border_mode=border_mode, W_regularizer=W_regularizer,
                                    b_regularizer=b_regularizer, activity_regularizer=act_regularizer,
                                    subsample_length=subsample_length, input_shape=(None, input_dim))

                            layer.input = theano.shared(value=input)
                            for train in [True, False]:
                                out = layer.get_output(train).eval()
                                assert input.shape[0] == out.shape[0]
                                if border_mode == 'same' and subsample_length == 1:
                                    assert input.shape[1] == out.shape[1]

                            config = layer.get_config()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号