133 lines
4.5 KiB
Python
133 lines
4.5 KiB
Python
import argparse
|
|
|
|
from keras.utils import np_utils
|
|
|
|
import dataset
|
|
import models
|
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
# parser.add_argument("--modes", action="store", dest="modes", nargs="+")
|
|
|
|
parser.add_argument("--train", action="store", dest="train_data",
|
|
default="data/full_dataset.csv.tar.bz2")
|
|
|
|
parser.add_argument("--test", action="store", dest="test_data",
|
|
default="data/full_future_dataset.csv.tar.bz2")
|
|
|
|
# parser.add_argument("--h5data", action="store", dest="h5data",
|
|
# default="")
|
|
#
|
|
parser.add_argument("--model", action="store", dest="model",
|
|
default="model_x")
|
|
|
|
# parser.add_argument("--pred", action="store", dest="pred",
|
|
# default="")
|
|
#
|
|
# parser.add_argument("--type", action="store", dest="model_type",
|
|
# default="simple_conv")
|
|
#
|
|
parser.add_argument("--batch", action="store", dest="batch_size",
|
|
default=64, type=int)
|
|
|
|
parser.add_argument("--epochs", action="store", dest="epochs",
|
|
default=10, type=int)
|
|
|
|
# parser.add_argument("--samples", action="store", dest="samples",
|
|
# default=100000, type=int)
|
|
#
|
|
# parser.add_argument("--samples_val", action="store", dest="samples_val",
|
|
# default=10000, type=int)
|
|
#
|
|
parser.add_argument("--embd", action="store", dest="embedding",
|
|
default=128, type=int)
|
|
|
|
parser.add_argument("--hidden_char_dims", action="store", dest="hidden_char_dims",
|
|
default=256, type=int)
|
|
|
|
parser.add_argument("--window", action="store", dest="window",
|
|
default=10, type=int)
|
|
|
|
parser.add_argument("--domain_length", action="store", dest="domain_length",
|
|
default=40, type=int)
|
|
|
|
parser.add_argument("--domain_embd", action="store", dest="domain_embedding",
|
|
default=512, type=int)
|
|
|
|
# parser.add_argument("--queue", action="store", dest="queue_size",
|
|
# default=50, type=int)
|
|
#
|
|
# parser.add_argument("--p", action="store", dest="p_train",
|
|
# default=0.5, type=float)
|
|
#
|
|
# parser.add_argument("--p_val", action="store", dest="p_val",
|
|
# default=0.01, type=float)
|
|
#
|
|
# parser.add_argument("--gpu", action="store", dest="gpu",
|
|
# default=0, type=int)
|
|
#
|
|
# parser.add_argument("--tmp", action="store_true", dest="tmp")
|
|
#
|
|
# parser.add_argument("--test", action="store_true", dest="test")
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
# config = tf.ConfigProto(log_device_placement=True)
|
|
# config.gpu_options.per_process_gpu_memory_fraction = 0.5
|
|
# config.gpu_options.allow_growth = True
|
|
# session = tf.Session(config=config)
|
|
|
|
|
|
def main():
|
|
# parameter
|
|
cnnDropout = 0.5
|
|
cnnHiddenDims = 1024
|
|
numCiscoFeatures = 30
|
|
kernel_size = 3
|
|
drop_out = 0.5
|
|
filters = 128
|
|
|
|
char_dict = dataset.get_character_dict()
|
|
user_flow_df = dataset.get_user_flow_data(args.train_data)
|
|
|
|
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)
|
|
|
|
shared_cnn = models.renes_networks.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()
|
|
|
|
model = models.renes_networks.get_model(cnnDropout, flow_tr.shape[-1], args.domain_embedding,
|
|
args.window, args.domain_length, filters, kernel_size,
|
|
cnnHiddenDims, shared_cnn)
|
|
model.summary()
|
|
|
|
model.compile(optimizer='adam',
|
|
loss='binary_crossentropy',
|
|
metrics=['accuracy'])
|
|
|
|
client_tr = np_utils.to_categorical(client_tr, 2)
|
|
server_tr = np_utils.to_categorical(server_tr, 2)
|
|
model.fit([domain_tr, flow_tr],
|
|
[client_tr, server_tr],
|
|
batch_size=args.batch_size,
|
|
epochs=args.epochs,
|
|
shuffle=True,
|
|
validation_split=0.2)
|
|
|
|
|
|
def test():
|
|
char_dict = dataset.get_character_dict()
|
|
user_flow_df = dataset.get_user_flow_data(args.test_data)
|
|
domain_val, flow_val, client_val, server_val = dataset.create_dataset_from_flows(
|
|
user_flow_df, char_dict,
|
|
max_len=args.domain_length, window_size=args.window)
|
|
# TODO: get model and exec model.evaluate(...)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|