get a summary of the results when evaluating
@@ -9,6 +9,7 @@ from poseidonml.common import Common
from poseidonml.eval_SoSModel import eval_pcap
from poseidonml.Model import Model
from poseidonml.pcap_utils import clean_session_dict
+import poseidonml.training_utils as utils
class OneLayerEval:
@@ -76,6 +77,13 @@ class OneLayerEval:
model.load(load_path)
self.logger.debug('Loaded model from %s', load_path)
+ # Get the true label assignments
+ self.logger.info('Getting label assignments')
+ label_assignments = utils.get_labels('opts/label_assignments.json', model_labels=model.labels)
+ if not label_assignments:
+ self.logger.warn('Could not read label assignments; continuing anyway.')
+
+ pcap_results = {'succeeded':0, 'failed':0, 'abnormal':0}
for pcap in pcaps:
self.logger.info('Processing {0}...'.format(pcap))
source_mac = None
@@ -189,14 +197,25 @@ class OneLayerEval:
self.logger.error(
'Failed to update keys in Redis because: {0}'.format(str(e)))
+ name, label = utils.get_true_label(pcap, label_assignments)
+
# Get json message
message = json.dumps(decision)
self.logger.info('Message: ' + message)
+ if key is None:
+ key = source_mac
+ if label == decision[key]['classification']['labels'][0]:
+ pcap_results['succeeded'] += 1
+ else:
+ pcap_results['failed'] += 1
+ if decision[key]['decisions']['behavior'] == 'abnormal':
+ pcap_results['abnormal'] += 1
if self.use_rabbit:
self.common.channel.basic_publish(exchange=self.common.exchange,
routing_key=self.common.routing_key,
body=message)
+ self.logger.info('Total results: {0}'.format(pcap_results))
if self.use_rabbit:
try:
self.common.connection.close()
