From d822573429d8cdecc40441caea51771b57a777a0 Mon Sep 17 00:00:00 2001 From: Oleksandr Chychkan Date: Mon, 31 Jan 2022 11:08:39 -0800 Subject: [PATCH 1/8] Add support for Apple M1 laptops --- requirements_3.9_arm64.txt | 14 ++++++++++++++ scripts/0_setup.sh | 33 +++++++++++++++++++++++++++++++-- 2 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 requirements_3.9_arm64.txt diff --git a/requirements_3.9_arm64.txt b/requirements_3.9_arm64.txt new file mode 100644 index 0000000..056f8c6 --- /dev/null +++ b/requirements_3.9_arm64.txt @@ -0,0 +1,14 @@ +numpy==1.21.4 +opencv-python==4.5.3.56 +numexpr==2.8.1 +h5py==3.1.0 +tqdm==4.62.3 +colorama==0.4.4 +cython==0.29.26 +ffmpeg-python==0.2.0 +Pillow==8.4.0 +scikit-image==0.19.0 +numpy==1.21.4 +scipy==1.7.3 +tensorflow-macos==2.7.0 +PyQt6==6.0.3 \ No newline at end of file diff --git a/scripts/0_setup.sh b/scripts/0_setup.sh index 1908632..a4e6f94 100755 --- a/scripts/0_setup.sh +++ b/scripts/0_setup.sh @@ -20,11 +20,40 @@ source .dfl/env/bin/activate version=$(python -V | cut -f 2 -d ' ' | cut -f 1,2 -d .) reqs_file='requirements.txt' +version_suffix='' if [[ ! -z "$version" && -f "requirements_$version.txt" ]]; then - reqs_file="requirements_$version.txt" + version_suffix="_$version" fi +architecture='' +if [[ ! -z "$(uname -a | grep -oE ' arm64$')" && -f "requirements${version_suffix}_arm64.txt" ]]; then + architecture='arm64' +fi + +architecture_suffix='' +if [[ ! -z "$architecture" ]]; then + architecture_suffix="_arm64" +fi + +reqs_file="requirements${version_suffix}${architecture_suffix}.txt" + echo "Using $reqs_file for $(python -V)" -pip install -r $reqs_file + +if [[ ! -z "$architecture" ]]; then + if [[ -z "$(brew ls --versions hdf5)" ]]; then + echo "ERROR: HDF5 needs to be installed to run DeepFaceLab on M1 chip." + echo "You can install it with 'brew install hdf5'. For more details, see https://formulae.brew.sh/formula/hdf5" + echo "Once it is installed, run ./scripts/0_setup.sh again" + exit 1 + fi + + cython_pkg="$(cat $reqs_file | grep -E 'cython==.+')" + pip --no-cache-dir install $cython_pkg + + h5py_pkg="$(cat $reqs_file | grep -E 'h5py==.+')" + HDF5_DIR="$(brew --prefix hdf5)" pip --no-cache-dir install --no-build-isolation $h5py_pkg +fi + +pip --no-cache-dir install -r $reqs_file echo "Done." -- 2.52.0 From 3f0958a1412741d28f3d7356c36e7488e12e8549 Mon Sep 17 00:00:00 2001 From: Oleksandr Chychkan Date: Fri, 4 Feb 2022 10:25:48 -0800 Subject: [PATCH 2/8] Pre-install numpy --- requirements_3.9_arm64.txt | 1 - scripts/0_setup.sh | 7 +++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/requirements_3.9_arm64.txt b/requirements_3.9_arm64.txt index 056f8c6..7711a9c 100644 --- a/requirements_3.9_arm64.txt +++ b/requirements_3.9_arm64.txt @@ -8,7 +8,6 @@ cython==0.29.26 ffmpeg-python==0.2.0 Pillow==8.4.0 scikit-image==0.19.0 -numpy==1.21.4 scipy==1.7.3 tensorflow-macos==2.7.0 PyQt6==6.0.3 \ No newline at end of file diff --git a/scripts/0_setup.sh b/scripts/0_setup.sh index a4e6f94..aa02e77 100755 --- a/scripts/0_setup.sh +++ b/scripts/0_setup.sh @@ -48,10 +48,13 @@ if [[ ! -z "$architecture" ]]; then fi cython_pkg="$(cat $reqs_file | grep -E 'cython==.+')" - pip --no-cache-dir install $cython_pkg + pip --no-cache-dir install "$cython_pkg" + + numpy_pkg="$(cat $reqs_file | grep -E 'numpy==.+')" + pip install "$numpy_pkg" h5py_pkg="$(cat $reqs_file | grep -E 'h5py==.+')" - HDF5_DIR="$(brew --prefix hdf5)" pip --no-cache-dir install --no-build-isolation $h5py_pkg + HDF5_DIR="$(brew --prefix hdf5)" pip --no-cache-dir install --no-build-isolation "$h5py_pkg" fi pip --no-cache-dir install -r $reqs_file -- 2.52.0 From 07869626bf41c3c29047b6e86ec82916029d09ae Mon Sep 17 00:00:00 2001 From: Oleksandr Chychkan Date: Fri, 4 Feb 2022 10:29:06 -0800 Subject: [PATCH 3/8] Use forked DeepFaceLab with minor fixes --- scripts/0_setup.sh | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/scripts/0_setup.sh b/scripts/0_setup.sh index aa02e77..ee766fa 100755 --- a/scripts/0_setup.sh +++ b/scripts/0_setup.sh @@ -6,9 +6,18 @@ set -e mkdir -p .dfl mkdir -p workspace +architecture='' +if [[ ! -z "$(uname -a | grep -oE ' arm64$')" ]]; then + architecture='arm64' +fi + if [ ! -d .dfl/DeepFaceLab ]; then echo "Cloning DeepFaceLab" - git clone --depth 1 "https://github.com/iperov/DeepFaceLab.git" .dfl/DeepFaceLab + git clone --depth 1 "https://github.com/chychkan/DeepFaceLab.git" .dfl/DeepFaceLab + + if [ "$architecture" == "arm64" ]; then + git checkout support-arm64 + fi fi if [ ! -d .dfl/env ]; then @@ -25,13 +34,8 @@ if [[ ! -z "$version" && -f "requirements_$version.txt" ]]; then version_suffix="_$version" fi -architecture='' -if [[ ! -z "$(uname -a | grep -oE ' arm64$')" && -f "requirements${version_suffix}_arm64.txt" ]]; then - architecture='arm64' -fi - architecture_suffix='' -if [[ ! -z "$architecture" ]]; then +if [ "$architecture" == "arm64" && -f "requirements${version_suffix}_arm64.txt" ]; then architecture_suffix="_arm64" fi -- 2.52.0 From 7106881627a496237aa2b8ce95e738658b2183fb Mon Sep 17 00:00:00 2001 From: Oleksandr Chychkan Date: Fri, 4 Feb 2022 10:44:33 -0800 Subject: [PATCH 4/8] Use --no-single-branch when cloning DFL --- scripts/0_setup.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/0_setup.sh b/scripts/0_setup.sh index ee766fa..7916ad4 100755 --- a/scripts/0_setup.sh +++ b/scripts/0_setup.sh @@ -13,10 +13,10 @@ fi if [ ! -d .dfl/DeepFaceLab ]; then echo "Cloning DeepFaceLab" - git clone --depth 1 "https://github.com/chychkan/DeepFaceLab.git" .dfl/DeepFaceLab + git clone --no-single-branch --depth 1 "https://github.com/chychkan/DeepFaceLab.git" .dfl/DeepFaceLab if [ "$architecture" == "arm64" ]; then - git checkout support-arm64 + (cd .dfl/DeepFaceLab; git checkout support-arm64) fi fi @@ -35,7 +35,7 @@ if [[ ! -z "$version" && -f "requirements_$version.txt" ]]; then fi architecture_suffix='' -if [ "$architecture" == "arm64" && -f "requirements${version_suffix}_arm64.txt" ]; then +if [ "$architecture" == "arm64" ] && [ -f "requirements${version_suffix}_arm64.txt" ]; then architecture_suffix="_arm64" fi -- 2.52.0 From d0ffbec9a49a90db2d51f9bfe1131faed0dd4933 Mon Sep 17 00:00:00 2001 From: Oleksandr Chychkan Date: Fri, 4 Feb 2022 11:03:40 -0800 Subject: [PATCH 5/8] Minor improvements --- scripts/0_setup.sh | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/scripts/0_setup.sh b/scripts/0_setup.sh index 7916ad4..22f20c3 100755 --- a/scripts/0_setup.sh +++ b/scripts/0_setup.sh @@ -6,16 +6,17 @@ set -e mkdir -p .dfl mkdir -p workspace -architecture='' -if [[ ! -z "$(uname -a | grep -oE ' arm64$')" ]]; then - architecture='arm64' -fi +is_arm64() { + [ "$(uname -m)" == "arm64" ] +} + +[ is_arm64 ] && echo "Running on Apple M1 chip" if [ ! -d .dfl/DeepFaceLab ]; then echo "Cloning DeepFaceLab" git clone --no-single-branch --depth 1 "https://github.com/chychkan/DeepFaceLab.git" .dfl/DeepFaceLab - if [ "$architecture" == "arm64" ]; then + if [ is_arm64 ]; then (cd .dfl/DeepFaceLab; git checkout support-arm64) fi fi @@ -26,6 +27,8 @@ fi source .dfl/env/bin/activate +python -m pip install --upgrade pip + version=$(python -V | cut -f 2 -d ' ' | cut -f 1,2 -d .) reqs_file='requirements.txt' @@ -35,7 +38,7 @@ if [[ ! -z "$version" && -f "requirements_$version.txt" ]]; then fi architecture_suffix='' -if [ "$architecture" == "arm64" ] && [ -f "requirements${version_suffix}_arm64.txt" ]; then +if [ is_arm64 ] && [ -f "requirements${version_suffix}_arm64.txt" ]; then architecture_suffix="_arm64" fi @@ -43,7 +46,7 @@ reqs_file="requirements${version_suffix}${architecture_suffix}.txt" echo "Using $reqs_file for $(python -V)" -if [[ ! -z "$architecture" ]]; then +if [ is_arm64 ]; then if [[ -z "$(brew ls --versions hdf5)" ]]; then echo "ERROR: HDF5 needs to be installed to run DeepFaceLab on M1 chip." echo "You can install it with 'brew install hdf5'. For more details, see https://formulae.brew.sh/formula/hdf5" -- 2.52.0 From e6a8b05e4cf239ed2681e8eb5392631d48bbf514 Mon Sep 17 00:00:00 2001 From: Oleksandr Chychkan Date: Fri, 4 Feb 2022 13:03:12 -0800 Subject: [PATCH 6/8] Minor fixes to 0_setup.sh --- scripts/0_setup.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/0_setup.sh b/scripts/0_setup.sh index 22f20c3..54b5d31 100755 --- a/scripts/0_setup.sh +++ b/scripts/0_setup.sh @@ -10,13 +10,13 @@ is_arm64() { [ "$(uname -m)" == "arm64" ] } -[ is_arm64 ] && echo "Running on Apple M1 chip" +is_arm64 && echo "Running on Apple M1 chip" if [ ! -d .dfl/DeepFaceLab ]; then echo "Cloning DeepFaceLab" git clone --no-single-branch --depth 1 "https://github.com/chychkan/DeepFaceLab.git" .dfl/DeepFaceLab - if [ is_arm64 ]; then + if is_arm64; then (cd .dfl/DeepFaceLab; git checkout support-arm64) fi fi @@ -38,7 +38,7 @@ if [[ ! -z "$version" && -f "requirements_$version.txt" ]]; then fi architecture_suffix='' -if [ is_arm64 ] && [ -f "requirements${version_suffix}_arm64.txt" ]; then +if is_arm64 && [ -f "requirements${version_suffix}_arm64.txt" ]; then architecture_suffix="_arm64" fi @@ -46,7 +46,7 @@ reqs_file="requirements${version_suffix}${architecture_suffix}.txt" echo "Using $reqs_file for $(python -V)" -if [ is_arm64 ]; then +if is_arm64; then if [[ -z "$(brew ls --versions hdf5)" ]]; then echo "ERROR: HDF5 needs to be installed to run DeepFaceLab on M1 chip." echo "You can install it with 'brew install hdf5'. For more details, see https://formulae.brew.sh/formula/hdf5" -- 2.52.0 From 138349570c2d475144eea0f0071172dca451f291 Mon Sep 17 00:00:00 2001 From: Oleksandr Chychkan Date: Tue, 22 Feb 2022 19:21:50 -0800 Subject: [PATCH 7/8] Update versions --- requirements_3.9_arm64.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/requirements_3.9_arm64.txt b/requirements_3.9_arm64.txt index 7711a9c..c63501c 100644 --- a/requirements_3.9_arm64.txt +++ b/requirements_3.9_arm64.txt @@ -1,5 +1,5 @@ numpy==1.21.4 -opencv-python==4.5.3.56 +opencv-python==4.5.5.62 numexpr==2.8.1 h5py==3.1.0 tqdm==4.62.3 @@ -7,7 +7,7 @@ colorama==0.4.4 cython==0.29.26 ffmpeg-python==0.2.0 Pillow==8.4.0 -scikit-image==0.19.0 -scipy==1.7.3 +scikit-image==0.19.1 +scipy==1.8.0 tensorflow-macos==2.7.0 -PyQt6==6.0.3 \ No newline at end of file +PyQt6==6.2.3 -- 2.52.0 From 1878127f7bea12021ff2e86fb780927b761eb881 Mon Sep 17 00:00:00 2001 From: Oleksandr Chychkan Date: Tue, 22 Feb 2022 19:33:03 -0800 Subject: [PATCH 8/8] Update README --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index e6a94b7..bfde164 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,10 @@ This project provides scripts inspired by [DeepFaceLab_Linux](https://github.com You'll need `git`, `ffmpeg`, `python3` and python module `virtualenv` available to be able to execute these scripts. The scripts will create a virtual env sandbox and will install all necessary dependencies there, so your main installation of `python3` will be left intact. +## NOTE: Apple M1 chip + +Currently there's limited support for Apple M1 laptops. You can do model training, but the XSeg editor currently does not work (the DeepFaceLab codebase is not compatible with PyQt6). + ## Setup **Tools** @@ -14,6 +18,9 @@ Make sure you have installed: - [Python 3](https://www.python.org/) (check with `python3 --version`) - [Virtualenv](https://github.com/pypa/virtualenv) (check with `virtualenv --version`) +For **Apple M1** laptops you also need [hdf5](https://formulae.brew.sh/formula/hdf5) lib installed. +Check if you have it with `brew ls --versions hdf5`. Install it with `brew install hdf5`. + **Clone and setup** 1. Clone this repository (`git clone https://github.com/chychkan/DeepFaceLab_MacOS.git`) -- 2.52.0