当前位置: 首页>>代码示例>>Python>>正文


Python core.Masking方法代码示例

本文整理汇总了Python中keras.layers.core.Masking方法的典型用法代码示例。如果您正苦于以下问题:Python core.Masking方法的具体用法?Python core.Masking怎么用?Python core.Masking使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在keras.layers.core的用法示例。


在下文中一共展示了core.Masking方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: textual_embedding

# 需要导入模块: from keras.layers import core [as 别名]
# 或者: from keras.layers.core import Masking [as 别名]
def textual_embedding(self, language_model, mask_zero):
        """
        Note:
        * mask_zero only makes sense if embedding is learnt
        """
        if self._config.textual_embedding_dim > 0:
            print('Textual Embedding is on')
            language_model.add(Embedding(
                self._config.input_dim, 
                self._config.textual_embedding_dim, 
                mask_zero=mask_zero))
        else:
            print('Textual Embedding is off')
            language_model.add(Reshape(
                input_shape=(self._config.max_input_time_steps, self._config.input_dim),
                dims=(self._config.max_input_time_steps, self._config.input_dim)))
            if mask_zero:
                language_model.add(Masking(0))
        return language_model 
开发者ID:mateuszmalinowski,项目名称:visual_turing_test-tutorial,代码行数:21,代码来源:model_zoo.py

示例2: textual_embedding_fixed_length

# 需要导入模块: from keras.layers import core [as 别名]
# 或者: from keras.layers.core import Masking [as 别名]
def textual_embedding_fixed_length(self, language_model, mask_zero):
        """
        In contrast to textual_embedding, it produces a fixed length output.
        """
        if self._config.textual_embedding_dim > 0:
            print('Textual Embedding with fixed length is on')
            language_model.add(Embedding(
                self._config.input_dim, 
                self._config.textual_embedding_dim,
                input_length=self._config.max_input_time_steps,
                mask_zero=mask_zero))
        else:
            print('Textual Embedding with fixed length is off')
            language_model.add(Reshape(
                input_shape=(self._config.max_input_time_steps, self._config.input_dim),
                dims=(self._config.max_input_time_steps, self._config.input_dim)))
            if mask_zero:
                language_model.add(Masking(0))
        return language_model 
开发者ID:mateuszmalinowski,项目名称:visual_turing_test-tutorial,代码行数:21,代码来源:model_zoo.py

示例3: test_masking_layer

# 需要导入模块: from keras.layers import core [as 别名]
# 或者: from keras.layers.core import Masking [as 别名]
def test_masking_layer():
    ''' This test based on a previously failing issue here:
    https://github.com/keras-team/keras/issues/1567
    '''
    inputs = np.random.random((6, 3, 4))
    targets = np.abs(np.random.random((6, 3, 5)))
    targets /= targets.sum(axis=-1, keepdims=True)

    model = Sequential()
    model.add(Masking(input_shape=(3, 4)))
    model.add(recurrent.SimpleRNN(units=5, return_sequences=True, unroll=False))
    model.compile(loss='categorical_crossentropy', optimizer='adam')
    model.fit(inputs, targets, epochs=1, batch_size=100, verbose=1)

    model = Sequential()
    model.add(Masking(input_shape=(3, 4)))
    model.add(recurrent.SimpleRNN(units=5, return_sequences=True, unroll=True))
    model.compile(loss='categorical_crossentropy', optimizer='adam')
    model.fit(inputs, targets, epochs=1, batch_size=100, verbose=1) 
开发者ID:hello-sea,项目名称:DeepLearning_Wavelet-LSTM,代码行数:21,代码来源:recurrent_test.py

示例4: test_specify_state_with_masking

# 需要导入模块: from keras.layers import core [as 别名]
# 或者: from keras.layers.core import Masking [as 别名]
def test_specify_state_with_masking(layer_class):
    ''' This test based on a previously failing issue here:
    https://github.com/keras-team/keras/issues/1567
    '''
    num_states = 2 if layer_class is recurrent.LSTM else 1

    inputs = Input((timesteps, embedding_dim))
    _ = Masking()(inputs)
    initial_state = [Input((units,)) for _ in range(num_states)]
    output = layer_class(units)(inputs, initial_state=initial_state)

    model = Model([inputs] + initial_state, output)
    model.compile(loss='categorical_crossentropy', optimizer='adam')

    inputs = np.random.random((num_samples, timesteps, embedding_dim))
    initial_state = [np.random.random((num_samples, units))
                     for _ in range(num_states)]
    targets = np.random.random((num_samples, units))
    model.fit([inputs] + initial_state, targets) 
开发者ID:hello-sea,项目名称:DeepLearning_Wavelet-LSTM,代码行数:21,代码来源:recurrent_test.py

示例5: test_sequences

# 需要导入模块: from keras.layers import core [as 别名]
# 或者: from keras.layers.core import Masking [as 别名]
def test_sequences(self):
        """Test masking sequences with zeroes as padding"""
        # integer inputs, one per timestep, like embeddings
        layer = core.Masking()
        func = theano.function([layer.input], layer.get_output_mask())
        self.assertTrue(np.all(
            # get mask for this input
            func(np.array(
            [[[1], [2], [3], [0]],
             [[0], [4], [5], [0]]], dtype=np.int32)) ==
            # This is the expected output mask, one dimension less
            np.array([[1, 1, 1, 0], [0, 1, 1, 0]]))) 
开发者ID:lllcho,项目名称:CAPTCHA-breaking,代码行数:14,代码来源:test_core.py

示例6: test_non_zero

# 需要导入模块: from keras.layers import core [as 别名]
# 或者: from keras.layers.core import Masking [as 别名]
def test_non_zero(self):
        """Test masking with non-zero mask value"""
        layer = core.Masking(5)
        func = theano.function([layer.input], layer.get_output_mask())
        self.assertTrue(np.all(
            # get mask for this input, if not all the values are 5, shouldn't masked
            func(np.array(
            [[[1, 1], [2, 1], [3, 1], [5, 5]],
             [[1, 5], [5, 0], [0, 0], [0, 0]]], dtype=np.int32)) ==
            # This is the expected output mask, one dimension less
            np.array([[1, 1, 1, 0], [1, 1, 1, 1]]))) 
开发者ID:lllcho,项目名称:CAPTCHA-breaking,代码行数:13,代码来源:test_core.py


注:本文中的keras.layers.core.Masking方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。