본문 바로가기
IT/Python

keras Masking Test

by Jang HyunWoong 2019. 3. 13.

Definition:

Masks a sequence by using a mask value to skip timesteps.

For each timestep in the input tensor (dimension #1 in the tensor), if all values in the input tensor at that timestep are equal to mask_value, then the timestep will be masked (skipped) in all downstream layers (as long as they support masking).

But, I want to know the real output from Masking that expected.

Below to see how the Masking works.

# When the masking value is -1, usually 0 with tf.Session() as sess: test_input1 = Input(shape=(1, )) test_masked = Masking(mask_value=-1)(test_input1) test_out = Lambda(lambda x: x)(test_masked) test_model = Model(inputs=test_input1, outputs=test_out) print(test_model.predict(([1, 2, -1, -1, 4, 5]))) Output: [[ 1.] [ 2.] [-0.] [-0.] [ 4.] [ 5.]] # When the masking value is 0 with tf.Session() as sess: test_input1 = Input(shape=(1, )) test_masked = Masking(mask_value=0.)(test_input1) test_out = Lambda(lambda x: x)(test_masked) test_model = Model(inputs=test_input1, outputs=test_out) print(test_model.predict(([1, 2, -1, -1, 4, 5]))) Output: [[ 1.] [ 2.] [ 0.] [ 0.] [ 4.] [ 5.]]

It makes all values are equal to mask_value to 0


반응형