Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions RealESRGAN/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from PIL import Image
import numpy as np
import cv2
from huggingface_hub import hf_hub_url, cached_download
from huggingface_hub import hf_hub_download

from .rrdbnet_arch import RRDBNet
from .utils import pad_reflect, split_image_into_overlapping_patches, stich_together, \
Expand Down Expand Up @@ -42,8 +42,16 @@ def load_weights(self, model_path, download=True):
config = HF_MODELS[self.scale]
cache_dir = os.path.dirname(model_path)
local_filename = os.path.basename(model_path)
config_file_url = hf_hub_url(repo_id=config['repo_id'], filename=config['filename'])
cached_download(config_file_url, cache_dir=cache_dir, force_filename=local_filename)
downloaded_model_path = hf_hub_download(
repo_id=config['repo_id'],
filename=config['filename'],
cache_dir=cache_dir,
local_dir=cache_dir,
local_dir_use_symlinks=False
)
os.rename(downloaded_model_path, model_path)
print('Weights downloaded to:', model_path)

print('Weights downloaded to:', os.path.join(cache_dir, local_filename))

loadnet = torch.load(model_path)
Expand Down