mediapipe icon indicating copy to clipboard operation
mediapipe copied to clipboard

Mac M1 Tensorflow Set Up

Open mgebhard opened this issue 3 years ago • 33 comments

"ERROR: While resolving toolchains for target @org_tensorflow//tensorflow/tools/git:gen_git_source: No matching toolchains found for types @bazel_tools//tools/cpp:toolchain_type. Maybe --incompatible_use_cc_configure_from_rules_cc has been flipped and there is no default C++ toolchain added in the WORKSPACE file? See https://github.com/bazelbuild/bazel/issues/10134 for details and migration instructions. ERROR: Analysis of target '//mediapipe/examples/ios/facedetectioncpu:facedetectioncpu' failed; build aborted: No matching toolchains found for types @bazel_tools//tools/cpp:toolchain_type. Maybe --incompatible_use_cc_configure_from_rules_cc has been flipped and there is no default C++ toolchain added in the WORKSPACE file? See https://github.com/bazelbuild/bazel/issues/10134 for details and migration instructions."

I am trying to follow instructions here to set up tensorflow using the new mac m1 chip: https://github.com/apple/tensorflow_macos

However, I am still having no luck with initial set up for media pipe.

Have I written custom code: No OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Mac OS 11.0.1 Bazel version:nbazel 3.7.2-homebrew Xcode & Tulsi version (if issue is related to building in mobile dev enviroment): 12.3 Tusli 0.20210106.88 Exact steps to reproduce: ./build_ios_examples.sh -d out_dir --nostrip

mgebhard avatar Jan 18 '21 15:01 mgebhard

MediaPipe with its TensorFlow dependence needs Bazel to build everything from scratch. I don't think bazel already supports M1 yet: https://github.com/bazelbuild/bazel/issues/11628.

https://github.com/apple/tensorflow_macos requires the users to use https://github.com/apple/tensorflow_macos/releases/download/v0.1alpha1/tensorflow_macos-0.1alpha1.tar.gz, which is not the "official" version of tensorflow.

jiuqiant avatar Jan 19 '21 18:01 jiuqiant

It looks like the tensorflow team has added M1 support. https://github.com/tensorflow/tensorflow/issues/46178

Is there a workaround to not have to wait for bazel compatibility?

mgebhard avatar Jan 19 '21 18:01 mgebhard

I took a look at https://github.com/tensorflow/tensorflow/commit/e687cab61615a95b8aea79120c9f168d4cc30955. My conclusion is the mediapipe repo needs some config changes for supporting Apple Silicon. For example, the repo needs to add a config for "macos_arm64" config_setting like the one it has for macos_x86_64. Also, it needs to point to the latest TF version that supports Apple Silicon.

jiuqiant avatar Jan 20 '21 18:01 jiuqiant

Do you have an ETA when the repo will be updated with the config changes? This blocks any integration from the m1 chip

mgebhard avatar Jan 22 '21 19:01 mgebhard

Any update on M1 support?

mgebhard avatar Feb 09 '21 01:02 mgebhard

also have an error on m1

miholeus avatar Jun 06 '21 14:06 miholeus

Feels like barely anyone else has an M1 mac, has anyone got a fix for this?

ROBYER1 avatar Oct 27 '21 15:10 ROBYER1

I am on M1 and its failing to build still

rcoenen avatar Oct 28 '21 06:10 rcoenen

Yea, not yet I suppose, I cannot install nuget too as it requires x86_64 architecture, I just use windows for now and my friend works on intel macbook

gkiernozek avatar Oct 31 '21 18:10 gkiernozek

I confirmed that hand_tracking_cpu works on Mac mini (M1, 2020) (macOS Big Sur 11.6) with the following patch applied.

diff --git a/.bazelrc b/.bazelrc
index 37a0bc1..7d7e159 100644
--- a/.bazelrc
+++ b/.bazelrc
@@ -87,6 +87,11 @@ build:darwin_x86_64 --apple_platform_type=macos
 build:darwin_x86_64 --macos_minimum_os=10.12
 build:darwin_x86_64 --cpu=darwin_x86_64
 
+# May not be necessary
+build:darwin_arm64 --apple_platform_type=macos
+build:darwin_arm64 --macos_minimum_os=10.16
+build:darwin_arm64 --cpu=darwin_arm64
+
 # This bazelrc file is meant to be written by a setup script.
 try-import %workspace%/.configure.bazelrc
 
diff --git a/.bazelversion b/.bazelversion
index 0b2eb36..fae6e3d 100644
--- a/.bazelversion
+++ b/.bazelversion
@@ -1 +1 @@
-3.7.2
+4.2.1
diff --git a/WORKSPACE b/WORKSPACE
index c2aaca6..30afd92 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -200,7 +200,7 @@ new_local_repository(
 new_local_repository(
     name = "macos_opencv",
     build_file = "@//third_party:opencv_macos.BUILD",
-    path = "/usr/local/opt/opencv@3",
+    path = "/opt/homebrew/opt/opencv@3",
 )
 
 new_local_repository(
diff --git a/mediapipe/BUILD b/mediapipe/BUILD
index 1171ea6..72e4208 100644
--- a/mediapipe/BUILD
+++ b/mediapipe/BUILD
@@ -74,6 +74,7 @@ alias(
     name = "macos",
     actual = select({
         ":macos_i386": ":macos_i386",
+        ":macos_arm64": ":macos_arm64",
         ":macos_x86_64": ":macos_x86_64",
         "//conditions:default": ":macos_i386",  # Arbitrarily chosen from above.
     }),
@@ -110,6 +111,15 @@ config_setting(
     visibility = ["//visibility:public"],
 )
 
+config_setting(
+    name = "macos_arm64",
+    values = {
+        "apple_platform_type": "macos",
+        "cpu": "darwin_arm64",
+    },
+    visibility = ["//visibility:public"],
+)
+
 config_setting(
     name = "macos_x86_64",
     values = {

The exact command can be found here.

It seems that a similar patch is already submitted as a PR. https://github.com/google/mediapipe/pull/2591

homuler avatar Nov 18 '21 11:11 homuler

@homuler Thank you for the recommendations; I've made those changes and I'm still having issues. Additionally, the PR you linked has issues: It still references bazel 3.7.2. Additionally in your changes, I had to also change the reference to ffmpeg in WORKSPACE.

I installed the latest bazel (4.2.2) through brew, then updated .bazelversion to reflect that, but when I tried to run the helloworld, I ended up with:

"dyld[70906]: symbol not found in flat namespace '_CFRelease'"

Any further advice?

Snipeye avatar Dec 12 '21 02:12 Snipeye

It has been almost a year does anyone have a solution to this?

I followed the changes in https://github.com/google/mediapipe/pull/2591/files with slight differences in OpenCV and FFMPEG versions and still got build errors.

In file included from mediapipe/framework/formats/image_frame_opencv.cc:15:
In file included from ./mediapipe/framework/formats/image_frame_opencv.h:20:
./mediapipe/framework/port/opencv_core_inc.h:18:10: fatal error: 'opencv2/core/version.hpp' file not found
#include <opencv2/core/version.hpp>

I would prefer not to use a unity plugin.

mgebhard avatar Dec 27 '21 21:12 mgebhard

This doesn't solve the issue of running mediapipe on M1 metal, but you can get mediapipe to run on your M1 hardware by using rosetta, as described in this comment. (Read the rest of the comments before diving in. To solve the homebrew permissions problem in /usr/local you can refer to this SO answer)

daviddavid avatar Jan 01 '22 12:01 daviddavid

@homuler Thank you for the recommendations; I've made those changes and I'm still having issues. Additionally, the PR you linked has issues: It still references bazel 3.7.2. Additionally in your changes, I had to also change the reference to ffmpeg in WORKSPACE.

I installed the latest bazel (4.2.2) through brew, then updated .bazelversion to reflect that, but when I tried to run the helloworld, I ended up with:

"dyld[70906]: symbol not found in flat namespace '_CFRelease'"

Any further advice?

same problem here。 any solutions?

binpan0423 avatar Feb 15 '22 10:02 binpan0423

I wonder why they don't reflect any of this limitation on the installation page at the TensorFlow website. They just say this:

macOS 10.12.6 (Sierra) or later (no GPU support)

Which seems to contradict the actual status if I'm following. What do you think?

matanox avatar Mar 18 '22 09:03 matanox

related: #3277 (community M1 wheels)

justin-f-perez avatar May 17 '22 01:05 justin-f-perez

Hi @mgebhard , Apple M1 supports in latest release , could you check, verify and close this issue.

sureshdagooglecom avatar Jun 30 '22 07:06 sureshdagooglecom

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you.

google-ml-butler[bot] avatar Jul 07 '22 08:07 google-ml-butler[bot]

@sureshdagooglecom pip install mediapipe still gives

ERROR: Could not find a version that satisfies the requirement mediapipe (from versions: none)
ERROR: No matching distribution found for mediapipe

I am on Python 3.9.13 and pip 22.1.2.

anandijain avatar Jul 09 '22 16:07 anandijain

Closing as stale. Please reopen if you'd like to work on this further.

google-ml-butler[bot] avatar Jul 16 '22 17:07 google-ml-butler[bot]

Are you satisfied with the resolution of your issue? Yes No

google-ml-butler[bot] avatar Jul 16 '22 17:07 google-ml-butler[bot]

Hi @mgebhard , what is the error you are facing w.r.t above issue and please share the error logs.

sureshdagooglecom avatar Aug 04 '22 06:08 sureshdagooglecom

@sureshdagooglecom pip install mediapipe still gives

ERROR: Could not find a version that satisfies the requirement mediapipe (from versions: none)
ERROR: No matching distribution found for mediapipe

I am on Python 3.9.13 and pip 22.1.2.

Unfortunately, we still do not have native Python wheels. You can run Python under Rosetta.

schmidt-sebastian avatar Aug 10 '22 15:08 schmidt-sebastian

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you.

google-ml-butler[bot] avatar Aug 17 '22 16:08 google-ml-butler[bot]

thanks! any timeline or eta for when native wheels will be built?

anandijain avatar Aug 17 '22 17:08 anandijain

Unfortunately, we don't have an ETA for this at this point.

schmidt-sebastian avatar Aug 17 '22 18:08 schmidt-sebastian

@schmidt-sebastian Can you enumerate the tasks/gaps that you are aware of for this support to be completed?

drush avatar Aug 17 '22 18:08 drush

I don't think I can go into much detail here, but it is an infrastructure issue on our end.

schmidt-sebastian avatar Aug 17 '22 18:08 schmidt-sebastian

This patch seems to work https://github.com/cansik/mediapipe-silicon . Would it be possible to implement this so there can be a wheel for people to download without having to run through rosetta.

In the meanwhile for people wanting to install mediapipe I suggest installing one of the prebuilt binaries with pip install https://github.com/cansik/mediapipe-silicon/releases/tag/v0.8.10.1

For me pip install mediapipe_silicon-0.8.10.1-cp39-cp39-macosx_12_0_arm64.whl worked.

The-Real-Thisas avatar Aug 20 '22 11:08 The-Real-Thisas

Are you satisfied with the resolution of your issue? Yes No

google-ml-butler[bot] avatar Aug 24 '22 07:08 google-ml-butler[bot]