ming0531 commited on
Commit
107af9c
·
verified ·
1 Parent(s): fb5a1e0

Sync the flashrefocus package

Browse files
.gitignore ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ weights/
2
+ __pycache__/
3
+ *.pyc
flashrefocus/_compat.py CHANGED
@@ -1,6 +1,9 @@
1
  """Compatibility with newer libraries than the ones the code was written for."""
2
  import huggingface_hub
3
 
4
- # diffusers 0.25 (required by PiSA-SR's model code) imports huggingface_hub.cached_download, removed in hub 0.26
5
- if not hasattr(huggingface_hub, "cached_download"):
6
- huggingface_hub.cached_download = huggingface_hub.hf_hub_download
 
 
 
 
1
  """Compatibility with newer libraries than the ones the code was written for."""
2
  import huggingface_hub
3
 
4
+
5
+ def patch_huggingface_hub():
6
+ """diffusers 0.25 (required by PiSA-SR's model code) imports huggingface_hub.cached_download, removed in hub 0.26.
7
+ Call before importing diffusers."""
8
+ if not hasattr(huggingface_hub, "cached_download"):
9
+ huggingface_hub.cached_download = huggingface_hub.hf_hub_download
flashrefocus/deblurring/decoder_refiner.py CHANGED
@@ -11,10 +11,12 @@ import torch.nn.functional as F
11
  from torch import nn
12
  from torchvision.transforms.functional import gaussian_blur
13
 
14
- from .. import _compat # noqa: F401
15
  from .. import paths
 
16
  from ..layers import NAFBlock
17
 
 
 
18
 
19
  def high_frequency_residual(image, kernel_size=5, sigma=1.0):
20
  """image minus its blurred 2x down-up-sampled version (one Laplacian-pyramid level)."""
 
11
  from torch import nn
12
  from torchvision.transforms.functional import gaussian_blur
13
 
 
14
  from .. import paths
15
+ from .._compat import patch_huggingface_hub
16
  from ..layers import NAFBlock
17
 
18
+ patch_huggingface_hub() # before diffusers is imported
19
+
20
 
21
  def high_frequency_residual(image, kernel_size=5, sigma=1.0):
22
  """image minus its blurred 2x down-up-sampled version (one Laplacian-pyramid level)."""
flashrefocus/deblurring/one_step_diffusion.py CHANGED
@@ -17,8 +17,10 @@ import copy
17
 
18
  import torch
19
 
20
- from .. import _compat # noqa: F401
21
  from .. import paths
 
 
 
22
 
23
  NO_TILING = 100000 # tile sizes above any input: the whole image is processed at once
24
 
 
17
 
18
  import torch
19
 
 
20
  from .. import paths
21
+ from .._compat import patch_huggingface_hub
22
+
23
+ patch_huggingface_hub() # before diffusers is imported
24
 
25
  NO_TILING = 100000 # tile sizes above any input: the whole image is processed at once
26