add soft parameter sharing network
This commit is contained in:
@@ -46,7 +46,10 @@ def get_models_by_params(params: dict):
|
||||
long = networks.get_new_model2(0.25, flow_features, hidden_embedding, window_size, domain_length,
|
||||
filter_main, kernel_main, dense_dim, embedding_model, model_output)
|
||||
|
||||
return embedding_model, final, inter, long
|
||||
soft = networks.get_new_soft(0.25, flow_features, hidden_embedding, window_size, domain_length,
|
||||
filter_main, kernel_main, dense_dim, embedding_model, model_output)
|
||||
|
||||
return embedding_model, final, inter, long, soft
|
||||
|
||||
|
||||
def get_server_model_by_params(params: dict):
|
||||
|
@@ -135,3 +135,49 @@ def get_new_model2(dropout, flow_features, domain_features, window_size, domain_
|
||||
out_client = Dense(1, activation='sigmoid', name="client")(y)
|
||||
|
||||
return Model(ipt_domains, ipt_flows, out_client, out_server)
|
||||
|
||||
|
||||
import keras.backend as K
|
||||
|
||||
|
||||
def get_new_soft(dropout, flow_features, domain_features, window_size, domain_length, cnn_dims, kernel_size,
|
||||
dense_dim, cnn, model_output="both") -> Model:
|
||||
def dist_reg(distant_layer):
|
||||
def dist_reg_h(weights):
|
||||
print("REG FUNCTION")
|
||||
print(weights)
|
||||
print(distant_layer)
|
||||
return 0.01 * K.sum(K.abs(weights - distant_layer))
|
||||
|
||||
return dist_reg_h
|
||||
|
||||
ipt_domains = Input(shape=(window_size, domain_length), name="ipt_domains")
|
||||
ipt_flows = Input(shape=(window_size, flow_features), name="ipt_flows")
|
||||
encoded = TimeDistributed(cnn, name="domain_cnn")(ipt_domains)
|
||||
merged = keras.layers.concatenate([encoded, ipt_flows], -1)
|
||||
y = conv_server = Conv1D(cnn_dims,
|
||||
kernel_size,
|
||||
activation='relu', name="conv_server")(merged)
|
||||
# remove temporal dimension by global max pooling
|
||||
y = GlobalMaxPooling1D()(y)
|
||||
y = Dropout(dropout)(y)
|
||||
y = dense_server = Dense(dense_dim,
|
||||
activation="relu",
|
||||
name="dense_server")(y)
|
||||
out_server = Dense(1, activation="sigmoid", name="server")(y)
|
||||
# CNN processing a small slides of flow windows
|
||||
y = Conv1D(cnn_dims,
|
||||
kernel_size,
|
||||
activation='relu', name="conv_client")(merged)
|
||||
# remove temporal dimension by global max pooling
|
||||
y = GlobalMaxPooling1D()(y)
|
||||
y = Dropout(dropout)(y)
|
||||
y = Dense(dense_dim,
|
||||
activation='relu',
|
||||
name="dense_client")(y)
|
||||
|
||||
out_client = Dense(1, activation='sigmoid', name="client")(y)
|
||||
# model = KerasModel(inputs=(ipt_domains, ipt_flows), outputs=(out_client, out_server))
|
||||
|
||||
|
||||
return Model(ipt_domains, ipt_flows, out_client, out_server)
|
||||
|
Reference in New Issue
Block a user