π Geometric Computer Vision Library for Spatial AI
Python artificial-intelligencecomputer-visiondeep-learninghacktoberfestimage-processingmachine-learningneural-networkpythonpytorchroboticsspatial-ai
improve tests, add docstring, address issues in demos
Luis Ferrazc387ffa58a4b
diff --git a/kornia/contrib/face_detection.py b/kornia/contrib/face_detection.pyindex 04dbc6cdf..f025472a8 100644--- a/kornia/contrib/face_detection.py+++ b/kornia/contrib/face_detection.py@@ -210,6 +210,15 @@ class FaceDetector(nn.Module):return batched_detsdef forward(self, image: torch.Tensor) -> List[torch.Tensor]:+ r"""Detect faces in a given batch of images.++ Args:+ image (torch.Tensor): batch of images :math:`(B,3,H,W)`++ Return:+ List[torch.Tensor]: list with the boxes found on each image. :math:`Bx(N,15)`++ """img = self.preprocess(image)out = self.model(img)return self.postprocess(out, img.shape[-2], img.shape[-1])diff --git a/test/test_contrib.py b/test/test_contrib.pyindex b33d38b98..f20168db0 100644--- a/test/test_contrib.py+++ b/test/test_contrib.py@@ -576,12 +576,17 @@ class TestFaceDetection:def test_smoke(self, device, dtype):assert kornia.contrib.FaceDetector().to(device, dtype) is not None- def test_valid(self, device, dtype):+ @pytest.mark.parametrize("batch_size", [1, 2, 4])+ def test_valid(self, batch_size, device, dtype):torch.manual_seed(44)- img = torch.rand(1, 3, 320, 320, device=device, dtype=dtype)+ img = torch.rand(3, 320, 320, device=device, dtype=dtype)face_detection = kornia.contrib.FaceDetector().to(device, dtype)- dets = face_detection(img)- assert len(dets) == 1+ dets = face_detection(torch.stack([img] * batch_size))+ assert isinstance(dets, list)+ assert len(dets) == batch_size # same as the number of images+ assert isinstance(dets[0], torch.Tensor)+ assert dets[0].shape[0] >= 0 # number of detections+ assert dets[0].shape[1] == 15 # dims of each detectiondef test_jit(self, device, dtype):op = kornia.contrib.FaceDetector().to(device, dtype)