Project import generated by Copybara.
GitOrigin-RevId: a6e7ccd12eb2ad9da2f723eb344658295ed85d46
This commit is contained in:
parent
16e5d7242d
commit
024f7bf0f1
|
@ -23,9 +23,9 @@
|
||||||
#include "mediapipe/framework/calculator_framework.h"
|
#include "mediapipe/framework/calculator_framework.h"
|
||||||
#include "mediapipe/framework/port/ret_check.h"
|
#include "mediapipe/framework/port/ret_check.h"
|
||||||
|
|
||||||
#if !defined(__EMSCRIPTEN__)
|
#if !defined(__EMSCRIPTEN__) || defined(__EMSCRIPTEN_PTHREADS__)
|
||||||
#include "mediapipe/util/cpu_util.h"
|
#include "mediapipe/util/cpu_util.h"
|
||||||
#endif // !__EMSCRIPTEN__
|
#endif // !__EMSCRIPTEN__ || __EMSCRIPTEN_PTHREADS__
|
||||||
|
|
||||||
#include "mediapipe/util/resource_util.h"
|
#include "mediapipe/util/resource_util.h"
|
||||||
#include "tensorflow/lite/error_reporter.h"
|
#include "tensorflow/lite/error_reporter.h"
|
||||||
|
@ -121,7 +121,7 @@ struct GPUData {
|
||||||
|
|
||||||
// Returns number of threads to configure XNNPACK delegate with.
|
// Returns number of threads to configure XNNPACK delegate with.
|
||||||
// (Equal to user provided value if specified. Otherwise, it returns number of
|
// (Equal to user provided value if specified. Otherwise, it returns number of
|
||||||
// high cores (hard-coded to 1 for __EMSCRIPTEN__))
|
// high cores (hard-coded to 1 for Emscripten without Threads extension))
|
||||||
int GetXnnpackNumThreads(
|
int GetXnnpackNumThreads(
|
||||||
const mediapipe::TfLiteInferenceCalculatorOptions& opts) {
|
const mediapipe::TfLiteInferenceCalculatorOptions& opts) {
|
||||||
static constexpr int kDefaultNumThreads = -1;
|
static constexpr int kDefaultNumThreads = -1;
|
||||||
|
@ -129,11 +129,11 @@ int GetXnnpackNumThreads(
|
||||||
opts.delegate().xnnpack().num_threads() != kDefaultNumThreads) {
|
opts.delegate().xnnpack().num_threads() != kDefaultNumThreads) {
|
||||||
return opts.delegate().xnnpack().num_threads();
|
return opts.delegate().xnnpack().num_threads();
|
||||||
}
|
}
|
||||||
#if !defined(__EMSCRIPTEN__)
|
#if !defined(__EMSCRIPTEN__) || defined(__EMSCRIPTEN_PTHREADS__)
|
||||||
return InferHigherCoreIds().size();
|
return InferHigherCoreIds().size();
|
||||||
#else
|
#else
|
||||||
return 1;
|
return 1;
|
||||||
#endif // !__EMSCRIPTEN__
|
#endif // !__EMSCRIPTEN__ || __EMSCRIPTEN_PTHREADS__
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculator Header Section
|
// Calculator Header Section
|
||||||
|
|
|
@ -32,13 +32,14 @@ project.
|
||||||
2. Run the Bazel build command to generate the AAR.
|
2. Run the Bazel build command to generate the AAR.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
bazel build -c opt --fat_apk_cpu=arm64-v8a,armeabi-v7a //path/to/the/aar/build/file:aar_name
|
bazel build -c opt --host_crosstool_top=@bazel_tools//tools/cpp:toolchain --fat_apk_cpu=arm64-v8a,armeabi-v7a \
|
||||||
|
//path/to/the/aar/build/file:aar_name
|
||||||
```
|
```
|
||||||
|
|
||||||
For the face detection AAR target we made in the step 1, run:
|
For the face detection AAR target we made in the step 1, run:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
bazel build -c opt --fat_apk_cpu=arm64-v8a,armeabi-v7a \
|
bazel build -c opt --host_crosstool_top=@bazel_tools//tools/cpp:toolchain --fat_apk_cpu=arm64-v8a,armeabi-v7a \
|
||||||
//mediapipe/examples/android/src/java/com/google/mediapipe/apps/aar_example:mp_face_detection_aar
|
//mediapipe/examples/android/src/java/com/google/mediapipe/apps/aar_example:mp_face_detection_aar
|
||||||
|
|
||||||
# It should print:
|
# It should print:
|
||||||
|
|
|
@ -527,7 +527,7 @@ REGISTER_CALCULATOR(Modulo3SourceCalculator);
|
||||||
// calculator.
|
// calculator.
|
||||||
class OutputAllSourceCalculator : public CalculatorBase {
|
class OutputAllSourceCalculator : public CalculatorBase {
|
||||||
public:
|
public:
|
||||||
static const int kNumOutputPackets = 100;
|
static constexpr int kNumOutputPackets = 100;
|
||||||
|
|
||||||
static ::mediapipe::Status GetContract(CalculatorContract* cc) {
|
static ::mediapipe::Status GetContract(CalculatorContract* cc) {
|
||||||
cc->Outputs().Index(0).Set<int>();
|
cc->Outputs().Index(0).Set<int>();
|
||||||
|
@ -550,7 +550,7 @@ REGISTER_CALCULATOR(OutputAllSourceCalculator);
|
||||||
// progress.
|
// progress.
|
||||||
class OutputOneAtATimeSourceCalculator : public CalculatorBase {
|
class OutputOneAtATimeSourceCalculator : public CalculatorBase {
|
||||||
public:
|
public:
|
||||||
static const int kNumOutputPackets = 1000;
|
static constexpr int kNumOutputPackets = 1000;
|
||||||
|
|
||||||
static ::mediapipe::Status GetContract(CalculatorContract* cc) {
|
static ::mediapipe::Status GetContract(CalculatorContract* cc) {
|
||||||
cc->Outputs().Index(0).Set<int>();
|
cc->Outputs().Index(0).Set<int>();
|
||||||
|
@ -577,7 +577,7 @@ REGISTER_CALCULATOR(OutputOneAtATimeSourceCalculator);
|
||||||
// input stream connected to this calculator can become full.
|
// input stream connected to this calculator can become full.
|
||||||
class DecimatorCalculator : public CalculatorBase {
|
class DecimatorCalculator : public CalculatorBase {
|
||||||
public:
|
public:
|
||||||
static const int kDecimationRatio = 101;
|
static constexpr int kDecimationRatio = 101;
|
||||||
|
|
||||||
static ::mediapipe::Status GetContract(CalculatorContract* cc) {
|
static ::mediapipe::Status GetContract(CalculatorContract* cc) {
|
||||||
cc->Inputs().Index(0).SetAny();
|
cc->Inputs().Index(0).SetAny();
|
||||||
|
|
|
@ -56,6 +56,19 @@ void AddJNINativeMethod(std::vector<JNINativeMethodStrings> *methods,
|
||||||
|
|
||||||
void RegisterNativesVector(JNIEnv *env, jclass cls,
|
void RegisterNativesVector(JNIEnv *env, jclass cls,
|
||||||
const std::vector<JNINativeMethodStrings> &methods) {
|
const std::vector<JNINativeMethodStrings> &methods) {
|
||||||
|
// A client Java project may not use some methods and classes that we attempt
|
||||||
|
// to register and could be removed by Proguard. In that case, we want to
|
||||||
|
// avoid triggering a crash due to ClassNotFoundException, so we are trading
|
||||||
|
// safety check here in exchange for flexibility to list out all registrations
|
||||||
|
// without worrying about usage subset by client Java projects.
|
||||||
|
if (!cls || methods.empty()) {
|
||||||
|
LOG(INFO) << "Skipping registration and clearing exception. Class or "
|
||||||
|
"native methods not found, may be unused and/or trimmed by "
|
||||||
|
"Proguard.";
|
||||||
|
env->ExceptionClear();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
JNINativeMethod *methods_array = new JNINativeMethod[methods.size()];
|
JNINativeMethod *methods_array = new JNINativeMethod[methods.size()];
|
||||||
for (int i = 0; i < methods.size(); i++) {
|
for (int i = 0; i < methods.size(); i++) {
|
||||||
JNINativeMethod jniNativeMethod{
|
JNINativeMethod jniNativeMethod{
|
||||||
|
@ -97,6 +110,13 @@ void RegisterGraphNatives(JNIEnv *env) {
|
||||||
(void *)&GRAPH_METHOD(nativeStartRunningGraph));
|
(void *)&GRAPH_METHOD(nativeStartRunningGraph));
|
||||||
AddJNINativeMethod(&graph_methods, graph, "nativeSetParentGlContext", "(JJ)V",
|
AddJNINativeMethod(&graph_methods, graph, "nativeSetParentGlContext", "(JJ)V",
|
||||||
(void *)&GRAPH_METHOD(nativeSetParentGlContext));
|
(void *)&GRAPH_METHOD(nativeSetParentGlContext));
|
||||||
|
AddJNINativeMethod(&graph_methods, graph, "nativeCloseAllPacketSources",
|
||||||
|
"(J)V",
|
||||||
|
(void *)&GRAPH_METHOD(nativeCloseAllPacketSources));
|
||||||
|
AddJNINativeMethod(&graph_methods, graph, "nativeWaitUntilGraphDone", "(J)V",
|
||||||
|
(void *)&GRAPH_METHOD(nativeWaitUntilGraphDone));
|
||||||
|
AddJNINativeMethod(&graph_methods, graph, "nativeReleaseGraph", "(J)V",
|
||||||
|
(void *)&GRAPH_METHOD(nativeReleaseGraph));
|
||||||
RegisterNativesVector(env, graph_class, graph_methods);
|
RegisterNativesVector(env, graph_class, graph_methods);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -130,11 +130,11 @@ cat > $(OUTS) <<EOF
|
||||||
"//third_party:androidx_legacy_support_v4",
|
"//third_party:androidx_legacy_support_v4",
|
||||||
"//third_party:camerax_core",
|
"//third_party:camerax_core",
|
||||||
"//third_party:camera2",
|
"//third_party:camera2",
|
||||||
"@com_google_code_findbugs//jar",
|
"@maven//:com_google_code_findbugs_jsr305",
|
||||||
"@com_google_common_flogger//jar",
|
"@maven//:com_google_flogger_flogger",
|
||||||
"@com_google_common_flogger_system_backend//jar",
|
"@maven//:com_google_flogger_flogger_system_backend",
|
||||||
"@com_google_guava_android//jar",
|
"@maven//:com_google_guava_guava",
|
||||||
"@androidx_lifecycle//jar",
|
"@maven//:androidx_lifecycle_lifecycle_common",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -144,18 +144,16 @@ def _proto_java_src_generator(name, proto_src, java_lite_out, srcs = []):
|
||||||
native.genrule(
|
native.genrule(
|
||||||
name = name + "_proto_java_src_generator",
|
name = name + "_proto_java_src_generator",
|
||||||
srcs = srcs + [
|
srcs = srcs + [
|
||||||
"@com_google_protobuf_javalite//:well_known_protos",
|
"@com_google_protobuf//:well_known_protos",
|
||||||
],
|
],
|
||||||
outs = [java_lite_out],
|
outs = [java_lite_out],
|
||||||
cmd = "$(location @com_google_protobuf_javalite//:protoc) " +
|
cmd = "$(location @com_google_protobuf//:protoc) " +
|
||||||
"--plugin=protoc-gen-javalite=$(location @com_google_protobuf_javalite//:protoc_gen_javalite) " +
|
|
||||||
"--proto_path=. --proto_path=$(GENDIR) " +
|
"--proto_path=. --proto_path=$(GENDIR) " +
|
||||||
"--proto_path=$$(pwd)/external/com_google_protobuf_javalite/src " +
|
"--proto_path=$$(pwd)/external/com_google_protobuf/src " +
|
||||||
"--javalite_out=$(GENDIR) " + proto_src + " && " +
|
"--java_out=lite:$(GENDIR) " + proto_src + " && " +
|
||||||
"mv $(GENDIR)/" + java_lite_out + " $$(dirname $(location " + java_lite_out + "))",
|
"mv $(GENDIR)/" + java_lite_out + " $$(dirname $(location " + java_lite_out + "))",
|
||||||
tools = [
|
tools = [
|
||||||
"@com_google_protobuf_javalite//:protoc",
|
"@com_google_protobuf//:protoc",
|
||||||
"@com_google_protobuf_javalite//:protoc_gen_javalite",
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user