[Bug Fix] fix FastDeploy.cmake.in errors for Android (#616)

* [Backend] fix lite backend save model error

* [Backend] fixed typos

* [FlyCV] optimize the integration of FlyCV

* [cmake] close some tests options

* [cmake] close some test option

* [FlyCV] remove un-need warnings

* [FlyCV] remove un-need GetMat method

* [FlyCV] optimize FlyCV codes

* [cmake] remove un-need cmake function in examples/CMakelists

* [cmake] support gflags for Android

* [Android] Run button shutter in sub Ui Thread

* [Android] Update CameraSurfaceView

* [Android] Update Android SDK usage docs

* [Android] Add facedet Android app example

* [cmake] fix FastDeploy.cmake.in errors for Android

* [Doc] update SetProcLibCpuNumThreads API doc
This commit is contained in:
DefTruth
2022-11-16 22:33:04 +08:00
committed by GitHub
parent fd81030351
commit ac805c26d9
12 changed files with 57 additions and 51 deletions

View File

@@ -18,8 +18,6 @@ set(PADDLEINFERENCE_VERSION @PADDLEINFERENCE_VERSION@)
set(OPENVINO_VERSION @OPENVINO_VERSION@)
set(WITH_LITE_STATIC @WITH_LITE_STATIC@)
set(WITH_OPENCV_STATIC @WITH_OPENCV_STATIC@)
set(WITH_LITE_FULL_API @WITH_LITE_FULL_API@)
set(WITH_LITE_FP16 @WITH_LITE_FP16@)
# set(ENABLE_OPENCV_CUDA @ENABLE_OPENCV_CUDA@)
set(OPENCV_FILENAME @OPENCV_FILENAME@)
set(OPENVINO_FILENAME @OPENVINO_FILENAME@)
@@ -106,15 +104,9 @@ if(ENABLE_LITE_BACKEND)
set(LITE_DIR ${CMAKE_CURRENT_LIST_DIR}/third_libs/install/${PADDLELITE_FILENAME})
if(ANDROID)
if(NOT WITH_LITE_STATIC)
if(WITH_LITE_FULL_API)
add_library(paddle_full_api_shared STATIC IMPORTED GLOBAL)
set_property(TARGET paddle_full_api_shared PROPERTY IMPORTED_LOCATION ${LITE_DIR}/lib/${ANDROID_ABI}/libpaddle_full_api_shared.so)
list(APPEND FASTDEPLOY_LIBS paddle_full_api_shared)
else()
add_library(paddle_light_api_shared STATIC IMPORTED GLOBAL)
set_property(TARGET paddle_light_api_shared PROPERTY IMPORTED_LOCATION ${LITE_DIR}/lib/${ANDROID_ABI}/libpaddle_light_api_shared.so)
list(APPEND FASTDEPLOY_LIBS paddle_light_api_shared)
endif()
endif()
else()
# Linux/Mac/Win/...
@@ -285,8 +277,6 @@ if(ANDROID)
message(STATUS " WITH_OPENCV_STATIC: : ${WITH_OPENCV_STATIC}")
if(ENABLE_LITE_BACKEND)
message(STATUS " WITH_LITE_STATIC : ${WITH_LITE_STATIC}")
message(STATUS " WITH_LITE_FULL_API : ${WITH_LITE_FULL_API}")
message(STATUS " WITH_LITE_FP16 : ${WITH_LITE_FP16}")
endif()
endif()
message(STATUS " DEPENDENCY_LIBS : ${FASTDEPLOY_LIBS}")

View File

@@ -33,6 +33,7 @@ function(fastdeploy_summary)
message(STATUS " ENABLE_ORT_BACKEND : ${ENABLE_ORT_BACKEND}")
message(STATUS " ENABLE_RKNPU2_BACKEND : ${ENABLE_RKNPU2_BACKEND}")
message(STATUS " ENABLE_PADDLE_BACKEND : ${ENABLE_PADDLE_BACKEND}")
message(STATUS " ENABLE_LITE_BACKEND : ${ENABLE_LITE_BACKEND}")
message(STATUS " ENABLE_POROS_BACKEND : ${ENABLE_POROS_BACKEND}")
message(STATUS " ENABLE_TRT_BACKEND : ${ENABLE_TRT_BACKEND}")
message(STATUS " ENABLE_OPENVINO_BACKEND : ${ENABLE_OPENVINO_BACKEND}")

View File

@@ -72,7 +72,6 @@ bool PaddleClasModel::BatchPredict(const std::vector<cv::Mat>& images, std::vect
FDERROR << "Failed to preprocess the input image." << std::endl;
return false;
}
reused_input_tensors_[0].name = InputInfoOfRuntime(0).name;
if (!Infer(reused_input_tensors_, &reused_output_tensors_)) {
FDERROR << "Failed to inference by runtime." << std::endl;

View File

@@ -32,8 +32,7 @@ FASTDEPLOY_DECL void EnableFlyCV();
/// Disable using FlyCV to process image while deploy vision models.
FASTDEPLOY_DECL void DisableFlyCV();
/*! @brief Set the cpu num threads of ProcLib. The cpu num threads
* of FlyCV and OpenCV is 2 by default.
/*! @brief Set the cpu num threads of ProcLib.
*/
FASTDEPLOY_DECL void SetProcLibCpuNumThreads(int threads);

View File

@@ -72,8 +72,8 @@ bool BGR2GRAY::ImplByOpenCV(FDMat* mat) {
}
#ifdef ENABLE_FLYCV
bool BGR2GRAY::ImplByFalconCV(FDMat* mat) {
fcv::Mat* im = mat->GetFalconCVMat();
bool BGR2GRAY::ImplByFlyCV(FDMat* mat) {
fcv::Mat* im = mat->GetFlyCVMat();
if (im->channels() != 3) {
FDERROR << "[BGR2GRAY] The channel of input image must be 3, but not it's " << im->channels() << "." << std::endl;
return false;
@@ -94,8 +94,8 @@ bool RGB2GRAY::ImplByOpenCV(FDMat* mat) {
}
#ifdef ENABLE_FLYCV
bool RGB2GRAY::ImplByFalconCV(FDMat* mat) {
fcv::Mat* im = mat->GetFalconCVMat();
bool RGB2GRAY::ImplByFlyCV(FDMat* mat) {
fcv::Mat* im = mat->GetFlyCVMat();
if (im->channels() != 3) {
FDERROR << "[RGB2GRAY] The channel of input image must be 3, but not it's " << im->channels() << "." << std::endl;
return false;

View File

@@ -45,22 +45,22 @@ class FASTDEPLOY_DECL BGR2GRAY : public Processor {
public:
bool ImplByOpenCV(FDMat* mat);
#ifdef ENABLE_FLYCV
bool ImplByFalconCV(FDMat* mat);
bool ImplByFlyCV(FDMat* mat);
#endif
virtual std::string Name() { return "BGR2GRAY"; }
static bool Run(FDMat* mat, ProcLib lib = ProcLib::OPENCV);
static bool Run(FDMat* mat, ProcLib lib = ProcLib::DEFAULT);
};
class FASTDEPLOY_DECL RGB2GRAY : public Processor {
public:
bool ImplByOpenCV(FDMat* mat);
#ifdef ENABLE_FLYCV
bool ImplByFalconCV(FDMat* mat);
bool ImplByFlyCV(FDMat* mat);
#endif
std::string Name() { return "RGB2GRAY"; }
static bool Run(FDMat* mat, ProcLib lib = ProcLib::OPENCV);
static bool Run(FDMat* mat, ProcLib lib = ProcLib::DEFAULT);
};

View File

@@ -149,6 +149,7 @@ bool YOLOv5Face::Preprocess(
HWC2CHW::Run(mat);
Cast::Run(mat, "float");
mat->ShareWithTensor(output);
output->shape.insert(output->shape.begin(), 1); // reshape to n, h, w, c
return true;

View File

@@ -15,14 +15,14 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".facedet.FaceDetMainActivity">
<activity android:name=".detection.DetectionMainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity
android:name=".facedet.FaceDetSettingsActivity"
android:name=".detection.DetectionSettingsActivity"
android:label="Settings">
</activity>
</application>

View File

@@ -77,8 +77,8 @@ public class ClassificationMainActivity extends Activity implements View.OnClick
private static final int INTENT_CODE_PICK_IMAGE = 100;
String savedImagePath = "result.jpg";
int lastFrameIndex = 0;
long lastFrameTime;
long timeElapsed = 0;
long frameCounter = 0;
// Call 'init' and 'release' manually later
PaddleClasModel predictor = new PaddleClasModel();
@@ -203,25 +203,31 @@ public class ClassificationMainActivity extends Activity implements View.OnClick
originShutterBitmap = ARGB8888ImageBitmap;
}
boolean modified = false;
long tc = System.currentTimeMillis();
ClassifyResult result = predictor.predict(
ARGB8888ImageBitmap, true, ClassificationSettingsActivity.scoreThreshold);
timeElapsed += (System.currentTimeMillis() - tc);
frameCounter++;
modified = result.initialized();
if (!savedImagePath.isEmpty()) {
synchronized (this) {
ClassificationMainActivity.this.savedImagePath = "result.jpg";
}
}
lastFrameIndex++;
if (lastFrameIndex >= 30) {
final int fps = (int) (lastFrameIndex * 1e9 / (System.nanoTime() - lastFrameTime));
if (frameCounter >= 30) {
final int fps = (int) (1000 / (timeElapsed / 30));
runOnUiThread(new Runnable() {
@SuppressLint("SetTextI18n")
public void run() {
tvStatus.setText(Integer.toString(fps) + "fps");
}
});
lastFrameIndex = 0;
lastFrameTime = System.nanoTime();
frameCounter = 0;
timeElapsed = 0;
}
return modified;
}

View File

@@ -84,8 +84,8 @@ public class DetectionMainActivity extends Activity implements View.OnClickListe
private static final int TIME_SLEEP_INTERVAL = 50; // ms
String savedImagePath = "result.jpg";
int lastFrameIndex = 0;
long lastFrameTime;
long timeElapsed = 0;
long frameCounter = 0;
// Call 'init' and 'release' manually later
PicoDet predictor = new PicoDet();
@@ -159,7 +159,7 @@ public class DetectionMainActivity extends Activity implements View.OnClickListe
public void run() {
try {
// Sleep some times to ensure picture has been correctly shut.
Thread.sleep(TIME_SLEEP_INTERVAL * 2); // 100ms
Thread.sleep(TIME_SLEEP_INTERVAL * 10); // 500ms
} catch (InterruptedException e) {
e.printStackTrace();
}
@@ -251,25 +251,30 @@ public class DetectionMainActivity extends Activity implements View.OnClickListe
}
boolean modified = false;
long tc = System.currentTimeMillis();
DetectionResult result = predictor.predict(
ARGB8888ImageBitmap, true, DetectionSettingsActivity.scoreThreshold);
timeElapsed += (System.currentTimeMillis() - tc);
frameCounter++;
modified = result.initialized();
if (!savedImagePath.isEmpty()) {
synchronized (this) {
DetectionMainActivity.this.savedImagePath = "result.jpg";
}
}
lastFrameIndex++;
if (lastFrameIndex >= 30) {
final int fps = (int) (lastFrameIndex * 1e9 / (System.nanoTime() - lastFrameTime));
if (frameCounter >= 30) {
final int fps = (int) (1000 / (timeElapsed / 30));
runOnUiThread(new Runnable() {
@SuppressLint("SetTextI18n")
public void run() {
tvStatus.setText(Integer.toString(fps) + "fps");
}
});
lastFrameIndex = 0;
lastFrameTime = System.nanoTime();
frameCounter = 0;
timeElapsed = 0;
}
return modified;
}

View File

@@ -36,7 +36,6 @@ import com.baidu.paddle.fastdeploy.app.ui.view.ResultListView;
import com.baidu.paddle.fastdeploy.app.ui.Utils;
import com.baidu.paddle.fastdeploy.app.ui.view.adapter.BaseResultAdapter;
import com.baidu.paddle.fastdeploy.app.ui.view.model.BaseResultModel;
import com.baidu.paddle.fastdeploy.vision.DetectionResult;
import com.baidu.paddle.fastdeploy.vision.FaceDetectionResult;
import com.baidu.paddle.fastdeploy.vision.facedet.SCRFD;
@@ -84,8 +83,8 @@ public class FaceDetMainActivity extends Activity implements View.OnClickListene
private static final int TIME_SLEEP_INTERVAL = 50; // ms
String savedImagePath = "result.jpg";
int lastFrameIndex = 0;
long lastFrameTime;
long timeElapsed = 0;
long frameCounter = 0;
// Call 'init' and 'release' manually later
SCRFD predictor = new SCRFD();
@@ -159,7 +158,7 @@ public class FaceDetMainActivity extends Activity implements View.OnClickListene
public void run() {
try {
// Sleep some times to ensure picture has been correctly shut.
Thread.sleep(TIME_SLEEP_INTERVAL * 2); // 100ms
Thread.sleep(TIME_SLEEP_INTERVAL * 10); // 500ms
} catch (InterruptedException e) {
e.printStackTrace();
}
@@ -251,25 +250,31 @@ public class FaceDetMainActivity extends Activity implements View.OnClickListene
}
boolean modified = false;
long tc = System.currentTimeMillis();
FaceDetectionResult result = predictor.predict(
ARGB8888ImageBitmap, true, FaceDetSettingsActivity.scoreThreshold, 0.4f);
timeElapsed += (System.currentTimeMillis() - tc);
frameCounter++;
modified = result.initialized();
if (!savedImagePath.isEmpty()) {
synchronized (this) {
FaceDetMainActivity.this.savedImagePath = "result.jpg";
}
}
lastFrameIndex++;
if (lastFrameIndex >= 30) {
final int fps = (int) (lastFrameIndex * 1e9 / (System.nanoTime() - lastFrameTime));
if (frameCounter >= 30) {
final int fps = (int) (1000 / (timeElapsed / 30));
runOnUiThread(new Runnable() {
@SuppressLint("SetTextI18n")
public void run() {
tvStatus.setText(Integer.toString(fps) + "fps");
}
});
lastFrameIndex = 0;
lastFrameTime = System.nanoTime();
frameCounter = 0;
timeElapsed = 0;
}
return modified;
}