訂閱
糾錯(cuò)
加入自媒體

如何在M1 Macbook上配置OpenCV等機(jī)器學(xué)習(xí)環(huán)境?

設(shè)置Xcode

打開終端并執(zhí)行

sudo xcode-select --install

安裝HomeBrew(原生Apple Silicon M1)

打開終端,逐個(gè)寫入

這將為M1芯片安裝最新的Brew/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
echo “export PATH=/opt/homebrew/bin:$PATH” >> ~/.zshrc
//Restart The Terminal

brew install gcc

brew install cmake

brew install wget

安裝Miniforge,設(shè)置Conda環(huán)境點(diǎn)擊下面的鏈接下載(Apple Silicon)版本https://github.com/conda-forge/miniforge

打開終端并執(zhí)行以下操作// If the Downloaded File Stored in Download
cd Downloads
bash Miniforge3-MacOSX-arm64.sh
//After Installation Completes Restart Terminal
//Creating Conda Environment named ml You can use any name in place           of "ml"
conda create --name ml
conda install -y python==3.8.6
conda install -y pandas matplotlib scikit-learn jupyterlab
安裝Tensorflow單擊下面的鏈接并下載文件https://github.com/apple/tensorflow_macos/releasesAm在2021年3月3日為M1使用最新的TF alpha 2版本。

//if Download Directory is Downloads
cd Downloads
tar xvf tensorflow_macos-0.1alpha2.tar.gz
cd tensorflow_macos/arm64
//Dont Forget To Activate Conda Environment
conda activate ml
// Install specific pip version and some other base packages
pip install --force pip==20.2.4 wheel setuptools cached-property six
// Install all the packages provided by Apple but TensorFlow
pip install --upgrade --no-dependencies --force numpy-1.18.5-cp38-cp38-macosx_11_0_arm64.whl grpcio-1.33.2-cp38-cp38-macosx_11_0_arm64.whl h5py-2.10.0-cp38-cp38-macosx_11_0_arm64.whl tensorflow_addons_macos-0.1a2-cp38-cp38-macosx_11_0_arm64.whl
// Install additional packages
pip install absl-py astunparse flatbuffers gast google_pasta keras_preprocessing opt_einsum protobuf tensorflow_estimator termcolor typing_extensions wrapt wheel tensorboard typeguard
// Install TensorFlow
pip install --upgrade --force --no-dependencies tensorflow_macos-0.1a2-cp38-cp38-macosx_11_0_arm64.whl
安裝額外的包pip install matplotlib
conda install -c conda-forge scikit-learn
pip install keras
pip install notebook
編譯和安裝OpenCV//I Suggest To Do all this Inside miniforge3 dir for that
//  cd miniforge3
wget -O opencv.zip https://github.com/opencv/opencv/archive/4.5.0.zip
wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/4.5.0.zip
unzip opencv.zip
unzip opencv_contrib.zip
cd opencv-4.5.0
mkdir build && cd build
//Here Take Care Of Paths of OPENCV_EXTRA_M(jìn)ODULES_PATH and  
//    PYTHON3_EXECUTABLE If you're Beginner watch the YouTube  video
//And If Inside miniforge3 just place your <username>.
cmake
-DCMAKE_SYSTEM_PROCESSOR=arm64
-DCMAKE_OSX_ARCHITECTURES=arm64
-DWITH_OPENJPEG=OFF
-DWITH_IPP=OFF
-D CMAKE_BUILD_TYPE=RELEASE
-D CMAKE_INSTALL_PREFIX=/usr/local
-D OPENCV_EXTRA_M(jìn)ODULES_PATH=/Users/<username>/miniforge3/opencv_contrib-4.5.0/modules
-D PYTHON3_EXECUTABLE=/Users/<username>/miniforge3/envs/ml/bin/python3
-D BUILD_opencv_python2=OFF
-D BUILD_opencv_python3=ON
-D INSTALL_PYTHON_EXAMPLES=ON
-D INSTALL_C_EXAMPLES=OFF
-D OPENCV_ENABLE_NONFREE=ON
-D BUILD_EXAMPLES=ON ..
make -j8
//"8" is the number of cores To be used(This Step Takes Time)
sudo make install
//Linking OpenCV To Conda Environment
mdfind cv2.cpython
//From the output Copy the Path similar to the below one
"/usr/local/lib/python3.8/site-packages/cv2/python-3.8/cv2.cpython-38-darwin.so cv2.so"
cd
cd miniforge3/envs/dev/lib/python3.8/site-packages
ln -s PasteYourCopiedPathHere

聲明: 本文由入駐維科號的作者撰寫,觀點(diǎn)僅代表作者本人,不代表OFweek立場。如有侵權(quán)或其他問題,請聯(lián)系舉報(bào)。

發(fā)表評論

0條評論,0人參與

請輸入評論內(nèi)容...

請輸入評論/評論長度6~500個(gè)字

您提交的評論過于頻繁,請輸入驗(yàn)證碼繼續(xù)

  • 看不清,點(diǎn)擊換一張  刷新

暫無評論

暫無評論

人工智能 獵頭職位 更多
掃碼關(guān)注公眾號
OFweek人工智能網(wǎng)
獲取更多精彩內(nèi)容
文章糾錯(cuò)
x
*文字標(biāo)題:
*糾錯(cuò)內(nèi)容:
聯(lián)系郵箱:
*驗(yàn) 證 碼:

粵公網(wǎng)安備 44030502002758號