Installing Detectron2 natively for Mac M1 Pro / Apple silicon
1 min readDec 21, 2021
This tutorial is for m1 pro (tested on 10-core 16GB M1 Pro, 16" macbook pro), Mac OSX version =12.0.1 and pytorch=1.10.
- Install Pytorch for m1 Mac.
NOTE: Do not install torchvision, as an updated torchvision binary is not provided for m1. The following works for me:
# Install brew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"# Install conda
brew install miniforge
conda init zsh
# Restart your terminal # Create a new environment
conda create --name torch10 python=3.8conda activate torch10# Install pytorch. Note that we do not install torchvision here.
conda install -c pytorch pytorch
For more details on pytorch installation, see these instructions.
2. Install dependencies
brew install ffmpeg pkg-config
conda install jpeg libpng
pip install opencv-python
2. Install torchvision from source
MACOSX_DEPLOYMENT_TARGET=12.0 CC=clang CXX=clang++ pip install git+https://github.com/pytorch/vision@v0.11.2
Here we install torchvision v0.11.2, but make sure to change this if you use a different version of pytorch. An overview is given here.
3. Install AV and grpcio
export GRPC_PYTHON_BUILD_SYSTEM_ZLIB=1
export GRPC_PYTHON_BUILD_SYSTEM_OPENSSL=1
pip install av grpcio
4. Install detectron2
pip install git+https://github.com/facebookresearch/detectron2@main