def createLivenessEngine(preparedConfig): faceEngine = fe.createFaceEngine("data") faceEngine.setSettingsProvider(preparedConfig) if not make_activation(faceEngine): raise ActivationLicenseError("License is not activated!") liveness_engine = fe.createLivenessEngine(faceEngine, "data") return liveness_engine
def setUp(cls): cls.faceEngine = f.createFaceEngine("data") if not make_activation(cls.faceEngine): raise ActivationLicenseError("License is not activated!") cls.config_desc = f.createSettingsProvider( "data/cnndescriptor_54.conf") cls.config = f.createSettingsProvider("data/faceengine.conf")
def loadAcquiredFaceEngineWithCnn46(): faceEnginePtr = fe.createFaceEngine("data", configPath) if not make_activation(faceEnginePtr): raise ActivationLicenseError("License is not activated!") config = fe.createSettingsProvider(configPath) config.setValue("DescriptorFactory::Settings", "model", 46) faceEnginePtr.setSettingsProvider(config) return faceEnginePtr
def setUpClass(cls): cls.faceEngine = fe.createFaceEngine("data") if not make_activation(cls.faceEngine): raise ActivationLicenseError("License is not activated!") cls.image = fe.Image() err = cls.image.load(os.path.join(testDataPath, "image1.ppm")) cls.assertTrue(cls, err.isOk) cls.assertTrue(cls, cls.image.isValid()) cls.face_for_redetect = fe.Face( cls.image, fe.Detection(fe.Rect(289, 94, 147, 185), 0.999999)) cls.faces_batch_for_redetect = [cls.face_for_redetect] * 10 cls.images_batch_for_detect = [cls.image] * 10 cls.rectangles = [cls.image.getRect()] * 10
def extractorAggregation(self, version, useMobileNet, cpuType, device): configPath = os.path.join(self.dataPath, "faceengine.conf") runtimeConfigPath = os.path.join(self.dataPath, "runtime.conf") faceEngine = fe.createFaceEngine(self.dataPath) self.assertTrue(make_activation(faceEngine)) config = fe.createSettingsProvider(configPath) runtimeConf = fe.createSettingsProvider(runtimeConfigPath) config.setValue("DescriptorFactory::Settings", "model", fe.SettingsProviderValue(version)) config.setValue("DescriptorFactory::Settings", "useMobileNet", fe.SettingsProviderValue(useMobileNet)) config.setValue("system", "verboseLogging", fe.SettingsProviderValue(5)) config.setValue("FaceDetV3::Settings", "minFaceSize", 20) runtimeConf.setValue("Runtime", "deviceClass", fe.SettingsProviderValue(device)) runtimeConf.setValue("Runtime", "cpuClass", fe.SettingsProviderValue(cpuType)) faceEngine.setSettingsProvider(config) faceEngine.setRuntimeSettingsProvider(runtimeConf) warps = [fe.Image(), fe.Image()] err1 = warps[0].load(os.path.join(self.test_data_path, "warp1.ppm")) self.assertTrue(err1.isOk) err2 = warps[1].load(os.path.join(self.test_data_path, "warp2.ppm")) self.assertTrue(err2.isOk) extractor = faceEngine.createExtractor() batch = faceEngine.createDescriptorBatch(2) descriptor = faceEngine.createDescriptor() aggr = faceEngine.createDescriptor() res = extractor.extractFromWarpedImageBatch(warps, batch, aggr, 1) self.assertFalse(res[0].isError) res, value = extractor.extractFromWarpedImage(warps[0], descriptor) self.assertTrue(res.isOk) self.assertEqual(descriptor.getModelVersion(), batch.getModelVersion()) data_expected = descriptor.getData() getErr, tmpDescriptorActual = batch.getDescriptorFast(0) self.assertTrue(getErr.isOk) data_actual = tmpDescriptorActual.getData() descLength = descriptor.getDescriptorLength() for j in range(descLength): self.assertEqual(data_expected[j], data_actual[j]) del extractor del batch del descriptor del aggr
def setUp(cls): cls.faceEngine = f.createFaceEngine("data") if not make_activation(cls.faceEngine): raise ActivationLicenseError("License is not activated!") cls.warper = cls.faceEngine.createWarper()
def extractorBatch(self, version, useMobileNet, cpuType, device): configPath = os.path.join(self.dataPath, "faceengine.conf") runtimeConfigPath = os.path.join(self.dataPath, "runtime.conf") faceEngine = fe.createFaceEngine(self.dataPath) self.assertTrue(make_activation(faceEngine)) config = fe.createSettingsProvider(configPath) runtimeConf = fe.createSettingsProvider(runtimeConfigPath) config.setValue("DescriptorFactory::Settings", "model", fe.SettingsProviderValue(version)) config.setValue("DescriptorFactory::Settings", "useMobileNet", fe.SettingsProviderValue(useMobileNet)) config.setValue("system", "verboseLogging", fe.SettingsProviderValue(5)) config.setValue("FaceDetV3::Settings", "minFaceSize", 20) runtimeConf.setValue("Runtime", "deviceClass", fe.SettingsProviderValue(device)) runtimeConf.setValue("Runtime", "cpuClass", fe.SettingsProviderValue(cpuType)) faceEngine.setSettingsProvider(config) faceEngine.setRuntimeSettingsProvider(runtimeConf) warps = [fe.Image(), fe.Image()] err1 = warps[0].load(os.path.join(self.test_data_path, "warp1.ppm")) self.assertTrue(err1.isOk) err2 = warps[1].load(os.path.join(self.test_data_path, "warp2.ppm")) self.assertTrue(err2.isOk) extractor = self.faceEngine.createExtractor() batch = self.faceEngine.createDescriptorBatch(2) descriptor = self.faceEngine.createDescriptor() res_batch, _, garbage_scores = extractor.extractFromWarpedImageBatch( warps, batch, descriptor, 2) self.assertTrue(res_batch.isOk) with open( self.test_data_path + "/batch12_" + str(version) + "_actual.bin", "wb") as out_file: for i in range(2): getErr, descriptor_from_batch = batch.getDescriptorFast(i) self.assertTrue(getErr.isOk) out_file.write(descriptor_from_batch.getData()) for i_desc in range(2): res, value = extractor.extractFromWarpedImage( warps[i_desc], descriptor) self.assertTrue(res.isOk) self.assertEqual(descriptor.getModelVersion(), batch.getModelVersion()) dataExpected = descriptor.getData() getErr, tmpDescriptor = batch.getDescriptorFast(i_desc) self.assertTrue(getErr.isOk) dataActual = tmpDescriptor.getData() descLength = descriptor.getDescriptorLength() for j in range(descLength): self.assertEqual(dataExpected[j], dataActual[j]) self.assertAlmostEqual(value, garbage_scores[i_desc], delta=0.0001) # test of saving and loading from archive batch_loaded = self.faceEngine.createDescriptorBatch(2) err, full_data_default1 = batch.save() self.assertTrue(err.isOk) err_load = batch_loaded.load(full_data_default1, len(full_data_default1)) self.assertTrue(err_load.isOk) self.assertBatchDescriptorsEquality(batch, batch_loaded) err, full_data_default2 = batch.save(fe.Save.Default) self.assertTrue(err.isOk) err_load = batch_loaded.load(full_data_default2, len(full_data_default2)) self.assertTrue(err_load.isOk) self.assertBatchDescriptorsEquality(batch, batch_loaded) err, full_data_no_signature = batch.save(fe.Save.NoSignature) self.assertTrue(err.isOk) err_load = batch_loaded.load(full_data_no_signature, len(full_data_no_signature)) # we cannot load batch from archive without signature self.assertTrue(err_load.isError) self.assertTrue(err_load.error, fe.SerializeError.Signature) del extractor del batch del descriptor del batch_loaded
def extractor(self, version, refGS, useMobileNet, cpuType, device): versionString = str(version) + ("", "_mobilenet")[useMobileNet] configPath = os.path.join(self.dataPath, "faceengine.conf") runtimeConfigPath = os.path.join(self.dataPath, "runtime.conf") faceEngine = fe.createFaceEngine(self.dataPath) self.assertTrue(make_activation(faceEngine)) config = fe.createSettingsProvider(configPath) runtimeConf = fe.createSettingsProvider(runtimeConfigPath) config.setValue("DescriptorFactory::Settings", "model", fe.SettingsProviderValue(version)) config.setValue("DescriptorFactory::Settings", "useMobileNet", fe.SettingsProviderValue(useMobileNet)) config.setValue("FaceDetV3::Settings", "minFaceSize", 20) config.setValue("system", "verboseLogging", fe.SettingsProviderValue(5)) runtimeConf.setValue("Runtime", "deviceClass", fe.SettingsProviderValue(device)) runtimeConf.setValue("Runtime", "verboseLogging", fe.SettingsProviderValue(4)) runtimeConf.setValue("Runtime", "cpuClass", fe.SettingsProviderValue(cpuType)) faceEngine.setSettingsProvider(config) faceEngine.setRuntimeSettingsProvider(runtimeConf) warp = fe.Image() err = warp.load(os.path.join(self.test_data_path, "warp1.bmp")) self.assertTrue(err.isOk) warp.save(os.path.join(self.test_data_path, "outbmp.bmp")) extractor = faceEngine.createExtractor() descriptor = faceEngine.createDescriptor() res, value = extractor.extractFromWarpedImage(warp, descriptor) self.assertTrue(res.isOk) data1 = descriptor.getData() with open( self.test_data_path + "/descriptor1_" + versionString + "_actual.bin", "wb") as out_file: out_file.write(data1) self.assertAlmostEqual(refGS, value, delta=(0.02, 0.03)[useMobileNet]) refPath = os.path.join(self.test_data_path, "descriptor1_" + versionString + ".bin") with open(refPath, "rb") as file: read_data = file.read() descriptorExpected = faceEngine.createDescriptor() err_load = descriptorExpected.load(read_data, len(read_data)) print(err_load) self.assertTrue(err_load.isOk) dataActual = descriptor.getData() dataExpected = descriptorExpected.getData() self.assertEqual(descriptorExpected.getModelVersion(), descriptor.getModelVersion()) for i in range(descriptor.getDescriptorLength()): self.assertEqual(dataActual[i], dataExpected[i]) descriptor_cases = { descriptor: dataActual, descriptorExpected: dataExpected } for i, data in descriptor_cases.items(): with self.subTest(descriptor=i): self.assertDescriptors(i, data) del extractor del descriptor
def setUp(cls): if not make_activation(cls.faceEngine): raise ActivationLicenseError("License is not activated!")