Spaces:
Runtime error
Runtime error
""" | |
Monkey patch for detectron2 PIL.Image.LINEAR issue | |
This module patches the PIL.Image module to ensure LINEAR exists as an alias for BILINEAR | |
Must be imported before detectron2 is imported | |
""" | |
import sys | |
import PIL.Image | |
# Add LINEAR as an alias for BILINEAR if it doesn't exist | |
if not hasattr(PIL.Image, 'LINEAR'): | |
PIL.Image.LINEAR = PIL.Image.BILINEAR | |
print("Monkey patched PIL.Image.LINEAR to PIL.Image.BILINEAR") | |
# This will make detectron2 imports work with our patched PIL | |
def patch_detectron2(): | |
# Force all detectron2 modules to reload if they're already imported | |
for name in list(sys.modules.keys()): | |
if name.startswith('detectron2'): | |
del sys.modules[name] | |
print("Cleaned up detectron2 imports for monkey patching") |