@@ 241-280 (lines=40) @@ | ||
238 | ||
239 | ||
240 | class TestJaccardIndex: |
|
241 | @pytest.mark.parametrize( |
|
242 | ("value", "smooth_nr", "smooth_dr", "expected"), |
|
243 | [ |
|
244 | (0, 1e-5, 1e-5, 1), |
|
245 | (0, 0, 1e-5, 0), |
|
246 | (0, 1e-5, 0, np.inf), |
|
247 | (0, 0, 0, np.nan), |
|
248 | (0, 1e-7, 1e-7, 1), |
|
249 | (1, 1e-5, 1e-5, 1), |
|
250 | (1, 0, 1e-5, 1), |
|
251 | (1, 1e-5, 0, 1), |
|
252 | (1, 0, 0, 1), |
|
253 | (1, 1e-7, 1e-7, 1), |
|
254 | ], |
|
255 | ) |
|
256 | def test_smooth( |
|
257 | self, |
|
258 | value: float, |
|
259 | smooth_nr: float, |
|
260 | smooth_dr: float, |
|
261 | expected: float, |
|
262 | ): |
|
263 | """ |
|
264 | Test values in extreme cases where numerator/denominator are all zero. |
|
265 | ||
266 | :param value: value for input. |
|
267 | :param smooth_nr: constant for numerator. |
|
268 | :param smooth_dr: constant for denominator. |
|
269 | :param expected: target value. |
|
270 | """ |
|
271 | shape = (1, 10) |
|
272 | y_true = tf.ones(shape=shape) * value |
|
273 | y_pred = tf.ones(shape=shape) * value |
|
274 | ||
275 | got = label.JaccardIndex(smooth_nr=smooth_nr, smooth_dr=smooth_dr).call( |
|
276 | y_true, |
|
277 | y_pred, |
|
278 | ) |
|
279 | expected = tf.constant(expected) |
|
280 | assert is_equal_tf(got[0], expected) |
|
281 | ||
282 | @pytest.mark.parametrize("binary", [True, False]) |
|
283 | @pytest.mark.parametrize("background_weight", [0.0, 0.1, 0.5, 1.0]) |
|
@@ 43-82 (lines=40) @@ | ||
40 | ||
41 | ||
42 | class TestDiceScore: |
|
43 | @pytest.mark.parametrize( |
|
44 | ("value", "smooth_nr", "smooth_dr", "expected"), |
|
45 | [ |
|
46 | (0, 1e-5, 1e-5, 1), |
|
47 | (0, 0, 1e-5, 0), |
|
48 | (0, 1e-5, 0, np.inf), |
|
49 | (0, 0, 0, np.nan), |
|
50 | (0, 1e-7, 1e-7, 1), |
|
51 | (1, 1e-5, 1e-5, 1), |
|
52 | (1, 0, 1e-5, 1), |
|
53 | (1, 1e-5, 0, 1), |
|
54 | (1, 0, 0, 1), |
|
55 | (1, 1e-7, 1e-7, 1), |
|
56 | ], |
|
57 | ) |
|
58 | def test_smooth( |
|
59 | self, |
|
60 | value: float, |
|
61 | smooth_nr: float, |
|
62 | smooth_dr: float, |
|
63 | expected: float, |
|
64 | ): |
|
65 | """ |
|
66 | Test values in extreme cases where numerator/denominator are all zero. |
|
67 | ||
68 | :param value: value for input. |
|
69 | :param smooth_nr: constant for numerator. |
|
70 | :param smooth_dr: constant for denominator. |
|
71 | :param expected: target value. |
|
72 | """ |
|
73 | shape = (1, 10) |
|
74 | y_true = tf.ones(shape=shape) * value |
|
75 | y_pred = tf.ones(shape=shape) * value |
|
76 | ||
77 | got = label.DiceScore(smooth_nr=smooth_nr, smooth_dr=smooth_dr).call( |
|
78 | y_true, |
|
79 | y_pred, |
|
80 | ) |
|
81 | expected = tf.constant(expected) |
|
82 | assert is_equal_tf(got[0], expected) |
|
83 | ||
84 | @pytest.mark.parametrize("binary", [True, False]) |
|
85 | @pytest.mark.parametrize("background_weight", [0.0, 0.1, 0.5, 1.0]) |