예제 #1
0
    def setup_class(cls):
        super().setup_class()
        cls.maskEstimator = cls.faceEngine.createMaskEstimator()

        cls.warpImageMedicalMask = FaceWarpedImage(VLImage.load(filename=FACE_WITH_MASK))
        cls.warpImageMissing = FaceWarpedImage(VLImage.load(filename=WARP_CLEAN_FACE))
        cls.warpImageOccluded = FaceWarpedImage(VLImage.load(filename=OCCLUDED_FACE))
예제 #2
0
    def setup_class(cls):
        super().setup_class()
        cls.glassesEstimator = cls.faceEngine.createGlassesEstimator()

        cls.warpNoGlasses = FaceWarpedImage(
            VLImage.load(filename=WARP_CLEAN_FACE))
        cls.warpEyeGlasses = FaceWarpedImage(
            VLImage.load(filename=WARP_FACE_WITH_EYEGLASSES))
        cls.warpSunGlasses = FaceWarpedImage(
            VLImage.load(filename=WARP_FACE_WITH_SUNGLASSES))
 def test_batch_estimate_with_success_and_error(self):
     """
     Test batch estimate with good and bad warp.
     """
     badWarp = FaceWarpedImage(VLImage.load(filename=WARP_CLEAN_FACE))
     badWarp.coreImage = VLIMAGE_SMALL.coreImage
     with pytest.raises(LunaSDKException) as exceptionInfo:
         self.estimator.estimateBasicAttributesBatch(
             warps=[self._warp, badWarp],
             estimateAge=True,
             estimateGender=True,
             estimateEthnicity=True,
             aggregate=False,
         )
     self.assertLunaVlError(exceptionInfo, LunaVLError.BatchedInternalError.format("Failed validation."))
     assert len(exceptionInfo.value.context) == 2, "Expect two errors in exception context"
     self.assertReceivedAndRawExpectedErrors(exceptionInfo.value.context[0], LunaVLError.Ok)
     self.assertReceivedAndRawExpectedErrors(exceptionInfo.value.context[1], LunaVLError.InvalidImageSize)
예제 #4
0
 def test_batch_detect_with_success_and_error(self):
     """
     Test batch detection with success and error using FACE_DET_V3 (there is no error with other detector)
     """
     badWarp = FaceWarpedImage(VLImage.load(filename=WARP_CLEAN_FACE))
     badWarp.coreImage = VLIMAGE_SMALL.coreImage
     for detector in self.detectors:
         with self.subTest(detectorType=detector.detectorType):
             with pytest.raises(LunaSDKException) as exceptionInfo:
                 detector.detect(
                     images=[VLIMAGE_ONE_FACE, VLIMAGE_BAD_IMAGE])
             self.assertLunaVlError(exceptionInfo,
                                    LunaVLError.BatchedInternalError)
             assert len(exceptionInfo.value.context
                        ) == 2, "Expect two errors in exception context"
             self.assertReceivedAndRawExpectedErrors(
                 exceptionInfo.value.context[0], LunaVLError.Ok)
             self.assertReceivedAndRawExpectedErrors(
                 exceptionInfo.value.context[1], LunaVLError.Internal)
예제 #5
0
 def test_extract_descriptors_batch_positive_and_negative(self):
     """
     Test estimate descriptor batch with one good warp and one bad (expected error).
     """
     for case in self.cases:
         for planVersion in case.versions:
             extractor = case.extractorFactory(descriptorVersion=planVersion)
             for kw in (dict(), dict(descriptorBatch=self.getBatch(planVersion, len(case.warps), case.type))):
                 for aggregate in (True, False):
                     with self.subTest(
                         type=case.type, plan_version=planVersion, aggregate=aggregate, external_descriptor=bool(kw)
                     ):
                         badWarp = FaceWarpedImage(VLImage.load(filename=WARP_CLEAN_FACE))
                         badWarp.coreImage = VLIMAGE_SMALL.coreImage
                         with pytest.raises(LunaSDKException) as exceptionInfo:
                             extractor.estimateDescriptorsBatch([case.warps[0], badWarp], aggregate=aggregate, **kw)
                         assert len(exceptionInfo.value.context) == 2, "Expect two errors in exception context"
                         self.assertReceivedAndRawExpectedErrors(exceptionInfo.value.context[0], LunaVLError.Ok)
                         self.assertReceivedAndRawExpectedErrors(
                             exceptionInfo.value.context[1], LunaVLError.InvalidImageSize
                         )
예제 #6
0
    def setup_class(cls):
        super().setup_class()
        cls.maskEstimator = cls.faceEngine.createMaskEstimator()

        cls.medicalMaskWarpNProperties = WarpNExpectedProperties(
            FaceWarpedImage(VLImage.load(filename=FACE_WITH_MASK)),
            MaskProperties(0.000, 0.999, 0.000))
        cls.missingMaskWarpNProperties = WarpNExpectedProperties(
            FaceWarpedImage(VLImage.load(filename=WARP_CLEAN_FACE)),
            MaskProperties(0.998, 0.002, 0.000))
        cls.occludedMaskWarpNProperties = WarpNExpectedProperties(
            FaceWarpedImage(VLImage.load(filename=OCCLUDED_FACE)),
            MaskProperties(0.260, 0.669, 0.071)  # TODO: bug
        )
        cls.imageMedicalMask = VLImage.load(filename=FULL_FACE_WITH_MASK)
        cls.warpImageMedicalMask = FaceWarpedImage(
            VLImage.load(filename=FACE_WITH_MASK))
        cls.imageMissing = VLImage.load(filename=FULL_FACE_NO_MASK)
        cls.warpImageMissing = FaceWarpedImage(
            VLImage.load(filename=WARP_CLEAN_FACE))
        cls.imageOccluded = VLImage.load(filename=FULL_OCCLUDED_FACE)
        cls.warpImageOccluded = FaceWarpedImage(
            VLImage.load(filename=OCCLUDED_FACE))

        cls.largeImage = VLImage.load(filename=LARGE_IMAGE)

        cls.detector = cls.faceEngine.createFaceDetector(
            DetectorType.FACE_DET_V3)
예제 #7
0
 def test_descriptor_batch_low_threshold_aggregation(self):
     """
     Test descriptor batch with low threshold warps with aggregation
     """
     faceWarp = FaceWarpedImage.load(filename=BAD_THRESHOLD_WARP)
     for descriptorVersion in EFDVa:
         with self.subTest(planVersion=descriptorVersion):
             extractor = self.faceEngine.createFaceDescriptorEstimator(descriptorVersion)
             descriptorBatch = self.getBatch(descriptorVersion, 2, DescriptorType.face)
             _, descriptor = extractor.estimateDescriptorsBatch(
                 [faceWarp] * 2, aggregate=1, descriptorBatch=descriptorBatch
             )
             assert descriptor.garbageScore < 0.6, "Expected low gs"
예제 #8
0
 def setup_class(cls):
     super().setup_class()
     cls.warper = cls.faceEngine.createFaceWarper()
     cls.mouthEstimator = cls.faceEngine.createMouthEstimator()
     CaseWarp = namedtuple("CaseWarp", ("warp", "detector"))
     cls.warpList = []
     for detector in cls.detectors:
         detection = detector.detectOne(VLIMAGE_ONE_FACE)
         cls.warpList.append(
             CaseWarp(cls.warper.warp(detection),
                      detector.detectorType.name))
     cls.warpList.append(
         CaseWarp(FaceWarpedImage(VLImage.load(filename=WARP_WHITE_MAN)),
                  "None"))
예제 #9
0
 def test_descriptor_batch_bad_threshold_aggregation(self):
     """
     Test descriptor batch with bad threshold warps with aggregation
     """
     faceWarp = FaceWarpedImage.load(filename=BAD_THRESHOLD_WARP)
     for descriptorVersion in [56]:
         with self.subTest(planVersion=descriptorVersion):
             extractor = self.faceEngine.createFaceDescriptorEstimator(descriptorVersion)
             descriptorBatch = self.getBatch(descriptorVersion, 2, DescriptorType.face)
             with pytest.raises(LunaSDKException) as exceptionInfo:
                 extractor.estimateDescriptorsBatch([faceWarp] * 2, aggregate=1, descriptorBatch=descriptorBatch)
             self.assertLunaVlError(
                 exceptionInfo,
                 LunaVLError.BatchedInternalError.format(
                     "Cant aggregate descriptors - all images'a GSs are less the threashold"
                 ),
             )
예제 #10
0
from lunavl.sdk.image_utils.image import VLImage
from tests.base import BaseTestClass
from tests.detect_test_class import VLIMAGE_SMALL
from tests.resources import WARP_WHITE_MAN, HUMAN_WARP, WARP_CLEAN_FACE, BAD_THRESHOLD_WARP

EFDVa = EXISTENT_FACE_DESCRIPTOR_VERSION_ABUNDANCE = [46, 52, 54, 56]

EHDVa = EXISTENT_HUMAN_DESCRIPTOR_VERSION_ABUNDANCE = [DHDV]


class DescriptorType(Enum):
    face = "face"
    human = "human"


faceWarp = FaceWarpedImage.load(filename=WARP_WHITE_MAN)
faceWarps = [faceWarp] * 3
humanWarp = HumanWarpedImage.load(filename=HUMAN_WARP)
humanWarps = [humanWarp] * 3


class DescriptorCase(NamedTuple):
    descriptor: BaseDescriptor
    aggregatedDescriptor: BaseDescriptor
    descriptorBatch: BaseDescriptorBatch
    type: DescriptorType
    estimator: Union[FaceDescriptorEstimator, HumanDescriptorEstimator]


class ExtractorCase(NamedTuple):
    type: DescriptorType
 def setUpClass(cls) -> None:
     """ Load warps. """
     cls._warp = FaceWarpedImage.load(filename=WARP_ONE_FACE)
     cls._warp2 = FaceWarpedImage.load(filename=WARP_CLEAN_FACE)
예제 #12
0
    def setup_class(cls):
        super().setup_class()
        cls.credibilityEstimator = cls.faceEngine.createCredibilityEstimator()

        cls.warp = FaceWarpedImage(VLImage.load(filename=WARP_CLEAN_FACE))
예제 #13
0
    FaceDescriptor,
    FaceDescriptorBatch,
)
from lunavl.sdk.errors.errors import LunaVLError
from lunavl.sdk.errors.exceptions import LunaSDKException
from lunavl.sdk.estimators.face_estimators.facewarper import FaceWarpedImage
from lunavl.sdk.indexes.base import IndexResult
from lunavl.sdk.indexes.builder import IndexBuilder
from lunavl.sdk.indexes.stored_index import DynamicIndex, DenseIndex, IndexType
from lunavl.sdk.estimators.face_estimators.face_descriptor import FaceDescriptorEstimator
from tests.base import BaseTestClass
from tests.resources import WARP_WHITE_MAN, WARP_ONE_FACE, WARP_CLEAN_FACE

EFDVa = EXISTENT_FACE_DESCRIPTOR_VERSION_ABUNDANCE = [54, 56, 57, 58]

faceWarp = FaceWarpedImage.load(filename=WARP_WHITE_MAN)
faceWarps = [FaceWarpedImage.load(filename=WARP_CLEAN_FACE), FaceWarpedImage.load(filename=WARP_ONE_FACE)]
currDir = os.path.dirname(__file__)
pathToStoredIndex = os.path.join(currDir, "data", "stored.index")
nonDefaultDynamicIndex = os.path.join(currDir, "data", "descriptor57.index")


class TestIndexFunctionality(BaseTestClass):
    """Test of indexes."""

    descriptorVersion: int
    nonDefaultDescriptorVersion: int
    defaultFaceEstimator: FaceDescriptorEstimator
    faceDescriptor: FaceDescriptor
    nonDefaultFaceDescriptor: FaceDescriptor
    faceDescriptorBatch: FaceDescriptorBatch