Since: API level 34
public class

KnoxAiSession

extends Object
java.lang.Object
   ↳ com.samsung.android.knox.ex.knoxAI.KnoxAiSession

Deprecated in API level 37

Class Overview

Class of managing Knox AI Session.

Since
API level 34
KNOX 3.7.1

Summary

Nested Classes
enum KnoxAiSession.CompUnit Deprecated in API level 37  
enum KnoxAiSession.DataFormat Deprecated in API level 37  
enum KnoxAiSession.DataType Deprecated in API level 37  
enum KnoxAiSession.ExecType Deprecated in API level 37  
enum KnoxAiSession.Mode Deprecated in API level 37  
enum KnoxAiSession.ModelInputType Deprecated in API level 37  
enum KnoxAiSession.ModelType Deprecated in API level 37  
Public Constructors
KnoxAiSession()
Deprecated in API level 37
Public Methods
KnoxAiManager.ErrorCodes close()
Deprecated in API level 37
KnoxAiManager.ErrorCodes execute(DataBuffer[] inputs, DataBuffer[] outputs)
Deprecated in API level 37
KnoxAiManager.ErrorCodes getModelInputShape(int inputIndex, int[] shape)
Deprecated in API level 37
KnoxAiManager.ErrorCodes open(KfaOptions options)
Deprecated in API level 37
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public KnoxAiSession ()

Since: API level 34

Deprecated in API level 37

Default Constructor

Since
API level 34
KNOX 3.7.1

Public Methods

public KnoxAiManager.ErrorCodes close ()

Since: API level 34

Deprecated in API level 37

Closes the current Knox AI session.

Returns
  • Returns status of close() API. Returns 0 on success.
Throws
SecurityException
Usage
Called at the end of AI model execution to release the instance of session.
     int status = -1;
     status = session.close();
 
Permission
com.samsung.android.knox.permission.KNOX_NDA_AI
Since
API level 34
KNOX 3.7.1
Multiuser Environment
User Scope
See Also

public KnoxAiManager.ErrorCodes execute (DataBuffer[] inputs, DataBuffer[] outputs)

Since: API level 34

Deprecated in API level 37

Executes the AI model using the given inputs and outputs the result of execution.

Returns
  • Returns status of Execute API. Returns 0 on success.
Throws
SecurityException
Usage
Called after the session is opened to execute AI model.
     DataBuffer[] input = new DataBuffer[1];
     DataBuffer[] output = new DataBuffer[1];
     DataBuffer dB = new DataBuffer();
     dB.setDataType((byte) 0);
     dB.setDataFormat((byte) 1);
     int[] shape = new int[]{1, 224, 224, 3};
     dB.setShape(shape);
     dB.setDataSource((byte)2);
     try {
         SharedMemory sharedMemory = SharedMemory.create("data", indata.length * 4);  
         ByteBuffer bBuffer = sharedMemory.mapReadWrite();
         byte[] bytes = DataBuffer.readFloatToBytes(indata);
         bBuffer.put(bytes);
         dB.setDataShared(sharedMemory);
     } catch (ErrnoException e) {
         e.printStackTrace();
     }
     input[0] = dB;
     status = session.execute(input, output);
     if (output != null && output.length > 0 ) {
         if (output[0].getDataSource() == 0) {
             float[] outputData = output[0].getDataOriginal();
         }
     }
 
Permission
com.samsung.android.knox.permission.KNOX_NDA_AI
Since
API level 34
KNOX 3.7.1
Multiuser Environment
User Scope

public KnoxAiManager.ErrorCodes getModelInputShape (int inputIndex, int[] shape)

Since: API level 34

Deprecated in API level 37

Gets the dimensions of input data based on the AI model.

Returns
  • Returns status of getModelInputShape() API. Returns 0 on success.
Throws
SecurityException
Usage
Called before execute API to get the expected input dimensions.
    int status = -1;
    int[] inputShape = new int[4];
    status = session.getModelInputShape(0, inputShape);
  
Permission
com.samsung.android.knox.permission.KNOX_NDA_AI
Since
API level 34
KNOX 3.7.1
Multiuser Environment
User Scope
See Also

public KnoxAiManager.ErrorCodes open (KfaOptions options)

Since: API level 34

Deprecated in API level 37

Opens the Knox AI session and loads the AI model using the given KfaOptions.

Returns
  • Returns status of Execute API. Returns 0 on success.
Throws
SecurityException
Usage
Called at beginning before AI model execution to load the model.
     KfaOptions options = new KfaOptions();
     options.setExecType(0);
     options.setCompUnit(0);
     options.setmType(4);
     ArrayList ipNames = new ArrayList();
     ipNames.add("keras_layer_input");
     options.setInputNames(ipNames);
     ArrayList opNames = new ArrayList();
     opNames.add("Identity");
     options.setOutputNames(opNames);
     options.setModelInputType(0);
     options.setWeights_file("/data/KFA/converted_model_224.tflite.pkg");
     options.setModel_file("/data/KFA/converted_model_224.tflite.pkg");
     status = session.open(options);
     return status;
 
Permission
com.samsung.android.knox.permission.KNOX_NDA_AI
Since
API level 34
KNOX 3.7.1
Multiuser Environment
User Scope