How to use the networkml.algorithms.sos.SoSmodel.SoSModel function in networkml

To help you get started, we’ve selected a few networkml examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github CyberReboot / NetworkML / networkml / algorithms / sos / train_SoSModel.py View on Github external
data = create_dataset(data_dir, time_const)
    # Create the training data
    logger.info('Saving data to %s', save_path)
    with open(save_path, 'wb') as handle:
        pickle.dump(data, handle, protocol=pickle.HIGHEST_PROTOCOL)

    logger.info('Loaded training data')
    # Create an iterator
    iterator = BatchIterator(
        data,
        labels,
        perturb_types=['random data', 'port swap', 'direction_swap']
    )
    logger.info('Created iterator')
    rnnmodel = SoSModel(rnn_size=100, label_size=len(labels))
    logger.info('Created model')
    try:
        rnnmodel.load(sos_model)
        logger.info('Loaded model')
    except Exception as e:  # pragma: no cover
        rnnmodel.initialize()
        logger.info(
            'Initialized model from scratch instead, because {0}'.format(str(e)))

    X_v, L_v, Y_v = iterator.gen_batch(
        split='validation',
        batch_size=64
    )

    cost = rnnmodel.get_cost(X_v, L_v, Y_v)
github CyberReboot / NetworkML / networkml / algorithms / sos / eval_SoSModel.py View on Github external
try:
        if 'LOG_LEVEL' in os.environ and os.environ['LOG_LEVEL'] != '':
            logger.setLevel(os.environ['LOG_LEVEL'])
    except Exception as e:  # pragma: no cover
        logger.error(
            'Unable to set logging level because: {0} defaulting to INFO.'.format(str(e)))
    data = create_dataset(pcap, time_const, label=label,
                          model_path=model_path, model_type=model_type)
    # Create an iterator
    iterator = BatchIterator(
        data,
        labels,
        perturb_types=['random data']
    )
    logger.debug('Created iterator')
    rnnmodel = SoSModel(rnn_size=rnn_size, label_size=len(labels))
    logger.debug('Created model')
    rnnmodel.load('networkml/trained_models/sos/SoSmodel')
    logger.debug('Loaded model')

    X_list = iterator.X
    L_list = iterator.L
    sessions = iterator.sessions

    num_total = 0
    max_score = 0
    scores = {}
    for i, X in enumerate(X_list):
        L = L_list[i]
        out = rnnmodel.get_output(
            np.expand_dims(X, axis=0),
            np.expand_dims(L, axis=0),