示例#1
0
 def test_should_return_abs_diff_for_single_value(self):
     with tf.Graph().as_default():
         labels = tf.constant([0.9])
         outputs = tf.constant([0.1])
         loss = l1_loss(labels, outputs)
         with tf.Session() as session:
             assert_close(session.run([loss])[0], 0.8)
示例#2
0
 def test_should_return_zero_if_logits_are_matching_labels_with_neg_pos_value(
         self):
     with tf.Graph().as_default():
         labels = tf.constant([[[0.0, 1.0]]])
         logits = tf.constant([[[-10.0, 10.0]]])
         loss = cross_entropy_loss(labels, logits)
         with tf.Session() as session:
             assert_close(session.run([loss])[0], 0.0)
def test_evaluate_predictions():
    n_classes = 4
    predictions = tf.constant(np.array([0, 1, 1, 2, 3, 3]))
    labels = tf.constant(np.array([0, 1, 2, 3, 3, 3]))

    evaluation_tensors = evaluate_predictions(labels=labels,
                                              predictions=predictions,
                                              n_classes=n_classes)
    with tf.Session() as session:
        assert np.array_equal(
            session.run(evaluation_tensors.confusion_matrix),
            np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 1, 0, 0], [0, 0, 1, 2]]))
        assert np.array_equal(session.run(evaluation_tensors.tp),
                              np.array([1, 1, 0, 2]))
        assert np.array_equal(session.run(evaluation_tensors.fp),
                              np.array([0, 1, 1, 0]))
        assert np.array_equal(session.run(evaluation_tensors.fn),
                              np.array([0, 0, 1, 1]))
        expected_micro_precision = 4.0 / (4 + 2)
        expected_micro_recall = 4.0 / (4 + 2)
        expected_micro_f1 = (
            2 * expected_micro_precision * expected_micro_recall /
            (expected_micro_precision + expected_micro_recall))
        assert_close(session.run(evaluation_tensors.micro_precision),
                     expected_micro_precision)
        assert_close(session.run(evaluation_tensors.micro_recall),
                     expected_micro_recall)
        assert_close(session.run(evaluation_tensors.micro_f1),
                     expected_micro_f1)
示例#4
0
 def test_should_return_zero_value_for_not_occuring_class(self):
     frequencies = [[1, 1], [1, 1], [0, 0]]
     result = calculate_median_weights_for_frequencies(frequencies)
     get_logger().debug('result: %s', result)
     assert_close(sum(result), 1.0)
     assert_all_close(result, [0.5, 0.5, 0.0], atol=0.001)