Fix unable to find Real-ESRGAN model info error (AttributeError: 'NoneType' object has no attribute 'data_path') #6841 #5170

This commit is contained in:
AUTOMATIC 2023-01-17 13:57:55 +03:00
parent c361b89026
commit aede265f1d
2 changed files with 5 additions and 8 deletions

View file

@ -38,13 +38,13 @@ class UpscalerRealESRGAN(Upscaler):
return img return img
info = self.load_model(path) info = self.load_model(path)
if not os.path.exists(info.data_path): if not os.path.exists(info.local_data_path):
print("Unable to load RealESRGAN model: %s" % info.name) print("Unable to load RealESRGAN model: %s" % info.name)
return img return img
upsampler = RealESRGANer( upsampler = RealESRGANer(
scale=info.scale, scale=info.scale,
model_path=info.data_path, model_path=info.local_data_path,
model=info.model(), model=info.model(),
half=not cmd_opts.no_half, half=not cmd_opts.no_half,
tile=opts.ESRGAN_tile, tile=opts.ESRGAN_tile,
@ -58,17 +58,13 @@ class UpscalerRealESRGAN(Upscaler):
def load_model(self, path): def load_model(self, path):
try: try:
info = None info = next(iter([scaler for scaler in self.scalers if scaler.data_path == path]), None)
for scaler in self.scalers:
if scaler.data_path == path:
info = scaler
if info is None: if info is None:
print(f"Unable to find model info: {path}") print(f"Unable to find model info: {path}")
return None return None
model_file = load_file_from_url(url=info.data_path, model_dir=self.model_path, progress=True) info.local_data_path = load_file_from_url(url=info.data_path, model_dir=self.model_path, progress=True)
info.data_path = model_file
return info return info
except Exception as e: except Exception as e:
print(f"Error making Real-ESRGAN models list: {e}", file=sys.stderr) print(f"Error making Real-ESRGAN models list: {e}", file=sys.stderr)

View file

@ -95,6 +95,7 @@ class UpscalerData:
def __init__(self, name: str, path: str, upscaler: Upscaler = None, scale: int = 4, model=None): def __init__(self, name: str, path: str, upscaler: Upscaler = None, scale: int = 4, model=None):
self.name = name self.name = name
self.data_path = path self.data_path = path
self.local_data_path = path
self.scaler = upscaler self.scaler = upscaler
self.scale = scale self.scale = scale
self.model = model self.model = model