Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not found: ValidatedGraphConfig Initialization failed.When I use handtrackinggpu.aar for Android,print:No registered calculator found. #1450

Closed
DandyLorenz opened this issue Dec 29, 2020 · 7 comments

Comments

@DandyLorenz
Copy link

DandyLorenz commented Dec 29, 2020

I build hand tracking aar or handTrackingGpu.aar,use it in Android error,print:
MediaPipeException: not found: ValidatedGraphConfig Initialization failed.
No registered object with name: HandLandmarkTrackingGpu;
Unable to find Calculator "HandLandmarkTrackingGpu"

this is my error information from android stdio log print when I build hand trcking application:
QQ截图20210104161335

I am using the new version 0.8.2, but the same problem has occurred to me. this is link:
issues-546 The problem has not been fixed, I will give more infomation,help me:

  1. use version:mediapipe V0.8.2
  2. build object:hand tracking gpu aar
  3. Additional questions:
    The above error is to use AAR to compile Android APK for Hand Tracking GPU .
    My compilation environment WSL (Windows Subsystem for Linux) is normal, it can compile aar and apk normally. Fortunately, I have successfully built hellow world (desktop), edge detection (aar), hair segmentation (aar), facedetectiongpu (aar), they can work normally in my application. However, only the compilation of handdetectiongpu aar has an appeal problem.
  4. Compilation process(Key command),I build my_handtrackinggpu_aar.aar:
    1. cd /root/mediapipe/mediapipe/examples/android/src/java/com/google/mediapipe/apps
      mkdir my_handtrackinggpu_aar && cd my_handtrackinggpu_aar
    2. vi BUILD

    write this in BUILD file:

 load("//mediapipe/java/com/google/mediapipe:mediapipe_aar.bzl", "mediapipe_aar")
                mediapipe_aar(
                name = "my_handtrackinggpu_aar",
                calculators = ["//mediapipe/graphs/hand_tracking:mobile_calculators"],
        )

There is one way of writing, but it still doesn't work,like this:

load("//mediapipe/java/com/google/mediapipe:mediapipe_aar.bzl", "mediapipe_aar")
                mediapipe_aar(
                name = "my_handtrackinggpu_aar",
                calculators = ["//mediapipe/graphs/hand_tracking:mobile_calculators",
                "//mediapipe/calculators/image:opencv_image_encoder_calculator"],
        )

There is another way of writing, but it also doesn't work and print our error,like this:

load("//mediapipe/java/com/google/mediapipe:mediapipe_aar.bzl", "mediapipe_aar")
mediapipe_aar(
    name = "my_handtrackinggpu_aar",
    calculators = [
"//mediapipe/graphs/hand_tracking:mobile_calculators",
 "//mediapipe/calculators/image:opencv_image_encoder_calculator",
"//mediapipe/calculators/core:pass_through_calculator",
"//mediapipe/framework/formats:classification_cc_proto",
"//mediapipe/calculators/core:constant_side_packet_calculator",
"//mediapipe/calculators/core:flow_limiter_calculator",
"//mediapipe/graphs/hand_tracking/subgraphs:hand_renderer_gpu",
"//mediapipe/modules/hand_landmark:hand_landmark_tracking_gpu",
    ],
)
  1. #build aar:
cd /root/mediapipe && chmod -R 755 mediapipe/
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/my_handtrackinggpu_aar:my_handtrackinggpu_aar

I think the above command is suspicious, because I want to compile a gpu version, but I am not sure whether it is correct or not. From the result, the aar cannot work normally.

  1. #build binary_graph:
    bazel build -c opt mediapipe/graphs/hand_tracking:hand_tracking_mobile_gpu_binary_graph
    ## Use the above command to output the result normally, I will copy the corresponding file to my Android project:
    copy bazel-bin/mediapipe/examples/android/src/java/com/google/mediapipe/apps/my_handtrackinggpu_aar into android project "libs" directory
    copy bazel-bin/mediapipe/graphs/hand_trackinghand_tracking_mobile_gpu.binarypb into android project,"assets" directory
    copy mediapipe/models/hand_landmark.tflite into android project,"assets" directory
    copy mediapipe/models/palm_detection.tflite into android project,"assets" directory

  2. The next step is to build the Android project,I think my project Including dependence is normal.some informations:

    minSdkVersion 21;targetSdkVersion 28;
    def camerax_version = "1.0.0-rc01"
    implementation "androidx.camera:camera-core:$camerax_version"
    implementation "androidx.camera:camera-camera2:$camerax_version"
    implementation "androidx.camera:camera-lifecycle:$camerax_version"

6.MainActivity.java

public class MainActivity extends AppCompatActivity {
  private static final String TAG = "MainActivity";

  private static final String BINARY_GRAPH_NAME = "handtrackinggpu.binarypb";
  private static final String INPUT_VIDEO_STREAM_NAME = "input_video";
  private static final String OUTPUT_VIDEO_STREAM_NAME = "output_video";
  private static final String OUTPUT_HAND_PRESENCE_STREAM_NAME = "hand_presence";
  private static final String OUTPUT_LANDMARKS_STREAM_NAME = "hand_landmarks";
  private static final CameraHelper.CameraFacing CAMERA_FACING = CameraHelper.CameraFacing.FRONT;

  // Flips the camera-preview frames vertically before sending them into FrameProcessor to be
  // processed in a MediaPipe graph, and flips the processed frames back when they are displayed.
  // This is needed because OpenGL represents images assuming the image origin is at the bottom-left
  // corner, whereas MediaPipe in general assumes the image origin is at top-left.
  private static final boolean FLIP_FRAMES_VERTICALLY = true;

  static {
    // Load all native libraries needed by the app.
    System.loadLibrary("mediapipe_jni");
    System.loadLibrary("opencv_java3");
  }

  // {@link SurfaceTexture} where the camera-preview frames can be accessed.
  private SurfaceTexture previewFrameTexture;
  // {@link SurfaceView} that displays the camera-preview frames processed by a MediaPipe graph.
  private SurfaceView previewDisplayView;

  // Creates and manages an {@link EGLContext}.
  private EglManager eglManager;
  // Sends camera-preview frames into a MediaPipe graph for processing, and displays the processed
  // frames onto a {@link Surface}.
  private FrameProcessor processor;
  // Converts the GL_TEXTURE_EXTERNAL_OES texture from Android camera into a regular texture to be
  // consumed by {@link FrameProcessor} and the underlying MediaPipe graph.
  private ExternalTextureConverter converter;

  // Handles camera access via the {@link CameraX} Jetpack support library.
  private CameraXPreviewHelper cameraHelper;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    previewDisplayView = new SurfaceView(this);
    setupPreviewDisplayView();

    // Initialize asset manager so that MediaPipe native libraries can access the app assets, e.g.,
    // binary graphs.
    AndroidAssetUtil.initializeNativeAssetManager(this);

    eglManager = new EglManager(null);
    processor =
        new FrameProcessor(
            this,
            eglManager.getNativeContext(),
            BINARY_GRAPH_NAME,
            INPUT_VIDEO_STREAM_NAME,
            OUTPUT_VIDEO_STREAM_NAME);
    processor.getVideoSurfaceOutput().setFlipY(FLIP_FRAMES_VERTICALLY);

    processor.addPacketCallback(
        OUTPUT_HAND_PRESENCE_STREAM_NAME,
        (packet) -> {
          Boolean handPresence = PacketGetter.getBool(packet);
          if (!handPresence) {
            Log.d(
                TAG,
                "[TS:" + packet.getTimestamp() + "] Hand presence is false, no hands detected.");
          }
        });

    processor.addPacketCallback(
        OUTPUT_LANDMARKS_STREAM_NAME,
        (packet) -> {
          byte[] landmarksRaw = PacketGetter.getProtoBytes(packet);
          try {
            NormalizedLandmarkList landmarks = NormalizedLandmarkList.parseFrom(landmarksRaw);
            if (landmarks == null) {
              Log.d(TAG, "[TS:" + packet.getTimestamp() + "] No hand landmarks.");
              return;
            }
            // Note: If hand_presence is false, these landmarks are useless.
            Log.d(
                TAG,
                "[TS:"
                    + packet.getTimestamp()
                    + "] #Landmarks for hand: "
                    + landmarks.getLandmarkCount());
            Log.d(TAG, getLandmarksDebugString(landmarks));
          } catch (InvalidProtocolBufferException e) {
            Log.e(TAG, "Couldn't Exception received - " + e);
            return;
          }
        });

    PermissionHelper.checkAndRequestCameraPermissions(this);
  }

  @Override
  protected void onResume() {
    super.onResume();
    converter = new ExternalTextureConverter(eglManager.getContext());
    converter.setFlipY(FLIP_FRAMES_VERTICALLY);
    converter.setConsumer(processor);
    if (PermissionHelper.cameraPermissionsGranted(this)) {
      startCamera();
    }
  }

  @Override
  protected void onPause() {
    super.onPause();
    converter.close();
  }

  @Override
  public void onRequestPermissionsResult(
      int requestCode, String[] permissions, int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    PermissionHelper.onRequestPermissionsResult(requestCode, permissions, grantResults);
  }

  private void setupPreviewDisplayView() {
    previewDisplayView.setVisibility(View.GONE);
    ViewGroup viewGroup = findViewById(R.id.preview_display_layout);
    viewGroup.addView(previewDisplayView);

    previewDisplayView
        .getHolder()
        .addCallback(
            new SurfaceHolder.Callback() {
              @Override
              public void surfaceCreated(SurfaceHolder holder) {
                processor.getVideoSurfaceOutput().setSurface(holder.getSurface());
              }

              @Override
              public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
                // (Re-)Compute the ideal size of the camera-preview display (the area that the
                // camera-preview frames get rendered onto, potentially with scaling and rotation)
                // based on the size of the SurfaceView that contains the display.
                Log.w(TAG,"surfaceChanged width:"+ width + " height:" + height);
                Size viewSize = new Size(width, height);
                Size displaySize = cameraHelper.computeDisplaySizeFromViewSize(viewSize);

                // Connect the converter to the camera-preview frames as its input (via
                // previewFrameTexture), and configure the output width and height as the computed
                // display size.
                converter.setSurfaceTextureAndAttachToGLContext(
                    previewFrameTexture, displaySize.getWidth(), displaySize.getHeight());
              }

              @Override
              public void surfaceDestroyed(SurfaceHolder holder) {
                processor.getVideoSurfaceOutput().setSurface(null);
              }
            });
  }

  private void startCamera() {
    cameraHelper = new CameraXPreviewHelper();
    cameraHelper.setOnCameraStartedListener(
        surfaceTexture -> {
          previewFrameTexture = surfaceTexture;
          // Make the display view visible to start showing the preview. This triggers the
          // SurfaceHolder.Callback added to (the holder of) previewDisplayView.
          previewDisplayView.setVisibility(View.VISIBLE);
        });
    cameraHelper.startCamera(this, CAMERA_FACING, /*surfaceTexture=*/ null);
  }

  private static String getLandmarksDebugString(NormalizedLandmarkList landmarks) {
    int landmarkIndex = 0;
    String landmarksString = "";
    for (NormalizedLandmark landmark : landmarks.getLandmarkList()) {
      landmarksString +=
          "\t\tLandmark["
              + landmarkIndex
              + "]: ("
              + landmark.getX()
              + ", "
              + landmark.getY()
              + ", "
              + landmark.getZ()
              + ")\n";
      ++landmarkIndex;
    }
    return landmarksString;
  }
}

Finally, I finished all the preparatory work to run, it will print the error log proposed in this article, resulting in the failure to run normally on multiple models of mobile phones.Thank you for your valuable time. I hope you can give me your opinions and solutions. Good luck

@DandyLorenz DandyLorenz changed the title MediaPipeException: not found: ValidatedGraphConfig Initialization failed. No registered object with name: FaceDetectionFrontGpu; Unable to find Calculator "FaceDetectionFrontGpu" No registered object with name: DetectionsToRenderDataCalculator; Unable to find Calculator "DetectionsToRenderDataCalculator" No registered object with name: AnnotationOverlayCalculator; Unable to find Calculator "AnnotationOverlayCalculator" build faceDetectionGpu.aar or handTrackingGpu.aar error: MediaPipeException: not found: ValidatedGraphConfig Initialization failed. No registered object with name: FaceDetectionFrontGpu; Unable to find Calculator "FaceDetectionFrontGpu" No registered object with name: DetectionsToRenderDataCalculator; Unable to find Calculator "DetectionsToRenderDataCalculator" No registered object with name: AnnotationOverlayCalculator; Unable to find Calculator "AnnotationOverlayCalculator" Dec 29, 2020
@liobsession
Copy link

I also encountered the same problem when compiling the latest version for android face detection gpu , how can I solve it?

@1549290123
Copy link

I have the same problem, what did we miss?

@DandyLorenz DandyLorenz changed the title build faceDetectionGpu.aar or handTrackingGpu.aar error: MediaPipeException: not found: ValidatedGraphConfig Initialization failed. No registered object with name: FaceDetectionFrontGpu; Unable to find Calculator "FaceDetectionFrontGpu" No registered object with name: DetectionsToRenderDataCalculator; Unable to find Calculator "DetectionsToRenderDataCalculator" No registered object with name: AnnotationOverlayCalculator; Unable to find Calculator "AnnotationOverlayCalculator" No registered calculator found.I build faceDetectionGpu.aar or handTrackingGpu.aar error,print: MediaPipeException: not found: ValidatedGraphConfig Initialization failed. No registered object with name: FaceDetectionFrontGpu; Unable to find Calculator "FaceDetectionFrontGpu" No registered object with name: DetectionsToRenderDataCalculator; Unable to find Calculator "DetectionsToRenderDataCalculator" No registered object with name: AnnotationOverlayCalculator; Unable to find Calculator "AnnotationOverlayCalculator" Dec 30, 2020
@DandyLorenz DandyLorenz changed the title No registered calculator found.I build faceDetectionGpu.aar or handTrackingGpu.aar error,print: MediaPipeException: not found: ValidatedGraphConfig Initialization failed. No registered object with name: FaceDetectionFrontGpu; Unable to find Calculator "FaceDetectionFrontGpu" No registered object with name: DetectionsToRenderDataCalculator; Unable to find Calculator "DetectionsToRenderDataCalculator" No registered object with name: AnnotationOverlayCalculator; Unable to find Calculator "AnnotationOverlayCalculator" not found: ValidatedGraphConfig Initialization failed.No registered calculator found. Jan 4, 2021
@DandyLorenz DandyLorenz changed the title not found: ValidatedGraphConfig Initialization failed.No registered calculator found. Not found: ValidatedGraphConfig Initialization failed.When I use hand tracking aar for Android,print:No registered calculator found. Jan 4, 2021
@DandyLorenz DandyLorenz changed the title Not found: ValidatedGraphConfig Initialization failed.When I use hand tracking aar for Android,print:No registered calculator found. Not found: ValidatedGraphConfig Initialization failed.When I use handtrackinggpu.aar for Android,print:No registered calculator found. Jan 4, 2021
@DandyLorenz DandyLorenz reopened this Jan 14, 2021
@DandyLorenz
Copy link
Author

Now I've solved the problem!

@rishabh063
Copy link

Can you Please Tell how ?

@bugmany
Copy link

bugmany commented Feb 5, 2021

@ DandyLorenz, I've got this problem, Could you give help?

@DandyLorenz
Copy link
Author

My question is from Android aar build my project,What is the reason for my problem?Because I imported the wrong resource package in Android stdio:Src --> jniLibs --> arm64-v8a or armeabi-v7a,I imported face recognition resources so file in hand tracking project。The root cause is that the .so file in the jnilibs folder will be overwritten my hand tracking aar file.So ,You can build AAR successfully and put it into use by strictly following my steps.

@bugmany
Copy link

bugmany commented Feb 5, 2021

ok, I re-check it, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants