Esempio n. 1
0
def test_JaccardMetric():

    # set up synthentic data for testing
    targets = np.array([
        [True, True, False], [True, False, True], [False, True, False],
        [True, True, True], [False, False, True]
    ])
    preds = np.array([
        [1, 0, 0], [0, 1, 1], [0, 1, 0],
        [1, 1, 1], [0, 0, 1]
    ])

    # create instance of jaccard metric object
    jm = JaccardMetric()

    # first test all the data at once
    jm.update_state(targets, preds)
    jaccard_big_batch = jm.result().numpy()

    # reset object and test multiple matches
    jm.reset_states()

    # Do two mini-batches
    jm.update_state(targets[:3], preds[:3])
    jm.update_state(targets[3:], preds[3:])
    jaccard_multiple_batches = jm.result().numpy()

    # check to make sure answers same for both big batch and multiple batches
    assert np.isclose(jaccard_big_batch, jaccard_multiple_batches)
Esempio n. 2
0
 def _setup_metrics(self):
     self.metric_functions = {}  # needed to shadow class variable
     self.metric_functions[LOSS] = self.eval_loss_function
     self.metric_functions[JACCARD] = JaccardMetric()