My master thesis project on malware detection using neural networks and multi task learning
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

models.py 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import keras
  2. from keras.engine import Input, Model
  3. from keras.layers import Embedding, Conv1D, GlobalMaxPooling1D, Dense, Dropout, Activation, TimeDistributed
  4. def get_shared_cnn(vocab_size, embedding_size, input_length, filters, kernel_size,
  5. hidden_dims, drop_out):
  6. x = y = Input(shape=(input_length,))
  7. y = Embedding(input_dim=vocab_size, output_dim=embedding_size)(y)
  8. y = Conv1D(filters, kernel_size, activation='relu')(y)
  9. y = GlobalMaxPooling1D()(y)
  10. y = Dense(hidden_dims)(y)
  11. y = Dropout(drop_out)(y)
  12. y = Activation('relu')(y)
  13. return Model(x, y)
  14. def get_full_model(vocabSize, embeddingSize, maxLen, domainFeatures, flowFeatures,
  15. filters, h1, h2, dropout, dense):
  16. pass
  17. def get_top_cnn(cnn, numFeatures, maxLen, windowSize, domainFeatures, filters, kernel_size, cnnHiddenDims, cnnDropout):
  18. ipt_domains = Input(shape=(windowSize, maxLen), name="ipt_domains")
  19. encoded = TimeDistributed(cnn)(ipt_domains)
  20. ipt_flows = Input(shape=(windowSize, numFeatures), name="ipt_flows")
  21. merged = keras.layers.concatenate([encoded, ipt_flows], -1)
  22. # add second cnn
  23. y = Conv1D(filters,
  24. kernel_size,
  25. activation='relu',
  26. input_shape=(windowSize, domainFeatures + numFeatures))(merged)
  27. # TODO: why global pooling? -> 3D to 2D
  28. # we use max pooling:
  29. y = GlobalMaxPooling1D()(y)
  30. y = Dropout(cnnDropout)(y)
  31. y = Dense(cnnHiddenDims, activation='relu')(y)
  32. y1 = Dense(2, activation='softmax', name="client")(y)
  33. y2 = Dense(2, activation='softmax', name="server")(y)
  34. return Model(inputs=[ipt_domains, ipt_flows], outputs=(y1, y2))