diff --git a/.gitattributes.bak b/.gitattributes.bak new file mode 100644 index 0000000..b3ec926 --- /dev/null +++ b/.gitattributes.bak @@ -0,0 +1,2 @@ +*.pkl filter=lfs diff=lfs merge=lfs -text +*.faiss filter=lfs diff=lfs merge=lfs -text diff --git a/config.py b/config.py index e89eeb9..feeff1c 100644 --- a/config.py +++ b/config.py @@ -6,6 +6,18 @@ Override via environment variables or by modifying defaults. """ import os +import platform + +# Disable MPS (Metal) on Apple Silicon to avoid intermittent inference failures +# This must be set BEFORE importing TensorFlow/Keras +os.environ.setdefault('TF_USE_LEGACY_KERAS', '1') +os.environ.setdefault('CUDA_VISIBLE_DEVICES', '') +os.environ.setdefault('TF_CPP_MIN_LOG_LEVEL', '2') + +# Force CPU-only on macOS to avoid MPS graph caching bugs +if platform.system() == 'Darwin': + os.environ['TF_DISABLE_MPS_DEVICE_PLACEMENT'] = '1' + os.environ['METAL_DEVICE_WRAPPER_TYPE'] = '0' class Config: diff --git a/reverse_icon_search.py b/reverse_icon_search.py index 0dbbbf8..c1f06d6 100644 --- a/reverse_icon_search.py +++ b/reverse_icon_search.py @@ -1,6 +1,16 @@ import os +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' + import numpy as np import joblib + +# Disable GPU/Metal to fix intermittent MPS graph cache crash on Apple Silicon +import tensorflow as tf +try: + tf.config.set_visible_devices([], 'GPU') +except Exception: + pass + from keras import Sequential from keras.preprocessing import image from keras.layers import GlobalMaxPooling2D