mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
fix: add torchvision shim to upscale.py and enhance_faces.py
When the Python dispatcher crashes and bridge.ts retries via per-request spawning, the shim from dispatcher.py isn't loaded. basicsr then fails importing torchvision.transforms.functional_tensor (removed in v0.17). Adding the shim directly to both scripts ensures they work regardless of whether they run through the dispatcher or standalone.
This commit is contained in:
@@ -2,6 +2,25 @@
|
|||||||
import sys
|
import sys
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
import types
|
||||||
|
|
||||||
|
# basicsr imports torchvision.transforms.functional_tensor which was removed
|
||||||
|
# in torchvision >= 0.17. This shim must exist before basicsr is imported.
|
||||||
|
try:
|
||||||
|
import torchvision.transforms.functional_tensor # noqa: F401
|
||||||
|
except (ImportError, ModuleNotFoundError):
|
||||||
|
try:
|
||||||
|
import torchvision.transforms.functional as _F
|
||||||
|
import torchvision.transforms
|
||||||
|
|
||||||
|
_shim = types.ModuleType("torchvision.transforms.functional_tensor")
|
||||||
|
for _attr in dir(_F):
|
||||||
|
if not _attr.startswith("_"):
|
||||||
|
setattr(_shim, _attr, getattr(_F, _attr))
|
||||||
|
sys.modules["torchvision.transforms.functional_tensor"] = _shim
|
||||||
|
torchvision.transforms.functional_tensor = _shim
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def emit_progress(percent, stage):
|
def emit_progress(percent, stage):
|
||||||
|
|||||||
@@ -1,7 +1,26 @@
|
|||||||
"""Image upscaling with Real-ESRGAN fallback to Lanczos."""
|
"""Image upscaling with Real-ESRGAN."""
|
||||||
import sys
|
import sys
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
import types
|
||||||
|
|
||||||
|
# basicsr imports torchvision.transforms.functional_tensor which was removed
|
||||||
|
# in torchvision >= 0.17. This shim must exist before basicsr is imported.
|
||||||
|
try:
|
||||||
|
import torchvision.transforms.functional_tensor # noqa: F401
|
||||||
|
except (ImportError, ModuleNotFoundError):
|
||||||
|
try:
|
||||||
|
import torchvision.transforms.functional as _F
|
||||||
|
import torchvision.transforms
|
||||||
|
|
||||||
|
_shim = types.ModuleType("torchvision.transforms.functional_tensor")
|
||||||
|
for _attr in dir(_F):
|
||||||
|
if not _attr.startswith("_"):
|
||||||
|
setattr(_shim, _attr, getattr(_F, _attr))
|
||||||
|
sys.modules["torchvision.transforms.functional_tensor"] = _shim
|
||||||
|
torchvision.transforms.functional_tensor = _shim
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def emit_progress(percent, stage):
|
def emit_progress(percent, stage):
|
||||||
|
|||||||
Reference in New Issue
Block a user