From 7cbfd936a29d903f3e7b3bbd3ced3305c3d60684 Mon Sep 17 00:00:00 2001 From: kiri Date: Sat, 23 Mar 2024 00:15:03 +0900 Subject: [PATCH 1/2] - Update dependencies for Python 3.10+, drop 3.6-3.7 support - add TensorFlow for Windows/Mac --- README.md | 5 +++-- eff_word_net/__init__.py | 4 +++- eff_word_net/audio_processing.py | 7 ++++-- requirements.txt | 9 ++++---- setup.py | 38 ++++++++++++++++++-------------- 5 files changed, 38 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index e3dfb75..bcf56b1 100755 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # EfficientWord-Net -![Versions : 3.6 ,3.7,3.8,3.9](https://camo.githubusercontent.com/a7b5b417de938c1faf3602c7f48f26fde8761a977be85390fd6c0d191e210ba8/68747470733a2f2f696d672e736869656c64732e696f2f707970692f707976657273696f6e732f74656e736f72666c6f772e7376673f7374796c653d706c6173746963) +![Versions : 3.8, 3.9, 3.10, 3.11, 3.12](https://camo.githubusercontent.com/a7b5b417de938c1faf3602c7f48f26fde8761a977be85390fd6c0d191e210ba8/68747470733a2f2f696d672e736869656c64732e696f2f707970692f707976657273696f6e732f74656e736f72666c6f772e7376673f7374796c653d706c6173746963) ## Hotword detection based on few-shot learning @@ -25,7 +25,7 @@ Here are the links: https://drive.google.com/file/d/1f6dp72D9WxErXvaZP6KIBLv4-eK ## Python Version Requirements This Library works between python versions: - `3.6 to 3.9` + `3.8 to 3.12`
## Dependencies Installation @@ -37,6 +37,7 @@ Before running the pip installation command for the library, few dependencies ne Mac OS M* and Raspberry Pi users might have to compile these dependecies. ***tflite*** package cannot be listed in requirements.txt hence will be automatically installed when the package is initialized in the system. +On Windows and Mac, use tensorflow instead. ***librosa*** package is not required for inference only cases , however when generate_reference is called , will be automatically installed. diff --git a/eff_word_net/__init__.py b/eff_word_net/__init__.py index 74d903c..90de772 100755 --- a/eff_word_net/__init__.py +++ b/eff_word_net/__init__.py @@ -3,9 +3,11 @@ """ import os +import sys RATE=16000 samples_loc = os.path.join(os.path.dirname(os.path.realpath(__file__)),"sample_refs") from eff_word_net.package_installation_scripts import check_install_tflite -check_install_tflite() +if sys.platform=="linux": + check_install_tflite() \ No newline at end of file diff --git a/eff_word_net/audio_processing.py b/eff_word_net/audio_processing.py index eaa2bc6..06fad90 100755 --- a/eff_word_net/audio_processing.py +++ b/eff_word_net/audio_processing.py @@ -1,5 +1,8 @@ -import glob -import tflite_runtime.interpreter as tflite +import sys +if sys.platform=="linux": + import tflite_runtime.interpreter as tflite +else: + from tensorflow import lite as tflite import os import numpy as np import random diff --git a/requirements.txt b/requirements.txt index ea9b218..264ff5b 100755 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ -numpy==1.24.0 -onnxruntime==1.15.1 -PyAudio==0.2.13 -requests==2.26.0 \ No newline at end of file +numpy>=1.22.0 +onnxruntime>=1.14.1 +PyAudio>=0.2.13 +requests>=2.26.0 +tensorflow>=2.13.0; sys_platform != 'linux' \ No newline at end of file diff --git a/setup.py b/setup.py index e37018d..4c10418 100755 --- a/setup.py +++ b/setup.py @@ -1,22 +1,28 @@ -from setuptools import setup -from glob import glob +from setuptools import setup, find_packages + +with open("README.md", "r", encoding="utf-8") as fh: + long_description = fh.read() + +with open("requirements.txt", "r", encoding="utf-8") as fr: + requirements = fr.read().splitlines() setup( - name = 'EfficientWord-Net', - version = '1.0.2', - description = 'Few Shot Learning based Hotword Detection Engine', - long_description = open("./README.md",'r').read(), - long_description_content_type = 'text/markdown', - url = 'https://github.com/Ant-Brain/EfficientWord', - #py_modules = ['efficientword'], - packages = ['eff_word_net'], - install_requires = open("./requirements.txt",'r').read().split("\n"), - classifiers = [ - 'Programming Language :: Python :: 3.6', - 'Programming Language :: Python :: 3.7', + name='EfficientWord-Net', + version='1.1.0', + description='Few Shot Learning based Hotword Detection Engine', + long_description=long_description, + long_description_content_type='text/markdown', + url='https://github.com/Ant-Brain/EfficientWord', + packages=find_packages(), + install_requires=requirements, + classifiers=[ + 'License :: OSI Approved :: Apache Software License', 'Programming Language :: Python :: 3.8', 'Programming Language :: Python :: 3.9', + 'Programming Language :: Python :: 3.10', + 'Programming Language :: Python :: 3.11', + 'Programming Language :: Python :: 3.12', ], + python_requires='>=3.8', include_package_data=True, -) - +) \ No newline at end of file From 83abd142448fb0d22ed534b33e0dcf59228fae3b Mon Sep 17 00:00:00 2001 From: kiri Date: Sat, 18 May 2024 17:10:15 +0900 Subject: [PATCH 2/2] Change TensorFlow install condition to check for ARM CPU instead of Linux OS --- eff_word_net/__init__.py | 9 +++++---- eff_word_net/audio_processing.py | 5 +++-- eff_word_net/package_installation_scripts.py | 14 ++++++++++++++ requirements.txt | 3 +-- setup.py | 20 +++++++++++++++++++- 5 files changed, 42 insertions(+), 9 deletions(-) diff --git a/eff_word_net/__init__.py b/eff_word_net/__init__.py index 90de772..684f06e 100755 --- a/eff_word_net/__init__.py +++ b/eff_word_net/__init__.py @@ -3,11 +3,12 @@ """ import os -import sys +from eff_word_net.package_installation_scripts import is_arm_cpu + + RATE=16000 samples_loc = os.path.join(os.path.dirname(os.path.realpath(__file__)),"sample_refs") -from eff_word_net.package_installation_scripts import check_install_tflite - -if sys.platform=="linux": +if is_arm_cpu(): + from eff_word_net.package_installation_scripts import check_install_tflite check_install_tflite() \ No newline at end of file diff --git a/eff_word_net/audio_processing.py b/eff_word_net/audio_processing.py index 06fad90..a242b15 100755 --- a/eff_word_net/audio_processing.py +++ b/eff_word_net/audio_processing.py @@ -1,5 +1,6 @@ -import sys -if sys.platform=="linux": +from eff_word_net.package_installation_scripts import is_arm_cpu + +if is_arm_cpu(): import tflite_runtime.interpreter as tflite else: from tensorflow import lite as tflite diff --git a/eff_word_net/package_installation_scripts.py b/eff_word_net/package_installation_scripts.py index 17fe617..f7b2a7d 100755 --- a/eff_word_net/package_installation_scripts.py +++ b/eff_word_net/package_installation_scripts.py @@ -74,3 +74,17 @@ def check_install_librosa(verbose=False, upgrade=False, force=False, **kw): print('.'*50) print('All done! Carry on.') +def is_arm_cpu(): + """ + Check if the CPU architecture is ARM. + + This function determines whether the current system is running on + an ARM CPU by inspecting the machine architecture string provided + by the platform module. + + Returns: + bool: True if the CPU is ARM, False otherwise. + """ + import platform + architecture = platform.machine() + return architecture.startswith('arm') or architecture.startswith('aarch') \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 264ff5b..0dac50d 100755 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,4 @@ numpy>=1.22.0 onnxruntime>=1.14.1 PyAudio>=0.2.13 -requests>=2.26.0 -tensorflow>=2.13.0; sys_platform != 'linux' \ No newline at end of file +requests>=2.26.0 \ No newline at end of file diff --git a/setup.py b/setup.py index 4c10418..9d02106 100755 --- a/setup.py +++ b/setup.py @@ -6,9 +6,27 @@ with open("requirements.txt", "r", encoding="utf-8") as fr: requirements = fr.read().splitlines() +def is_arm_cpu(): + """ + Check if the CPU architecture is ARM. + + This function determines whether the current system is running on + an ARM CPU by inspecting the machine architecture string provided + by the platform module. + + Returns: + bool: True if the CPU is ARM, False otherwise. + """ + import platform + architecture = platform.machine() + return architecture.startswith('arm') or architecture.startswith('aarch') + +if not is_arm_cpu(): + requirements.append("tensorflow>=2.13.0") + setup( name='EfficientWord-Net', - version='1.1.0', + version='1.1.1', description='Few Shot Learning based Hotword Detection Engine', long_description=long_description, long_description_content_type='text/markdown',