fix(ctrlregen): correct module import paths (#11)

The CtrlRegen engine module references a non-existent top-level package
'ctrlregen' in four locations:

  src/remove_ai_watermarks/noai/ctrlregen/engine.py
    L39:  from ctrlregen.pipeline import CustomCtrlRegenPipeline
    L57:  from ctrlregen.color import color_match
    L242: from ctrlregen.tiling import resize_center_crop, run_tiled
    L267: from ctrlregen.tiling import resize_center_crop

These should be absolute imports of the package's own subpackage. As a
result, the top-level try/except sets _HAS_DIFFUSERS=False and
_HAS_COLOR_MATCHER=False even when the [gpu] extra is correctly
installed, and is_ctrlregen_available() always returns False.

Effect on users: invoking the ctrlregen profile crashes with

  ImportError: Failed to auto-install missing dependencies:
  controlnet-aux, color-matcher, safetensors

regardless of whether those packages are installed. The auto-install
fallback also fails in uv-managed venvs (uv does not ship pip in the
venv by default), so the error path is unrecoverable.

Reproduction (before fix):
  uv sync --all-extras
  uv run remove-ai-watermarks invisible <image> --pipeline ctrlregen
  # → ImportError as above

Fix: change the four imports to use the package-qualified path
(matching the absolute-import style used elsewhere in the codebase,
e.g. watermark_remover.py).

Verified post-fix on Linux/CUDA (NVIDIA L40S):
  - is_ctrlregen_available() returns True
  - CtrlRegen pipeline loads, downloads weights, and runs end-to-end
  - Tile-based path (image > 512px) processes 6 tiles cleanly
  - 142 existing pytest tests still pass
This commit is contained in:
Neo 孫
2026-05-26 00:11:20 +08:00
committed by GitHub
parent b45e2a5731
commit 663c8c64ca
@@ -36,7 +36,7 @@ _HAS_COLOR_MATCHER = False
_HAS_DIFFUSERS = False
try:
from ctrlregen.pipeline import CustomCtrlRegenPipeline
from remove_ai_watermarks.noai.ctrlregen.pipeline import CustomCtrlRegenPipeline
from diffusers import AutoencoderKL, ControlNetModel, UniPCMultistepScheduler
_HAS_DIFFUSERS = True
@@ -54,7 +54,7 @@ except ImportError:
CannyDetector = None # type: ignore[assignment,misc]
try:
from ctrlregen.color import color_match
from remove_ai_watermarks.noai.ctrlregen.color import color_match
_HAS_COLOR_MATCHER = True
except ImportError:
@@ -239,7 +239,7 @@ class CtrlRegenEngine:
needs_tiling = orig_w > TILE_SIZE or orig_h > TILE_SIZE
if needs_tiling:
from ctrlregen.tiling import resize_center_crop, run_tiled
from remove_ai_watermarks.noai.ctrlregen.tiling import resize_center_crop, run_tiled
aligned_w = orig_w // 8 * 8
aligned_h = orig_h // 8 * 8
@@ -264,7 +264,7 @@ class CtrlRegenEngine:
ip_adapter_image=orig_image,
)
else:
from ctrlregen.tiling import resize_center_crop
from remove_ai_watermarks.noai.ctrlregen.tiling import resize_center_crop
proc_image = resize_center_crop(image, PROCESS_SIZE)
self._set_progress(f"Preprocessed {orig_w}x{orig_h}px → {proc_image.size[0]}x{proc_image.size[1]}px")