|
15 | 15 |
|
16 | 16 | import numpy as np |
17 | 17 | import tensorflow as tf |
| 18 | +from tensorflow import keras |
18 | 19 |
|
19 | 20 | from keras_cv.metrics.coco.recall import COCORecall |
20 | 21 |
|
21 | 22 |
|
22 | 23 | class COCORecallTest(tf.test.TestCase): |
23 | | - def test_recall_area_range_filtering(self): |
| 24 | + |
| 25 | + def test_runs_inside_model(self): |
| 26 | + i = keras.layers.Input((None, None, 6)) |
| 27 | + model = keras.Model(i, i) |
| 28 | + |
24 | 29 | recall = COCORecall( |
25 | 30 | max_detections=100, |
26 | 31 | category_ids=[1], |
27 | | - area_range=(32 ** 2, 64 ** 2), |
| 32 | + area_range=(0, 64 ** 2), |
28 | 33 | ) |
29 | 34 |
|
30 | 35 | # These would match if they were in the area range |
31 | | - y_true = np.array([[[0, 0, 10, 10, 1], [5, 5, 10, 10, 1]]]).astype( |
| 36 | + y_true = np.array([[[0, 0, 10, 10, 1], [5, 5, 10, 10, 1]]]).astype(np.float32) |
| 37 | + y_pred = np.array([[[0, 0, 10, 10, 1, 1.0], [5, 5, 10, 10, 1, 0.9]]]).astype( |
32 | 38 | np.float32 |
33 | 39 | ) |
| 40 | + |
| 41 | + model.compile(metrics=[recall]) |
| 42 | + model.evaluate(y_pred, y_true) |
| 43 | + |
| 44 | + self.assertAllEqual(recall.result(), 1.0) |
| 45 | + |
| 46 | + def test_recall_area_range_filtering(self): |
| 47 | + recall = COCORecall( |
| 48 | + max_detections=100, |
| 49 | + category_ids=[1], |
| 50 | + area_range=(32 ** 2, 64 ** 2), |
| 51 | + ) |
| 52 | + |
| 53 | + # These would match if they were in the area range |
| 54 | + y_true = np.array([[[0, 0, 10, 10, 1], [5, 5, 10, 10, 1]]]).astype(np.float32) |
34 | 55 | y_pred = np.array([[[0, 0, 10, 10, 1, 1.0], [5, 5, 10, 10, 1, 0.9]]]).astype( |
35 | 56 | np.float32 |
36 | 57 | ) |
|
0 commit comments