From a3324b5e04d5a8bff9f37a64653aadbfee3c4ff0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Knaebel?= Date: Sat, 8 Jul 2017 11:53:03 +0200 Subject: [PATCH] add pauls config test (TMP) --- main.py | 49 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 42 insertions(+), 7 deletions(-) diff --git a/main.py b/main.py index 5e751f0..9cbc986 100644 --- a/main.py +++ b/main.py @@ -19,8 +19,8 @@ parser.add_argument("--test", action="store", dest="test_data", # parser.add_argument("--h5data", action="store", dest="h5data", # default="") # -parser.add_argument("--model", action="store", dest="model", - default="model_x") +parser.add_argument("--models", action="store", dest="models", + default="models/model_x") # parser.add_argument("--pred", action="store", dest="pred", # default="") @@ -80,6 +80,38 @@ args = parser.parse_args() # session = tf.Session(config=config) +def main_paul_best(): + char_dict = dataset.get_character_dict() + user_flow_df = dataset.get_user_flow_data(args.train_data) + + param = models.pauls_networks.best_config + print(param) + + print("create training dataset") + domain_tr, flow_tr, client_tr, server_tr = dataset.create_dataset_from_flows( + user_flow_df, char_dict, + max_len=args.domain_length, + window_size=args.window) + client_tr = np_utils.to_categorical(client_tr, 2) + server_tr = np_utils.to_categorical(server_tr, 2) + + embedding, model = models.get_models_by_params(param) + + model.compile(optimizer='adam', + loss='categorical_crossentropy', + metrics=['accuracy']) + + model.fit([domain_tr, flow_tr], + [client_tr, server_tr], + batch_size=args.batch_size, + epochs=args.epochs, + shuffle=True, + validation_split=0.2) + + embedding.save(args.models + "_embd.h5") + model.save(args.models + "_clf.h5") + + def main_hyperband(): char_dict = dataset.get_character_dict() user_flow_df = dataset.get_user_flow_data(args.train_data) @@ -137,13 +169,13 @@ def main_train(): client_tr = np_utils.to_categorical(client_tr, 2) server_tr = np_utils.to_categorical(server_tr, 2) - shared_cnn = network.get_embedding(len(char_dict) + 1, args.embedding, args.domain_length, - args.hidden_char_dims, kernel_size, args.domain_embedding, 0.5) - shared_cnn.summary() + embedding = network.get_embedding(len(char_dict) + 1, args.embedding, args.domain_length, + args.hidden_char_dims, kernel_size, args.domain_embedding, 0.5) + embedding.summary() model = network.get_model(cnnDropout, flow_tr.shape[-1], args.domain_embedding, args.window, args.domain_length, filters, kernel_size, - cnnHiddenDims, shared_cnn) + cnnHiddenDims, embedding) model.summary() model.compile(optimizer='adam', @@ -157,7 +189,8 @@ def main_train(): shuffle=True, validation_split=0.2) - model.save(args.model) + embedding.save(args.models + "_embd.h5") + model.save(args.models + "_clf.h5") def main_test(): @@ -206,6 +239,8 @@ def main(): main_visualization() if "score" in args.modes: main_score() + if "paul" in args.modes: + main_paul_best() if __name__ == "__main__":