Skip to content

Latest commit

History

History

README.md

English | 简体中文

FastDeploy Android AAR Package

Currently FastDeploy Android SDK supports image classification, target detection, OCR text recognition, semantic segmentation and face detection. More AI tasks will be added in the future. The following is the API documents for each task. To use the models integrated in FastDeploy on Android, you only need to take the following steps.

  • Model initialization
  • Calling the predict interface
  • Visualization validation (optional)
Image ClassificationTarget DetectionOCR Text RecognitionPortrait SegmentationFace Detection
classifydetectionocrsegface

Content

Download and Configure SDK

Download FastDeploy Android SDK

The release version is as follows (Java SDK currently supports Android only):

PlatformFileDescription
Android Java SDKfastdeploy-android-sdk-0.0.0.aarNDK 20 compiles, minSdkVersion 15,targetSdkVersion 28

For more information for pre-compile library, please refer to: download_prebuilt_libraries.md.

Configure FastDeploy Android SDK

First, please copy fastdeploy-android-sdk-xxx.aar to the libs directory of your Android project, where xxx indicates the version number of the SDK you download.

├── build.gradle
├── libs
│ └── fastdeploy-android-sdk-xxx.aar
├── proguard-rules.pro
└── src

Then, please add FastDeploy SDK to build.gradble in your Android project.

dependencies {
implementationfileTree(include: ['*.aar'], dir: 'libs')
implementation'com.android.support:appcompat-v7:28.0.0'// ...
}

Image Classification API

PaddleClasModel Java API Introduction

  • Model initialization API: Model initialization API contains two methods, you can initialize directly through the constructor, or call init function at the appropriate program node. PaddleClasModel initialization parameters are described as follows:
    • modelFile: String, path to the model file in paddle format, e.g. model.pdmodel.
    • paramFile: String, path to the parameter file in paddle format, e.g. model.pdiparams.
    • configFile: String, preprocessing configuration file of model inference, e.g. infer_cfg.yml.
    • labelFile: String, optional, path to the label file, for visualization, e.g. imagenet1k_label_list.txt, in which each line contains a label.
    • option: RuntimeOption, optional, model initialization option. If this parameter is not passed, the default runtime option will be used.
// Constructor w/o label filepublicPaddleClasModel(); // An empty constructor, which can be initialised by calling init function later.publicPaddleClasModel(StringmodelFile, StringparamsFile, StringconfigFile);
publicPaddleClasModel(StringmodelFile, StringparamsFile, StringconfigFile, StringlabelFile);
publicPaddleClasModel(StringmodelFile, StringparamsFile, StringconfigFile, RuntimeOptionoption);
publicPaddleClasModel(StringmodelFile, StringparamsFile, StringconfigFile, StringlabelFile, RuntimeOptionoption);
// Call init manually w/o label filepublicbooleaninit(StringmodelFile, StringparamsFile, StringconfigFile, RuntimeOptionoption);
publicbooleaninit(StringmodelFile, StringparamsFile, StringconfigFile, StringlabelFile, RuntimeOptionoption);
  • Model prediction API: Model prediction API includes direct prediction API and API with visualization function. Direct prediction means that no image is saved and no result is rendered to Bitmap, but only the inference result is predicted. Prediction and visualization means to predict the result and visualize it, and save the visualized image to the specified path, and render the result to Bitmap (currently supports Bitmap in format ARGB8888), which can be displayed in camera later.
// Directly predict: do not save images or render result to Bitmap.publicClassifyResultpredict(BitmapARGB8888Bitmap);
// Predict and visualize: predict the result and visualize it, and save the visualized image to the specified path, and render the result to Bitmap.publicClassifyResultpredict(BitmapARGB8888Bitmap, StringsavedImagePath, floatscoreThreshold);
publicClassifyResultpredict(BitmapARGB8888Bitmap, booleanrendering, floatscoreThreshold); // Only rendering images without saving.
  • Model resource release API: Calling function release() API can release model resources, and true means successful release, false means failure. Calling function initialized() can determine whether the model is initialized successfully, and true means successful initialization, false means failure.
publicbooleanrelease(); // Release native resources.publicbooleaninitialized(); // Check if initialization is successful.

Target Detection API

PicoDet Java API Introduction

  • Model initialization API: Model initialization API contains two methods, you can initialize directly through the constructor, or call init function at the appropriate program node. PicoDet initialization parameters are described as follows:
    • modelFile: String, path to the model file in paddle format, e.g. model.pdmodel.
    • paramFile: String, path to the parameter file in paddle format, e.g. model.pdiparams.
    • configFile: String, preprocessing configuration file of model inference, e.g. infer_cfg.yml.
    • labelFile: String, optional, path to the label file, for visualization, e.g. coco_label_list.txt, in which each line contains a label.
    • option: RuntimeOption, optional, model initialization option. If this parameter is not passed, the default runtime option will be used.
// Constructor w/o label file.publicPicoDet(); // An empty constructor, which can be initialised by calling init function later.publicPicoDet(StringmodelFile, StringparamsFile, StringconfigFile);
publicPicoDet(StringmodelFile, StringparamsFile, StringconfigFile, StringlabelFile);
publicPicoDet(StringmodelFile, StringparamsFile, StringconfigFile, RuntimeOptionoption);
publicPicoDet(StringmodelFile, StringparamsFile, StringconfigFile, StringlabelFile, RuntimeOptionoption);
// Call init manually w/o label file.publicbooleaninit(StringmodelFile, StringparamsFile, StringconfigFile, RuntimeOptionoption);
publicbooleaninit(StringmodelFile, StringparamsFile, StringconfigFile, StringlabelFile, RuntimeOptionoption);
  • Model prediction API: Model prediction API includes direct prediction API and API with visualization function. Direct prediction means that no image is saved and no result is rendered to Bitmap, but only the inference result is predicted. Prediction and visualization means to predict the result and visualize it, and save the visualized image to the specified path, and render the result to Bitmap (currently supports Bitmap in format ARGB8888), which can be displayed in camera later.
// Directly predict: do not save images or render result to Bitmap.publicDetectionResultpredict(BitmapARGB8888Bitmap);
// Predict and visualize: predict the result and visualize it, and save the visualized image to the specified path, and render the result to Bitmap.publicDetectionResultpredict(BitmapARGB8888Bitmap, StringsavedImagePath, floatscoreThreshold);
publicDetectionResultpredict(BitmapARGB8888Bitmap, booleanrendering, floatscoreThreshold); // Only rendering images without saving.
  • Model resource release API: Calling function release() API can release model resources, and true means successful release, false means failure. Calling function initialized() can determine whether the model is initialized successfully, and true means successful initialization, false means failure.
publicbooleanrelease(); // Release native resources. publicbooleaninitialized(); // Check if initialization is successful.

OCR Text Recognition API

PP-OCRv2 & PP-OCRv3 Java API Introduction

  • Model initialization API: Model initialization API contains two methods, you can initialize directly through the constructor, or call init function at the appropriate program node. PP-OCR initialization parameters are described as follows:
    • modelFile: String, path to the model file in paddle format, e.g. model.pdmodel.
    • paramFile: String, path to the parameter file in paddle format, e.g. model.pdiparams.
    • labelFile: String, optional, path to the label file, for visualization, e.g. ppocr_keys_v1.txt, in which each line contains a label.
    • option: RuntimeOption, optional, model initialization option. If this parameter is not passed, the default runtime option will be used.
      Unlike other models, PP-OCRv2 and PP-OCRv3 contain base models such as DBDetector, Classifier and Recognizer, and pipeline types such as PPOCRv2 and PPOCRv3.
// Constructor w/o label filepublicDBDetector(StringmodelFile, StringparamsFile);
publicDBDetector(StringmodelFile, StringparamsFile, RuntimeOptionoption);
publicClassifier(StringmodelFile, StringparamsFile);
publicClassifier(StringmodelFile, StringparamsFile, RuntimeOptionoption);
publicRecognizer(StringmodelFile, StringparamsFile, StringlabelPath);
publicRecognizer(StringmodelFile, StringparamsFile, StringlabelPath, RuntimeOptionoption);
publicPPOCRv2(); // An empty constructor, which can be initialised by calling init function later.// Constructor w/o classifierpublicPPOCRv2(DBDetectordetModel, RecognizerrecModel);
publicPPOCRv2(DBDetectordetModel, ClassifierclsModel, RecognizerrecModel);
publicPPOCRv3(); // An empty constructor, which can be initialised by calling init function later.// Constructor w/o classifierpublicPPOCRv3(DBDetectordetModel, RecognizerrecModel);
publicPPOCRv3(DBDetectordetModel, ClassifierclsModel, RecognizerrecModel);
  • Model prediction API: Model prediction API includes direct prediction API and API with visualization function. Direct prediction means that no image is saved and no result is rendered to Bitmap, but only the inference result is predicted. Prediction and visualization means to predict the result and visualize it, and save the visualized image to the specified path, and render the result to Bitmap (currently supports Bitmap in format ARGB8888), which can be displayed in camera later.
// Directly predict: do not save images or render result to Bitmap.publicOCRResultpredict(BitmapARGB8888Bitmap);
// Predict and visualize: predict the result and visualize it, and save the visualized image to the specified path, and render the result to Bitmap.publicOCRResultpredict(BitmapARGB8888Bitmap, StringsavedImagePath);
publicOCRResultpredict(BitmapARGB8888Bitmap, booleanrendering); // Only rendering images without saving.
  • Model resource release API: Calling function release() API can release model resources, and true means successful release, false means failure. Calling function initialized() can determine whether the model is initialized successfully, and true means successful initialization, false means failure.
publicbooleanrelease(); // Release native resources. publicbooleaninitialized(); // Check if initialization is successful.

Semantic Segmentation API

PaddleSegModel Java API Introduction

  • Model initialization API: Model initialization API contains two methods, you can initialize directly through the constructor, or call init function at the appropriate program node. PaddleSegModel initialization parameters are described as follows:
    • modelFile: String, path to the model file in paddle format, e.g. model.pdmodel.
    • paramFile: String, path to the parameter file in paddle format, e.g. model.pdiparams.
    • configFile: String, preprocessing configuration file of model inference, e.g. infer_cfg.yml.
    • option: RuntimeOption, optional, model initialization option. If this parameter is not passed, the default runtime option will be used.
// Constructor w/o label filepublicPaddleSegModel(); // An empty constructor, which can be initialised by calling init function later.publicPaddleSegModel(StringmodelFile, StringparamsFile, StringconfigFile);
publicPaddleSegModel(StringmodelFile, StringparamsFile, StringconfigFile, RuntimeOptionoption);
// Call init manually w/o label filepublicbooleaninit(StringmodelFile, StringparamsFile, StringconfigFile, RuntimeOptionoption);
  • Model prediction API: Model prediction API includes direct prediction API and API with visualization function. Direct prediction means that no image is saved and no result is rendered to Bitmap, but only the inference result is predicted. Prediction and visualization means to predict the result and visualize it, and save the visualized image to the specified path, and render the result to Bitmap (currently supports Bitmap in format ARGB8888), which can be displayed in camera later.
// Directly predict: do not save images or render result to Bitmap.publicSegmentationResultpredict(BitmapARGB8888Bitmap);
// Predict and visualize: predict the result and visualize it, and save the visualized image to the specified path, and render the result to Bitmap.publicSegmentationResultpredict(BitmapARGB8888Bitmap, StringsavedImagePath, floatweight);
publicSegmentationResultpredict(BitmapARGB8888Bitmap, booleanrendering, floatweight); // Only rendering images without saving.// Modify result, but not return it. Concerning performance, you can use the following interface with CxxBuffer in SegmentationResult.publicbooleanpredict(BitmapARGB8888Bitmap, SegmentationResultresult);
publicbooleanpredict(BitmapARGB8888Bitmap, SegmentationResultresult, StringsavedImagePath, floatweight);
publicbooleanpredict(BitmapARGB8888Bitmap, SegmentationResultresult, booleanrendering, floatweight);
  • Set vertical or horizontal mode: For PP-HumanSeg series model, you should call this method to set the vertical mode to true.
publicvoidsetVerticalScreenFlag(booleanflag);
  • Model resource release API: Calling function release() API can release model resources, and true means successful release, false means failure. Calling function initialized() can determine whether the model is initialized successfully, and true means successful initialization, false means failure.
publicbooleanrelease(); // Release native resources.publicbooleaninitialized(); // Check if initialization is successful.

Face Detection API

SCRFD Java API Introduction

  • Model initialization API: Model initialization API contains two methods, you can initialize directly through the constructor, or call init function at the appropriate program node. PaddleSegModel initialization parameters are described as follows:
    • modelFile: String, path to the model file in paddle format, e.g. model.pdmodel.
    • paramFile: String, path to the parameter file in paddle format, e.g. model.pdiparams.
    • option: RuntimeOption, optional, model initialization option. If this parameter is not passed, the default runtime option will be used.
// Constructor w/o label file.publicSCRFD(); // An empty constructor, which can be initialised by calling init function later.publicSCRFD(StringmodelFile, StringparamsFile);
publicSCRFD(StringmodelFile, StringparamsFile, RuntimeOptionoption);
// Call init manually w/o label file.publicbooleaninit(StringmodelFile, StringparamsFile, RuntimeOptionoption);
  • Model prediction API: Model prediction API includes direct prediction API and API with visualization function. Direct prediction means that no image is saved and no result is rendered to Bitmap, but only the inference result is predicted. Prediction and visualization means to predict the result and visualize it, and save the visualized image to the specified path, and render the result to Bitmap (currently supports Bitmap in format ARGB8888), which can be displayed in camera later.
// Directly predict: do not save images or render result to Bitmap.publicFaceDetectionResultpredict(BitmapARGB8888Bitmap);
publicFaceDetectionResultpredict(BitmapARGB8888Bitmap, floatconfThreshold, floatnmsIouThreshold); // Set confidence thresholds and NMS thresholds.// Predict and visualize: predict the result and visualize it, and save the visualized image to the specified path, and render the result to Bitmap.publicFaceDetectionResultpredict(BitmapARGB8888Bitmap, StringsavedImagePath, floatconfThreshold, floatnmsIouThreshold);
publicFaceDetectionResultpredict(BitmapARGB8888Bitmap, booleanrendering, floatconfThreshold, floatnmsIouThreshold); // Only rendering images without saving.
  • Model resource release API: Calling function release() API can release model resources, and true means successful release, false means failure. Calling function initialized() can determine whether the model is initialized successfully, and true means successful initialization, false means failure.
publicbooleanrelease(); // Release native resources. publicbooleaninitialized(); // Check if initialization is successful.

YOLOv5Face Java API Introduction

  • Model initialization API: Model initialization API contains two methods, you can initialize directly through the constructor, or call init function at the appropriate program node. PaddleSegModel initialization parameters are described as follows:
    • modelFile: String, path to the model file in paddle format, e.g. model.pdmodel.
    • paramFile: String, path to the parameter file in paddle format, e.g. model.pdiparams.
    • option: RuntimeOption, optional, model initialization option. If this parameter is not passed, the default runtime option will be used.
// Constructor w/o label file.publicYOLOv5Face(); // An empty constructor, which can be initialised by calling init function later.publicYOLOv5Face(StringmodelFile, StringparamsFile);
publicYOLOv5Face(StringmodelFile, StringparamsFile, RuntimeOptionoption);
// Call init manually w/o label file.publicbooleaninit(StringmodelFile, StringparamsFile, RuntimeOptionoption);
  • Model prediction API: Model prediction API includes direct prediction API and API with visualization function. Direct prediction means that no image is saved and no result is rendered to Bitmap, but only the inference result is predicted. Prediction and visualization means to predict the result and visualize it, and save the visualized image to the specified path, and render the result to Bitmap (currently supports Bitmap in format ARGB8888), which can be displayed in camera later.
// Directly predict: do not save images or render result to Bitmap.publicFaceDetectionResultpredict(BitmapARGB8888Bitmap);
publicFaceDetectionResultpredict(BitmapARGB8888Bitmap, floatconfThreshold, floatnmsIouThreshold); // Set confidence thresholds and NMS thresholds.// Predict and visualize: predict the result and visualize it, and save the visualized image to the specified path, and render the result to Bitmap.publicFaceDetectionResultpredict(BitmapARGB8888Bitmap, StringsavedImagePath, floatconfThreshold, floatnmsIouThreshold);
publicFaceDetectionResultpredict(BitmapARGB8888Bitmap, booleanrendering, floatconfThreshold, floatnmsIouThreshold); // Only rendering images without saving.
  • Model resource release API: Calling function release() API can release model resources, and true means successful release, false means failure. Calling function initialized() can determine whether the model is initialized successfully, and true means successful initialization, false means failure.
publicbooleanrelease(); // Release native resources. publicbooleaninitialized(); // Check if initialization is successful.

Identification Result Description

  • Image classification result description
publicclassClassifyResult {
publicfloat[] mScores; // [n] Scores of every class(probability).publicint[] mLabelIds; // [n] Class ID, specific class type.publicbooleaninitialized(); // To test whether the result is valid.
}

Other reference: C++/Python corresponding ClassifyResult description: api/vision_results/classification_result.md

  • Target detection result description
publicclassDetectionResult {
publicfloat[][] mBoxes; // [n,4] Detecting box (x1,y1,x2,y2).publicfloat[] mScores; // [n] Score (confidence level, probability value) for each detecting box.publicint[] mLabelIds; // [n] Class ID.publicbooleaninitialized(); // To test whether the result is valid.
}

Other reference: C++/Python corresponding DetectionResult description: api/vision_results/detection_result.md

  • OCR text recognition result description
publicclassOCRResult {
publicint[][] mBoxes; // [n,8] indicates the coordinates of all target boxes detected in a single image. Each box is 8 int values representing the 4 coordinate points of the box, in the order of lower left, lower right, upper right, upper left.publicString[] mText; // [n] indicates the content recognized in multiple text boxes. publicfloat[] mRecScores; // [n] indicates the confidence level of the text recognized in the text box.publicfloat[] mClsScores; // [n] indicates the confidence level of the classification result of the text.publicint[] mClsLabels; // [n] indicates the direction classification category of the text box.publicbooleaninitialized(); // To test whether the result is valid.
}

Other reference: C++/Python corresponding OCRResult description: api/vision_results/ocr_result.md

  • Semantic segmentation result description
publicclassSegmentationResult {
publicint[] mLabelMap; // The predicted label map, each pixel position corresponds to a label HxW.publicfloat[] mScoreMap; // The predicted score map, each pixel position corresponds to a score HxW.publiclong[] mShape; // The real shape(H,W) of label map.publicbooleanmContainScoreMap = false; // Whether score map is included.// You can choose to use CxxBuffer directly instead of copying it to JAVA layer through JNI.// This method can improve performance to some extent.publicvoidsetCxxBufferFlag(booleanflag); // Set whether the mode is CxxBuffer.publicbooleanreleaseCxxBuffer(); // Release CxxBuffer manually!!!publicbooleaninitialized(); // Check if the result is valid.
} 

Other reference: C++/Python corresponding SegmentationResult description: api/vision_results/segmentation_result.md

  • Face detection result description
publicclassFaceDetectionResult {
publicfloat[][] mBoxes; // [n,4] detection box (x1,y1,x2,y2)publicfloat[] mScores; // [n] scores(confidence level, probability value) of every detection box publicfloat[][] mLandmarks; // [nx?,2] Each detected face corresponding keypointintmLandmarksPerFace = 0; // Each face corresponding keypoints numberpublicbooleaninitialized(); // Check if the result is valid.
} 

Other reference:C++/Python corresponding FaceDetectionResult description: api/vision_results/face_detection_result.md

Runtime Option Description

  • RuntimeOption setting description
publicclassRuntimeOption {
publicvoidenableLiteFp16(); // Enable fp16 precision inferencepublicvoiddisableLiteFP16(); // Disable fp16 precision inferencepublicvoidenableLiteInt8(); // Enable int8 precision inference, for quantized modelspublicvoiddisableLiteInt8(); // Disable int8 precision inferencepublicvoidsetCpuThreadNum(intthreadNum); // Set number of threads.publicvoidsetLitePowerMode(LitePowerModemode); // Set power mode.publicvoidsetLitePowerMode(StringmodeStr); // Set power mode by string.
}

Visualization Interface

FastDeploy Android SDK also provides visual interfaces that can be used to quickly validate the inference results. The following interfaces all render the result in the input Bitmap.

publicclassVisualize {
// Default parameter interface.publicstaticbooleanvisClassification(BitmapARGB8888Bitmap, ClassifyResultresult);
publicstaticbooleanvisDetection(BitmapARGB8888Bitmap, DetectionResultresult);
publicstaticbooleanvisFaceDetection(BitmapARGB8888Bitmap, FaceDetectionResultresult);
publicstaticbooleanvisOcr(BitmapARGB8888Bitmap, OCRResultresult);
publicstaticbooleanvisSegmentation(BitmapARGB8888Bitmap, SegmentationResultresult);
// Visual interface with configurable parameters. // visDetection: You can configure the threshold value (draw the boxes higher than the threshold), box line size, font size, labels, etc.publicstaticbooleanvisDetection(BitmapARGB8888Bitmap, DetectionResultresult, floatscoreThreshold);
publicstaticbooleanvisDetection(BitmapARGB8888Bitmap, DetectionResultresult, floatscoreThreshold, intlineSize, floatfontSize);
publicstaticbooleanvisDetection(BitmapARGB8888Bitmap, DetectionResultresult, String[] labels);
publicstaticbooleanvisDetection(BitmapARGB8888Bitmap, DetectionResultresult, String[] labels, floatscoreThreshold, intlineSize, floatfontSize);
// visClassification: You can configure the threshold value (draw the boxes higher than the threshold), font size, labels, etc.publicstaticbooleanvisClassification(BitmapARGB8888Bitmap, ClassifyResultresult, floatscoreThreshold,floatfontSize);
publicstaticbooleanvisClassification(BitmapARGB8888Bitmap, ClassifyResultresult, String[] labels);
publicstaticbooleanvisClassification(BitmapARGB8888Bitmap, ClassifyResultresult, String[] labels, floatscoreThreshold,floatfontSize);
// visSegmentation: Background weight.publicstaticbooleanvisSegmentation(BitmapARGB8888Bitmap, SegmentationResultresult, floatweight);
// visFaceDetection: String size, font size, etc.publicstaticbooleanvisFaceDetection(BitmapARGB8888Bitmap, FaceDetectionResultresult, intlineSize, floatfontSize);
}

The corresponding visualization types:

importcom.baidu.paddle.fastdeploy.vision.Visualize;

Examples of How to Use Models

  • Example 1: Using constructor function and default RuntimeOption.
importjava.nio.ByteBuffer;
importandroid.graphics.Bitmap;
importandroid.opengl.GLES20;
importcom.baidu.paddle.fastdeploy.vision.DetectionResult;
importcom.baidu.paddle.fastdeploy.vision.detection.PicoDet;
// Initialize model.PicoDetmodel = newPicoDet("picodet_s_320_coco_lcnet/model.pdmodel",
"picodet_s_320_coco_lcnet/model.pdiparams",
"picodet_s_320_coco_lcnet/infer_cfg.yml");
// Model inference.DetectionResultresult = model.predict(ARGB8888ImageBitmap); // Release model resources.model.release();
  • Example 2: Manually call init function at appropriate program nodes, and customize RuntimeOption.
// import id.importcom.baidu.paddle.fastdeploy.RuntimeOption;
importcom.baidu.paddle.fastdeploy.LitePowerMode;
importcom.baidu.paddle.fastdeploy.vision.DetectionResult;
importcom.baidu.paddle.fastdeploy.vision.detection.PicoDet;
// Create a new empty model.PicoDetmodel = newPicoDet(); // Model path.StringmodelFile = "picodet_s_320_coco_lcnet/model.pdmodel";
StringparamFile = "picodet_s_320_coco_lcnet/model.pdiparams";
StringconfigFile = "picodet_s_320_coco_lcnet/infer_cfg.yml";
// Set RuntimeOption.RuntimeOptionoption = newRuntimeOption();
option.setCpuThreadNum(2);
option.setLitePowerMode(LitePowerMode.LITE_POWER_HIGH);
option.enableLiteFp16();
// Initiaze with init function.model.init(modelFile, paramFile, configFile, option);
// Reading Bitmap, model prediction, resource release id.

How to Use the App Sample Project

FastDeploy provides some sample projects in the java/android/app directory. Since the java/android directory also contains JNI projects, users who want to use the sample projects also need to configure the NDK. If you only want to use the Java API and don't want to configure the NDK, you can jump to the detailed case links below.

Prepare for Environment

  1. Install Android Studio tools in your local environment, please refer to Android Stuido official website for detailed installation method.
  2. Get an Android phone and turn on USB debugging mode. How to turn on: Phone Settings -> Find Developer Options -> Turn on Developer Options and USB Debug Mode.

Notes:If your Android Studio is not configured with an NDK, please configure the it according to Installing and Configuring NDK and CMake in the Android Studio User Guide. You can either choose the latest NDK version or use the same version as the FastDeploy Android prediction library.

Configuration Steps

  1. The App sample project is located in directory fastdeploy/java/android/app.
  2. Open fastdeploy/java/android project by Android Studio, please note that the directory is java/android.
  3. Connect your phone to your computer, turn on USB debugging and file transfer mode, and connect your own mobile device on Android Studio (your phone needs to be enabled to allow software installation from USB).

image

Notes:

If you encounter an NDK configuration error during importing, compiling or running the program, please open File > Project Structure > SDK Location and change Andriod NDK location to your locally configured NDK path. The default NDK version in this project is 20. If you downloaded the NDK through SDK Tools in Andriod Studio (see "Prepare for Environment" in this section), you can select the default path by clicking the drop-down box. There is another way to configure the NDK: you can do it manually in the file java/android/local.properties, as shown above. If the above steps still can't solve the configuration error, please try to update Android Gradle plugin version according to section Updating Android Gradle plugin in official Andriod Studio documentation.

  1. Click the Run button to automatically compile the APP and install it to your phone. (The process will automatically download the pre-compiled FastDeploy Android library and model files, internet connection required.) The success interface is as follows. Figure 1: Install APP on phone; Figure 2: The opening interface, it will automatically recognize the objects in the picture and mark them; Figure 3: APP setting options, click setting in the upper right corner, and you can set different options.
APP iconAPP effectAPP setting options
app_picapp_resapp_setup

Switch Between Different Scenarios

App sample project only needs to switch between different Activity in AndroidManifest.xml to compile App in different scenarios.

image

  • Image classification scenario
<manifestxmlns:android="http://schemas.android.com/apk/res/android"package="com.baidu.paddle.fastdeploy.app.examples">
<!-- ... -->
<activityandroid:name=".classification.ClassificationMainActivity">
<!---->
</activity>
<activityandroid:name=".classification.ClassificationSettingsActivity"
</activity>
</application>
</manifest>
  • Target detection scenario
<manifestxmlns:android="http://schemas.android.com/apk/res/android"package="com.baidu.paddle.fastdeploy.app.examples">
<!-- ... -->
<activityandroid:name=".detection.DetectionMainActivity">
<!---->
</activity>
<activityandroid:name=".detection.DetectionSettingsActivity"
</activity>
</application>
</manifest>
  • OCR text detection scenario
<manifestxmlns:android="http://schemas.android.com/apk/res/android"package="com.baidu.paddle.fastdeploy.app.examples">
<!-- ... -->
<activityandroid:name=".ocr.OcrMainActivity">
<!---->
</activity>
<activityandroid:name=".ocr.OcrSettingsActivity"
</activity>
</application>
</manifest>
  • Portrait segmentation scenario
<manifestxmlns:android="http://schemas.android.com/apk/res/android"package="com.baidu.paddle.fastdeploy.app.examples">
<!-- ... -->
<activityandroid:name=".segmentation.SegmentationMainActivity">
<!---->
</activity>
<activityandroid:name=".segmentation.SegmentationSettingsActivity"
</activity>
</application>
</manifest>
  • Face detection scenario
<manifestxmlns:android="http://schemas.android.com/apk/res/android"package="com.baidu.paddle.fastdeploy.app.examples">
<!-- ... -->
<activityandroid:name=".facedet.FaceDetMainActivity">
<!---->
</activity>
<activityandroid:name=".facedet.FaceDetSettingsActivity"
</activity>
</application>
</manifest>