TFOD on M1 Mac

Hey guys, Just got a brand new M1 MacBook and started all my developer tools. However, I'm stuck trying to setup the Tensorflow. Object Detection API. I'm having an issue copying and installing the 'setup.py' file as I keep getting dependency issues. Just for reference I'll leave a link to a guide that shows pretty much all the steps I'm taking (one I followed when I first started): https://github.com/nicknochnack/TFODCourse/blob/main/2.%20Training%20and%20Detection.ipynb.

Where I'm getting stuck is the 3rd part in section 1. I get a dependency conflicts from tensorflow-text (tf-models-official 2.6.0 depends on tensorflow-text>=2.5.0) and tensorflow-addons (tf-models-official 2.5.1 depends on tensorflow-addons). I looked up if anyone else was having the same problem and sure enough I found a couple issues on GitHub. Mainly, this one directly on the tensorflow/addons repo: https://github.com/tensorflow/addons/issues/2503.

Now, the solution that was proposed was following the steps in this PR (https://github.com/tensorflow/addons/pull/2504, linked on the bottom of the issue) which seemed to work for some of the members. However, when I go to bazel build I encounter two main errors. The first is a Symbol not found: _TF_AllocateOutput, Expected in: flat namespace error which, I believe leads to bazel not building correctly (which is the second error).

If anybody has any idea on how to get TFOD setup or fix any of these issue thanks in advance! Even some pointers or ideas are welcome as I'm kind of at a dead end for using TFOD natively on my Mac.

Commenting to say I'm having the same issue. If I set up an environment with tensorflow-macos and tensorflow-metal I can't install the object detection API. If I create an environment through Anaconda I can't install tf-macos or tf-metal, but I can install tensorflow and the object detection API but whenever I try to run python scripts I get a new hardware error regarding python. Beyond frustrating.

I have same issue. Did you guys happen to find the solution? Thanks

Please delete

Can confirm that this issue still exists (with TF version 2.7.0). GPU acceleration lacks of M1 GPU support, getting this message when trying to run a trained model on GPU:

NotFoundError: No registered 'AddN' OpKernel for 'GPU' devices compatible with node {{node StatefulPartitionedCall/MultiLevelMatMulCropAndResize/MultiLevelRoIAlign/ArithmeticOptimizer/AddOpsRewrite_add_8}}
(OpKernel was found, but attributes didn't match) Requested Attributes: N=3, T=DT_INT32, _XlaHasReferenceVars=false, _grappler_ArithmeticOptimizer_AddOpsRewriteStage=true, _device="/job:localhost/replica:0/task:0/device:GPU:0"
. Registered: device='XLA_CPU_JIT'; T in [DT_FLOAT, DT_DOUBLE, DT_INT32, DT_UINT8, DT_INT16, DT_INT8, DT_COMPLEX64, DT_INT64, DT_QINT8, DT_QUINT8, DT_QINT32, DT_BFLOAT16, DT_UINT16, DT_COMPLEX128, DT_HALF, DT_UINT32, DT_UINT64, DT_VARIANT]
device='GPU'; T in [DT_FLOAT]
device='CPU'; T in [DT_UINT64]
device='CPU'; T in [DT_INT64]
device='CPU'; T in [DT_UINT32]
device='CPU'; T in [DT_UINT16]
device='CPU'; T in [DT_INT16]
device='CPU'; T in [DT_UINT8]
device='CPU'; T in [DT_INT8]
device='CPU'; T in [DT_INT32]
device='CPU'; T in [DT_HALF]
device='CPU'; T in [DT_BFLOAT16]
device='CPU'; T in [DT_FLOAT]
device='CPU'; T in [DT_DOUBLE]
device='CPU'; T in [DT_COMPLEX64]
device='CPU'; T in [DT_COMPLEX128]
device='CPU'; T in [DT_VARIANT]
[[StatefulPartitionedCall/MultiLevelMatMulCropAndResize/MultiLevelRoIAlign/ArithmeticOptimizer/AddOpsRewrite_add_8]] [Op:__inference_restored_function_body_26361]

On CPU, everything works perfect. Seems that not all operations used in the F-RCNN model are implemented in tensorflow-metal. So training will also be impossible even if you are able to install TFOD API. I have no experience, if the SSD models affected as well.

Very frustrating.

I've been trying to get it to run all evening, unfortunately not successfully. As soon as someone has a solution, I would be grateful for help!

I got the TensorFlow object detection tutorial page (https://www.tensorflow.org/hub/tutorials/tf2_object_detection) running. I had successfully installed tensorflow-macos and tensor flow-metal before, so that I could do already the image classification task shown on the TensorFlow hub site, but object detection was not possible for me as the installation mentioned on TensorFlow hub did not work.

Initially I was struggling with the cell containing the installation of the object_detection-package, mainly because of missing packages or package conflicts. I mean this piece of code:

%%bash
sudo apt install -y protobuf-compiler
cd models/research/
protoc object_detection/protos/*.proto --python_out=.
cp object_detection/packages/tf2/setup.py .
python -m pip install .

The failure always occurred with the last line. I could overcome them with the following steps (as it was a longer trial and error I hope I don't miss any steps):

  1. The missing tensor flow-text package for the M1 I found in the following git hub repository: https://github.com/sun1638650145/Libraries-and-Extensions-for-TensorFlow-for-Apple-Silicon/releases

I downloaded the wheel and installed it with pip like mentioned there.

  1. I had to install tensorflow-io as well. The necessary steps I found here: https://stackoverflow.com/questions/70277737/cant-install-tensorflow-io-on-m1.

  2. I installed tf_slim as well manually

pip install tf_slim
  1. After that I was able to execute the last piece of the bash-command sequences shown above, but I replaced the

python -m pip install .

by

python -m pip install --force --no-dependencies .

Don't miss the dot at the end as it stands for the current directory where the bash commands operate.

As for the completeness here is the output of my pip list of my environment:

I hope this helps.

Thanks a lot for these instructions @Frank_L! Are you able to run the following test successfully?

python object_detection/builders/model_builder_tf2_test.py

For me, unfortunately this fails with:

ModuleNotFoundError: No module named 'official'.

TFOD on M1 Mac
 
 
Q