| @@ 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]) |
|
| @@ 38-77 (lines=40) @@ | ||
| 35 | ||
| 36 | ||
| 37 | class TestDiceScore: |
|
| 38 | @pytest.mark.parametrize( |
|
| 39 | ("value", "smooth_nr", "smooth_dr", "expected"), |
|
| 40 | [ |
|
| 41 | (0, 1e-5, 1e-5, 1), |
|
| 42 | (0, 0, 1e-5, 0), |
|
| 43 | (0, 1e-5, 0, np.inf), |
|
| 44 | (0, 0, 0, np.nan), |
|
| 45 | (0, 1e-7, 1e-7, 1), |
|
| 46 | (1, 1e-5, 1e-5, 1), |
|
| 47 | (1, 0, 1e-5, 1), |
|
| 48 | (1, 1e-5, 0, 1), |
|
| 49 | (1, 0, 0, 1), |
|
| 50 | (1, 1e-7, 1e-7, 1), |
|
| 51 | ], |
|
| 52 | ) |
|
| 53 | def test_smooth( |
|
| 54 | self, |
|
| 55 | value: float, |
|
| 56 | smooth_nr: float, |
|
| 57 | smooth_dr: float, |
|
| 58 | expected: float, |
|
| 59 | ): |
|
| 60 | """ |
|
| 61 | Test values in extreme cases where numerator/denominator are all zero. |
|
| 62 | ||
| 63 | :param value: value for input. |
|
| 64 | :param smooth_nr: constant for numerator. |
|
| 65 | :param smooth_dr: constant for denominator. |
|
| 66 | :param expected: target value. |
|
| 67 | """ |
|
| 68 | shape = (1, 10) |
|
| 69 | y_true = tf.ones(shape=shape) * value |
|
| 70 | y_pred = tf.ones(shape=shape) * value |
|
| 71 | ||
| 72 | got = label.DiceScore(smooth_nr=smooth_nr, smooth_dr=smooth_dr)._call( |
|
| 73 | y_true, |
|
| 74 | y_pred, |
|
| 75 | ) |
|
| 76 | expected = tf.constant(expected) |
|
| 77 | assert is_equal_tf(got[0], expected) |
|
| 78 | ||
| 79 | @pytest.mark.parametrize("binary", [True, False]) |
|
| 80 | @pytest.mark.parametrize("background_weight", [0.0, 0.1, 0.5, 1.0]) |
|