diff --git a/pkgs/development/python-modules/deepface/default.nix b/pkgs/development/python-modules/deepface/default.nix new file mode 100644 index 0000000000000..6565d98cdf75e --- /dev/null +++ b/pkgs/development/python-modules/deepface/default.nix @@ -0,0 +1,80 @@ +{ + lib, + buildPythonPackage, + fetchFromGitHub, + fire, + flask, + flask-cors, + gdown, + gunicorn, + mtcnn, + numpy, + opencv4, + pandas, + pillow, + pythonOlder, + requests, + retinaface, + setuptools, + tensorflow, + tqdm, +}: + +buildPythonPackage rec { + pname = "deepface"; + version = "0.0.92"; + pyproject = true; + + disabled = pythonOlder "3.7"; + + src = fetchFromGitHub { + owner = "serengil"; + repo = "deepface"; + rev = "refs/tags/v${version}"; + hash = "sha256-Vjm8lfpGyJ7/1CUwIvxXxHqwmv0+iKewYV3vE08gpPQ="; + }; + + postPatch = '' + # prevent collisions + substituteInPlace setup.py \ + --replace-fail "data_files=[(\"\", [\"README.md\", \"requirements.txt\", \"package_info.json\"])]," "" \ + --replace-fail "install_requires=requirements," "" + + substituteInPlace deepface/detectors/OpenCv.py \ + --replace-fail "opencv_home = cv2.__file__" "opencv_home = os.readlink(cv2.__file__)" \ + --replace-fail "folders = opencv_home.split(os.path.sep)[0:-1]" "folders = opencv_home.split(os.path.sep)[0:-4]" \ + --replace-fail "return path + \"/data/\"" "return path + \"/share/opencv4/haarcascades/\"" + ''; + + build-system = [ setuptools ]; + + dependencies = [ + fire + flask + flask-cors + gdown + gunicorn + mtcnn + numpy + opencv4 + pandas + pillow + requests + retinaface + tensorflow + tqdm + ]; + + # requires internet connection + doCheck = false; + + pythonImportsCheck = [ "deepface" ]; + + meta = { + description = "Lightweight Face Recognition and Facial Attribute Analysis (Age, Gender, Emotion and Race) Library for Python"; + homepage = "https://github.com/serengil/deepface"; + changelog = "https://github.com/serengil/deepface/releases/tag/v${version}"; + license = lib.licenses.mit; + maintainers = with lib.maintainers; [ derdennisop ]; + }; +} diff --git a/pkgs/development/python-modules/mtcnn/default.nix b/pkgs/development/python-modules/mtcnn/default.nix new file mode 100644 index 0000000000000..1c25eeab5e1f6 --- /dev/null +++ b/pkgs/development/python-modules/mtcnn/default.nix @@ -0,0 +1,53 @@ +{ + lib, + buildPythonPackage, + fetchFromGitHub, + opencv4, + pytestCheckHook, + pythonOlder, + setuptools, + tensorflow, +}: + +buildPythonPackage { + pname = "mtcnn"; + version = "0.1.1"; + pyproject = true; + + disabled = pythonOlder "3.7"; + + src = fetchFromGitHub { + owner = "ipazc"; + repo = "mtcnn"; + # No tags / releases; using commit: https://github.com/ipazc/mtcnn/commit/3208d443a8f01d317c65d7c97a03bc0a6143c41d + rev = "3208d443a8f01d317c65d7c97a03bc0a6143c41d"; + hash = "sha256-GXUrLJ5XD6V2hT/gjyYSuh/CMMw2xIXKBsYFvQmbLYs="; + }; + + postPatch = '' + substituteInPlace setup.py \ + --replace-fail "setup, setuptools" "setup, find_packages"\ + --replace-fail "setuptools.find_packages" "find_packages"\ + --replace-fail "opencv-python>=4.1.0" ""\ + --replace-fail "keras>=2.0.0" ""\ + --replace-fail "tests_require=['nose']," "" + ''; + + build-system = [ setuptools ]; + + dependencies = [ + opencv4 + tensorflow + ]; + + pythonImportsCheck = [ "mtcnn" ]; + + nativeCheckInputs = [ pytestCheckHook ]; + + meta = { + description = "MTCNN face detection implementation for TensorFlow"; + homepage = "https://github.com/ipazc/mtcnn"; + license = lib.licenses.mit; + maintainers = with lib.maintainers; [ derdennisop ]; + }; +} diff --git a/pkgs/development/python-modules/retinaface/default.nix b/pkgs/development/python-modules/retinaface/default.nix new file mode 100644 index 0000000000000..f727d3f31158c --- /dev/null +++ b/pkgs/development/python-modules/retinaface/default.nix @@ -0,0 +1,64 @@ +{ + lib, + buildPythonPackage, + fetchFromGitHub, + gdown, + numpy, + opencv4, + pillow, + pytestCheckHook, + pythonOlder, + setuptools, + tensorflow, +}: + +buildPythonPackage rec { + pname = "retinaface"; + version = "0.0.17"; + pyproject = true; + + disabled = pythonOlder "3.7"; + + src = fetchFromGitHub { + owner = "serengil"; + repo = "retinaface"; + rev = "refs/tags/v${version}"; + hash = "sha256-0s1CSGlK2bF1F2V/IuG2ZqD7CkNfHGvp1M5C3zDnuKs="; + }; + + postPatch = '' + # prevent collisions + substituteInPlace setup.py \ + --replace-fail "data_files=[(\"\", [\"README.md\", \"requirements.txt\", \"package_info.json\"])]," "" \ + --replace-fail "install_requires=requirements," "" + ''; + + # requires internet connection + disabledTestPaths = [ + "tests/test_actions.py" + "tests/test_align_first.py" + "tests/test_expand_face_area.py" + ]; + + build-system = [ setuptools ]; + + dependencies = [ + gdown + numpy + opencv4 + pillow + tensorflow + ]; + + nativeCheckInputs = [ pytestCheckHook ]; + + pythonImportsCheck = [ "retinaface" ]; + + meta = { + description = "Deep Face Detection Library for Python"; + homepage = "https://github.com/serengil/retinaface"; + changelog = "https://github.com/serengil/retinaface/releases/tag/v${version}"; + license = lib.licenses.mit; + maintainers = with lib.maintainers; [ derdennisop ]; + }; +} diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix index 7ec548731554d..d454a36446990 100644 --- a/pkgs/top-level/python-packages.nix +++ b/pkgs/top-level/python-packages.nix @@ -3034,6 +3034,8 @@ self: super: with self; { deepdish = callPackage ../development/python-modules/deepdish { }; + deepface = callPackage ../development/python-modules/deepface { }; + deepl = callPackage ../development/python-modules/deepl { }; deepmerge = callPackage ../development/python-modules/deepmerge { }; @@ -8248,6 +8250,8 @@ self: super: with self; { msrest = callPackage ../development/python-modules/msrest { }; + mtcnn = callPackage ../development/python-modules/mtcnn { }; + mt-940 = callPackage ../development/python-modules/mt-940 { }; mullvad-api = callPackage ../development/python-modules/mullvad-api { }; @@ -13627,6 +13631,8 @@ self: super: with self; { rethinkdb = callPackage ../development/python-modules/rethinkdb { }; + retinaface = callPackage ../development/python-modules/retinaface { }; + retry = callPackage ../development/python-modules/retry { }; retry-decorator = callPackage ../development/python-modules/retry-decorator { };