Ver Fonte

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

AUTOMATIC há 2 anos atrás
pai
commit
aede265f1d
2 ficheiros alterados com 5 adições e 8 exclusões
  1. 4 8
      modules/realesrgan_model.py
  2. 1 0
      modules/upscaler.py

+ 4 - 8
modules/realesrgan_model.py

@@ -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
-            for scaler in self.scalers:
-                if scaler.data_path == path:
-                    info = scaler
+            info = next(iter([scaler for scaler in self.scalers if scaler.data_path == path]), None)
 
 
             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.data_path = model_file
+            info.local_data_path = load_file_from_url(url=info.data_path, model_dir=self.model_path, progress=True)
             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)

+ 1 - 0
modules/upscaler.py

@@ -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