Upload monkey_patch.py

#7
by skallewag - opened
Files changed (1) hide show
  1. monkey_patch.py +21 -0
monkey_patch.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Monkey patch for detectron2 PIL.Image.LINEAR issue
3
+ This module patches the PIL.Image module to ensure LINEAR exists as an alias for BILINEAR
4
+ Must be imported before detectron2 is imported
5
+ """
6
+ import sys
7
+ import PIL.Image
8
+
9
+ # Add LINEAR as an alias for BILINEAR if it doesn't exist
10
+ if not hasattr(PIL.Image, 'LINEAR'):
11
+ PIL.Image.LINEAR = PIL.Image.BILINEAR
12
+ print("Monkey patched PIL.Image.LINEAR to PIL.Image.BILINEAR")
13
+
14
+ # This will make detectron2 imports work with our patched PIL
15
+ def patch_detectron2():
16
+ # Force all detectron2 modules to reload if they're already imported
17
+ for name in list(sys.modules.keys()):
18
+ if name.startswith('detectron2'):
19
+ del sys.modules[name]
20
+
21
+ print("Cleaned up detectron2 imports for monkey patching")