Kernel Crash when importing TensorFlow or cvlib on M1 MacBook

I had the common issue of kernel crashing when trying to import cvlib or TensorFlow while trying to complete the week1’s ungraded lab. on my M1 MacBook.

I tried most of the solutions posted here on the Discussion Forum of the course and the Discourse on DeepLearningAI’s platform. However, most of them did not work.

I was able to come up with a solution by mixing and trying what I found on the forum and online blog posts and want to share it with you down below in case you have the same issue.

Steps you have to take after cloning the github repo and changing your direcotry to where the lab for week 1 is located are as follows:

1- remove the two specific lines below from requirements.txt file of the lab folder. Since Tensorflow and OpenCV should be installed separately on your M1 Macbook

opencv-python-headless==4.5.3.56
tensorflow==2.7.0

2- Install Conda on your MacOS as you will need to install TensorFlow and OpenCV properly on your MacOS.

3- Follow the steps to install TensorFlow from https://caffeinedev.medium.com/how-to-install-tensorflow-on-m1-mac-8e9b91d93706

4- Follow the steps to install OpenCV from https://caffeinedev.medium.com/building-and-installing-opencv-on-m1-macbook-c4654b10c188

5- Once you have installed TensorFlow and OpenCV on your conda environment you can now proceed with installing requirements.txt

pip install -r requirements.txt

6- Now you can open Jupyter lab and resume your server.ipynb.

jupyter lab

About one hour trying this solution on my Mac M1 so I figured I’ll just turn my old PC on