Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Masking layer does not work after training #14108

Closed
Jbiloki opened this issue Jun 9, 2020 · 3 comments
Closed

Masking layer does not work after training #14108

Jbiloki opened this issue Jun 9, 2020 · 3 comments
Assignees
Labels
stale stat:awaiting response from contributor type:support User is asking for help / asking an implementation question. Stackoverflow would be better suited.

Comments

@Jbiloki
Copy link

Jbiloki commented Jun 9, 2020

Before training the model my masking layer correctly 0s out the unwanted inputs. After model compile and training it outputs non-zero values:

import numpy as np
from tensorflow.keras.layers import Masking,Input,TimeDistributed,Dense
a = np.array([[[3,1,2],[-1,-1,-1],[2,1,1],[-1,-1,-1],[-1,-1,-1]], [[3,1,2],[-1,-1,-1],[2,1,1],[-1,-1,-1],[-1,-1,-1]]]).astype(np.float32)

rel_inputs = Input(shape=(a.shape[-2], a.shape[-1],))
masked = Masking(mask_value=-1.0)(rel_inputs)
x = TimeDistributed(Dense(16, activation='relu',
                          kernel_regularizer=regularizers.l1_l2(l1=1e-5, l2=1e-4),
                          bias_regularizer=regularizers.l2(1e-4),
                          activity_regularizer=regularizers.l2(1e-5)))
x2 = TimeDistributed(Dense(32, activation='relu',
                          kernel_regularizer=regularizers.l1_l2(l1=1e-5, l2=1e-4),
                          bias_regularizer=regularizers.l2(1e-4),
                          activity_regularizer=regularizers.l2(1e-5)))
rel_map = x(masked)
rel_map = Dropout(0.3)(rel_map)
rel_map = x2(rel_map)
rel_map = Dropout(0.3)(rel_map)
s = TimeDistributed(Dense(1))
output = s(rel_map)
output = Reshape((5,))(output)
#output = Lambda(lambda x: K.squeeze(x, -1))(output)
#irr_score = s(irr_map)
#diff = Subtract()([rel_score, irr_score])
model = Model(inputs=rel_inputs, outputs=output, name='rank_net_basic')
q = model.predict(a)
print (q)

image

@saikumarchalla saikumarchalla added the type:support User is asking for help / asking an implementation question. Stackoverflow would be better suited. label Jun 9, 2020
@sushreebarsa sushreebarsa self-assigned this Sep 21, 2021
@sushreebarsa
Copy link
Contributor

sushreebarsa commented Oct 7, 2021

@Jbiloki
In order to expedite the trouble-shooting process, please provide a code snippet to reproduce the issue reported here. Please have a look at the issue for reference.Thanks!

@google-ml-butler
Copy link

This issue has been automatically marked as stale because it has no recent activity. It will be closed if no further activity occurs. Thank you.

@google-ml-butler
Copy link

Closing as stale. Please reopen if you'd like to work on this further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale stat:awaiting response from contributor type:support User is asking for help / asking an implementation question. Stackoverflow would be better suited.
Projects
None yet
Development

No branches or pull requests

4 participants