diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 757988f..7c2b253 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -74,6 +74,14 @@ jobs: uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} + - name: Cache DeepFace weights + uses: actions/cache@v4 + with: + path: ~/.deepface/weights + key: deepface-weights-${{ runner.os }}-py${{ matrix.python-version }}-${{ hashFiles('requirements.txt') }} + restore-keys: | + deepface-weights-${{ runner.os }}-py${{ matrix.python-version }}- + deepface-weights-${{ runner.os }}- - name: Install dependencies run: | python -m pip install --upgrade pip @@ -81,6 +89,41 @@ jobs: # sending files in form data throwing error in flask 3 while running tests pip install Werkzeug==2.0.2 flask==2.0.2 pip install . + - name: Remove corrupted DeepFace weights (if any) + run: | + python - <<'PY' + import os, glob + + weights_dir = os.path.expanduser("~/.deepface/weights") + if not os.path.isdir(weights_dir): + raise SystemExit(0) + + # Validate HDF5 integrity; delete invalid files so they will be re-downloaded. + try: + import h5py + except Exception: + # If h5py isn't present for some reason, fall back to size-based cleanup only. + h5py = None + + for p in glob.glob(os.path.join(weights_dir, "*.h5")): + try: + # Keep your existing small-file guard + if os.path.getsize(p) < 1024 * 100: + print("Removing tiny weight file:", p) + os.remove(p) + continue + + if h5py is not None: + try: + with h5py.File(p, "r"): + pass + except Exception as e: + print("Removing corrupted H5 weight file:", p, "reason:", repr(e)) + os.remove(p) + + except OSError: + pass + PY - name: Test with pytest run: | cd tests/unit