Facial Training

Configuration

To use any Sybrin SDK you will need a Sybrin issued license. You can have a look at our licensing page to request a license.

Using the license provided you will need to build and instance of the SybrinFacialRecognitionConfiguration class that will help with configuring the SDKs' behavior.

For example:

SybrinFacialRecognitionConfiguration sfrc = new SybrinFacialRecognitionConfiguration
        .Builder(<sybrin_license_here>)
        .build(context);

To see the full range of configuration available please visit the SybrinFacialRecognitionConfiguration page

Calling feature

Did you know that you are able to pre-load all components needed for training and authentication? By using the Load Model feature found on the SybrinFacialRecognition class you are able to download previously trained models and initialize the machine learning components for a smoother start up!

To start the facial recognition training process you will need to get an instance of the SybrinFacialRecognition class using the configuration built earlier. With this object you will be able to call the trainFace method, which takes an identifying string as a parameter. The identifier is used to associate the trained recognition model with the user. The process works best when the identifier is unique to each user.

When the model is trained it is uploaded online where Sybrin's AI Superbots can keep it safe. Once the model is trained, you are able to download it at a later date.

Finally you can register for the 3 different callbacks right on the method call.

For example:

String identifier = "uniqueIdentifier";

SybrinFacialRecognition sfr = SybrinFacialRecognition.getInstance(this, sfrc);
 
sfr.trainFace(identifier)
        .addOnSuccessListener(new FacialTrainer.OnSuccessListener<FacialTrainingModel>() {
            @Override
            public void onSuccess(FacialTrainingModel result) {
                // Handle success
            }
        })
        .addOnFailureListener(new FacialTrainer.OnFailureListener() {
            @Override
             public void onFailure(FacialRecognitionException fre) {
                // Handle failure
            }
        })
        .addOnCancelListener(new FacialTrainer.onCancelListener() {
            @Override
            public void onCancel() {
                // Handle cancelation
            }
        });

Sybrin does not provide user management for the identifiers that are used to train and recognize on a specific license key. The proper management and storage of unique identifiers is the sole responsibility of the developer.

Subscribing to any of the callbacks on the trainFaces method is optional.

Handling callback responses

There are 3 different callbacks that can be subscribed to. They are as follows:

OnSuccessListener

When the SDK has completed the liveness detection process the result will be posted to the OnSuccessListener.onSuccess callback. The FacialTraningModel is returned as a result.

If the model failed to upload for whatever reason you can use the uploadModel method to attempt another upload. You can also check the upload status of the trained model.

For example:

sfr.trainFace(identifier)
        .addOnSuccessListener(new FacialTrainer.OnSuccessListener<FacialTrainingModel>() {
            @Override
            public void onSuccess(FacialTrainingModel result) {
                
                // Handle success
                boolean isUploaded = result.isUploaded();
            }
        });

Uploading model

If for some reason the model failed to upload during the normal operations of the SDK you can upload it at a later time. To check whether the model was upload use the isUploaded method.

For example:

sfr.trainFace(identifier)
        .addOnSuccessListener(new FacialTrainer.OnSuccessListener<FacialTrainingModel>() {
            @Override
            public void onSuccess(FacialTrainingModel result) {
                
                result.addOnModelUploadSuccessListener(new FacialTrainingModel.OnModelUploadSuccessListener() {
                        @Override
                        public void onModelUploadSuccess(float timeTaken) {
                            //Handle upload success
                        }
                    }).addOnModelUploadFailureListener(new FacialTrainingModel.OnModelUploadFailureListener() {
                        @Override
                        public void onModelUploadFailure(FacialRecognitionException ie) {
                            //Handle upload failure
                        }
                    }).uploadModel();
            }
        });

OnFailureListener

When the SDK encounters an error a FacialRecognitionException is posted to the OnFailureListener.onFailure callback. The FacialRecognitionException will contain all the needed information to help solve the issue causing the error.

For example:

sfr.trainFace(identifier)
        .addOnFailureListener(new FacialTrainer.OnFailureListener() {
            @Override
             public void onFailure(FacialRecognitionException fre) {
            
                // Get error message
                String error = fre.getLocalizedMessage();
            }
        });

If you would like to report a bug, contact us!

OnCancelListener

When the scanning process is interrupted by the user by pressing the back button the SDK will post a response to the OnCancelListener.onCancel callback. This callback has no return value.

For example:

sfr.trainFace(identifier)
        .addOnCancelListener(new FacialTrainer.OnCancelListener() {
            @Override
            public void onCancel() {
                // Do something when scanning is cancelled
            }
        });

Full example

Activity.java
SybrinFacialRecognitionConfiguration sfrc = new SybrinFacialRecognitionConfiguration
        .Builder(<sybrin_license_here>)
        .build(context);
        
String identifier = "uniqueIdentifier";

SybrinFacialRecognition sfr = SybrinFacialRecognition.getInstance(this, sfrc);
 
sfr.trainFace(identifier)
        .addOnSuccessListener(new FacialTrainer.OnSuccessListener<FacialTrainingModel>() {
            @Override
            public void onSuccess(FacialTrainingModel result) {
                
                // Handle success
                boolean isUploaded = result.isUploaded();
            }
        })
        .addOnFailureListener(new FacialTrainer.OnFailureListener() {
            @Override
             public void onFailure(FacialRecognitionException fre) {
            
                // Get error message
                String error = fre.getLocalizedMessage();
            }
        })
        .addOnCancelListener(new FacialTrainer.OnCancelListener() {
            @Override
            public void onCancel() {
                // Handle cancelation
            }
        });

Last updated