add soft parameter sharing network

This commit is contained in:
2017-11-06 21:51:49 +01:00
parent 7b8dfcebbe
commit b1f48c1895
4 changed files with 82 additions and 3 deletions

View File

@@ -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):

View File

@@ -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)