Three bugs: numpy 2.x crash, --with_scratch always active, filenames with spaces fail silently

Author: shabo94Created Jun 30, 2026Updated Jun 30, 2026

Summary

Three bugs found while running the project on Ubuntu 24.04 with Python 3.12, numpy 2.x and PyTorch 2.5.


Bug 1 — numpy 2.x crash in align_warp_back_multiple_dlib.py

File: Face_Detection/align_warp_back_multiple_dlib.py (lines 200 and 219)

Error: ``` numpy._core._exceptions._UFuncOutputCastingError: Cannot cast ufunc 'multiply' output from dtype('float64') to dtype('uint8') with casting rule 'same_kind' ```

numpy 2.x enforces stricter in-place casting rules. The fix:

```python

Before (both occurrences)

mask *= 255.0

After

mask = (mask * 255.0).astype(np.uint8) ```


Bug 2 — --with_scratch always active in GUI.py

File: GUI.py (line 33)

The default value for --with_scratch is set to the string "--with_scratch" instead of False. Since action="store_true" uses the default when the flag is absent, and a non-empty string is truthy, scratch detection mode is always active regardless of user intent.

```python

Before

parser.add_argument("--with_scratch", default="--with_scratch", action="store_true")

After

parser.add_argument("--with_scratch", default=False, action="store_true") ```


Bug 3 — Filenames with spaces cause silent failures in GUI.py

File: GUI.py (all stage commands)

All shell commands in modify() concatenate paths as raw strings. Any filename or folder containing spaces breaks the command silently (the subprocess fails but the try/except: continue block swallows the error).

Fix: wrap all path variables with shlex.quote():

```python import shlex q = shlex.quote

Example for Stage 1:

stage_1_command = ( "python test.py --test_mode Full --Quality_restore --test_input " + q(stage_1_input_dir) + " --outputs_dir " + q(stage_1_output_dir) + " --gpu_ids " + gpu1 ) ```

The same fix applies to all stage commands (Stage 2, 3 and 4).


Environment

  • OS: Ubuntu 24.04 / Linux Lite 7.8
  • Python: 3.12.3
  • numpy: 2.4.4
  • PyTorch: 2.5.1+cu121
  • CUDA: 12.2

Source: microsoft/Bringing-Old-Photos-Back-to-Life