|
| 1 | + |
| 2 | +import tensorflow as tf |
| 3 | +from absl.testing import parameterized |
| 4 | +from official.projects.fcos.model.model import FCOS |
| 5 | + |
| 6 | +class FCOSModelTest(parameterized.TestCase, tf.test.TestCase): |
| 7 | + |
| 8 | + def test_fcos_model_instantiation_and_forward_pass(self): |
| 9 | + """Tests that the FCOS model can be instantiated and run.""" |
| 10 | + |
| 11 | + # Create the model |
| 12 | + model = FCOS() |
| 13 | + |
| 14 | + # specific input shape [Batch, H, W, 3] |
| 15 | + input_image_size = (1, 800, 1024, 3) |
| 16 | + inputs = tf.random.normal(input_image_size) |
| 17 | + |
| 18 | + # Run forward pass |
| 19 | + outputs = model(inputs, training=False) |
| 20 | + |
| 21 | + # Check output keys |
| 22 | + self.assertIn('classifier', outputs) |
| 23 | + self.assertIn('box', outputs) |
| 24 | + self.assertIn('centerness', outputs) |
| 25 | + |
| 26 | + # Check output shapes (approximate checks based on feature map sizes) |
| 27 | + # We expect a flattened output of shape [Batch, N_points, Channels] |
| 28 | + self.assertEqual(outputs['classifier'].shape[0], 1) |
| 29 | + self.assertEqual(outputs['box'].shape[0], 1) |
| 30 | + self.assertEqual(outputs['centerness'].shape[0], 1) |
| 31 | + |
| 32 | + # Detailed shape check for channels |
| 33 | + self.assertEqual(outputs['classifier'].shape[-1], 80) # 80 classes |
| 34 | + self.assertEqual(outputs['box'].shape[-1], 4) # 4 regression coords |
| 35 | + self.assertEqual(outputs['centerness'].shape[-1], 1)# 1 centerness score |
| 36 | + |
| 37 | +if __name__ == '__main__': |
| 38 | + tf.test.main() |
0 commit comments