Esempio n. 1
0
    def test_get_incremental_score(self):
        test_cases = [
            # scores to be returned in order by mock of model.score
            np.array(
                [0, 0, 0.5, 0.3, 0.8, 0.6, 0.9, 0.7, 1, 0.8, 1, 0.9, 1, 1]),
            np.array([0, 144, 222, -0.29, 1, 1])
        ]
        for scores in test_cases:
            model = RNNModel(3, 8, num_epochs=int(len(scores) / 2))
            model.score = MagicMock()
            model.score.side_effect = scores
            model.spawn_clf = MagicMock()

            # mock tensorflow network attributes
            model.sess = MagicMock()
            model.sess.run = MagicMock()
            model.opt = MagicMock()
            model.x = MagicMock()
            model.y = MagicMock()
            model.sequence_lengths = MagicMock()

            preprocess.up_sample = MagicMock()

            # none of the inputs are actually used due to mocking so just give dummy inputs
            train_scores, test_scores = model.incremental_score(
                [], [], [], [],
                train_sequence_lengths=[],
                test_sequence_lengths=[])
            self.assertListEqual(
                train_scores,
                list(scores[[i for i in range(0, len(scores), 2)]]))
            self.assertListEqual(
                test_scores,
                list(scores[[i for i in range(1, len(scores), 2)]]))
"""
This program creates the log files necessary for TensorBoard to visualise the architecture. It provides code for
changing the parameters of the model, the number of windows, number of features and number of classes. Different
versions were experimented with to ensure the model worked properly
In order to display the visualisation follow the steps below. The logfiles are stored in a folder called tmp in the
directory containing this python file.
1 - Go to the terminal
2 - Use the tensorboard command to display the visualisation on a local server. If the path to the tmp directory created
    is path/to/tmp/ then run the following command -
    tensorboard --logdir=path/to/tmp/ --port 6006
3 - Open the following link in your browser - http://localhost:6006/
"""
import sys, os

sys.path.append(os.path.join(sys.path[0], "../.."))

from analysis.rnn_model import RNNModel
import settings

settings.num_windows = settings.max_reading_length

num_classes = 3
num_features = len(settings.used_sensors) * len(
    settings.used_sensor_attributes) * settings.num_windows
clf_params = None

model = RNNModel(num_classes, num_features, clf_params=clf_params)

model.spawn_clf()
model.write_graph_for_visualisation()