Unverified Commit 9d8af4bd authored by Beinsezii's avatar Beinsezii Committed by GitHub
Browse files

Merge branch 'AUTOMATIC1111:dev' into dev

parents 1d7c51fb fab73f2e
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -18,7 +18,7 @@ jobs:
          #     not to have GHA download an (at the time of writing) 4 GB cache
          #     not to have GHA download an (at the time of writing) 4 GB cache
          #     of PyTorch and other dependencies.
          #     of PyTorch and other dependencies.
      - name: Install Ruff
      - name: Install Ruff
        run: pip install ruff==0.0.265
        run: pip install ruff==0.0.272
      - name: Run Ruff
      - name: Run Ruff
        run: ruff .
        run: ruff .
  lint-js:
  lint-js:
+1 −1
Original line number Original line Diff line number Diff line
@@ -50,7 +50,7 @@ jobs:
          python -m pytest -vv --junitxml=test/results.xml --cov . --cov-report=xml --verify-base-url test
          python -m pytest -vv --junitxml=test/results.xml --cov . --cov-report=xml --verify-base-url test
      - name: Kill test server
      - name: Kill test server
        if: always()
        if: always()
        run: curl -vv -XPOST http://127.0.0.1:7860/_stop && sleep 10
        run: curl -vv -XPOST http://127.0.0.1:7860/sdapi/v1/server-stop && sleep 10
      - name: Show coverage
      - name: Show coverage
        run: |
        run: |
          python -m coverage combine .coverage*
          python -m coverage combine .coverage*
+8 −12
Original line number Original line Diff line number Diff line
import os
import os


from basicsr.utils.download_util import load_file_from_url
from modules.modelloader import load_file_from_url

from modules.upscaler import Upscaler, UpscalerData
from modules.upscaler import Upscaler, UpscalerData
from ldsr_model_arch import LDSR
from ldsr_model_arch import LDSR
from modules import shared, script_callbacks, errors
from modules import shared, script_callbacks, errors
@@ -43,20 +42,17 @@ class UpscalerLDSR(Upscaler):
        if local_safetensors_path is not None and os.path.exists(local_safetensors_path):
        if local_safetensors_path is not None and os.path.exists(local_safetensors_path):
            model = local_safetensors_path
            model = local_safetensors_path
        else:
        else:
            model = local_ckpt_path if local_ckpt_path is not None else load_file_from_url(url=self.model_url, model_dir=self.model_download_path, file_name="model.ckpt", progress=True)
            model = local_ckpt_path or load_file_from_url(self.model_url, model_dir=self.model_download_path, file_name="model.ckpt")


        yaml = local_yaml_path if local_yaml_path is not None else load_file_from_url(url=self.yaml_url, model_dir=self.model_download_path, file_name="project.yaml", progress=True)
        yaml = local_yaml_path or load_file_from_url(self.yaml_url, model_dir=self.model_download_path, file_name="project.yaml")


        try:
        return LDSR(model, yaml)
        return LDSR(model, yaml)
        except Exception:
            errors.report("Error importing LDSR", exc_info=True)
        return None


    def do_upscale(self, img, path):
    def do_upscale(self, img, path):
        try:
            ldsr = self.load_model(path)
            ldsr = self.load_model(path)
        if ldsr is None:
        except Exception:
            print("NO LDSR!")
            errors.report(f"Failed loading LDSR model {path}", exc_info=True)
            return img
            return img
        ddim_steps = shared.opts.ldsr_steps
        ddim_steps = shared.opts.ldsr_steps
        return ldsr.super_resolution(img, ddim_steps, self.scale)
        return ldsr.super_resolution(img, ddim_steps, self.scale)
+11 −15
Original line number Original line Diff line number Diff line
import os.path
import sys
import sys


import PIL.Image
import PIL.Image
@@ -6,12 +5,11 @@ import numpy as np
import torch
import torch
from tqdm import tqdm
from tqdm import tqdm


from basicsr.utils.download_util import load_file_from_url

import modules.upscaler
import modules.upscaler
from modules import devices, modelloader, script_callbacks, errors
from modules import devices, modelloader, script_callbacks, errors
from scunet_model_arch import SCUNet as net
from scunet_model_arch import SCUNet


from modules.modelloader import load_file_from_url
from modules.shared import opts
from modules.shared import opts




@@ -28,7 +26,7 @@ class UpscalerScuNET(modules.upscaler.Upscaler):
        scalers = []
        scalers = []
        add_model2 = True
        add_model2 = True
        for file in model_paths:
        for file in model_paths:
            if "http" in file:
            if file.startswith("http"):
                name = self.model_name
                name = self.model_name
            else:
            else:
                name = modelloader.friendly_name(file)
                name = modelloader.friendly_name(file)
@@ -89,9 +87,10 @@ class UpscalerScuNET(modules.upscaler.Upscaler):


        torch.cuda.empty_cache()
        torch.cuda.empty_cache()


        try:
            model = self.load_model(selected_file)
            model = self.load_model(selected_file)
        if model is None:
        except Exception as e:
            print(f"ScuNET: Unable to load model from {selected_file}", file=sys.stderr)
            print(f"ScuNET: Unable to load model from {selected_file}: {e}", file=sys.stderr)
            return img
            return img


        device = devices.get_device_for('scunet')
        device = devices.get_device_for('scunet')
@@ -119,15 +118,12 @@ class UpscalerScuNET(modules.upscaler.Upscaler):


    def load_model(self, path: str):
    def load_model(self, path: str):
        device = devices.get_device_for('scunet')
        device = devices.get_device_for('scunet')
        if "http" in path:
        if path.startswith("http"):
            filename = load_file_from_url(url=self.model_url, model_dir=self.model_download_path, file_name="%s.pth" % self.name, progress=True)
            # TODO: this doesn't use `path` at all?
            filename = load_file_from_url(self.model_url, model_dir=self.model_download_path, file_name=f"{self.name}.pth")
        else:
        else:
            filename = path
            filename = path
        if not os.path.exists(os.path.join(self.model_path, filename)) or filename is None:
        model = SCUNet(in_nc=3, config=[4, 4, 4, 4, 4, 4, 4], dim=64)
            print(f"ScuNET: Unable to load model from {filename}", file=sys.stderr)
            return None

        model = net(in_nc=3, config=[4, 4, 4, 4, 4, 4, 4], dim=64)
        model.load_state_dict(torch.load(filename), strict=True)
        model.load_state_dict(torch.load(filename), strict=True)
        model.eval()
        model.eval()
        for _, v in model.named_parameters():
        for _, v in model.named_parameters():
+29 −28
Original line number Original line Diff line number Diff line
import os
import sys


import numpy as np
import numpy as np
import torch
import torch
from PIL import Image
from PIL import Image
from basicsr.utils.download_util import load_file_from_url
from tqdm import tqdm
from tqdm import tqdm


from modules import modelloader, devices, script_callbacks, shared
from modules import modelloader, devices, script_callbacks, shared
from modules.shared import opts, state
from modules.shared import opts, state
from swinir_model_arch import SwinIR as net
from swinir_model_arch import SwinIR
from swinir_model_arch_v2 import Swin2SR as net2
from swinir_model_arch_v2 import Swin2SR
from modules.upscaler import Upscaler, UpscalerData
from modules.upscaler import Upscaler, UpscalerData


SWINIR_MODEL_URL = "https://github.com/JingyunLiang/SwinIR/releases/download/v0.0/003_realSR_BSRGAN_DFOWMFC_s64w8_SwinIR-L_x4_GAN.pth"


device_swinir = devices.get_device_for('swinir')
device_swinir = devices.get_device_for('swinir')


@@ -19,16 +19,14 @@ device_swinir = devices.get_device_for('swinir')
class UpscalerSwinIR(Upscaler):
class UpscalerSwinIR(Upscaler):
    def __init__(self, dirname):
    def __init__(self, dirname):
        self.name = "SwinIR"
        self.name = "SwinIR"
        self.model_url = "https://github.com/JingyunLiang/SwinIR/releases/download/v0.0" \
        self.model_url = SWINIR_MODEL_URL
                         "/003_realSR_BSRGAN_DFOWMFC_s64w8_SwinIR" \
                         "-L_x4_GAN.pth "
        self.model_name = "SwinIR 4x"
        self.model_name = "SwinIR 4x"
        self.user_path = dirname
        self.user_path = dirname
        super().__init__()
        super().__init__()
        scalers = []
        scalers = []
        model_files = self.find_models(ext_filter=[".pt", ".pth"])
        model_files = self.find_models(ext_filter=[".pt", ".pth"])
        for model in model_files:
        for model in model_files:
            if "http" in model:
            if model.startswith("http"):
                name = self.model_name
                name = self.model_name
            else:
            else:
                name = modelloader.friendly_name(model)
                name = modelloader.friendly_name(model)
@@ -37,8 +35,10 @@ class UpscalerSwinIR(Upscaler):
        self.scalers = scalers
        self.scalers = scalers


    def do_upscale(self, img, model_file):
    def do_upscale(self, img, model_file):
        try:
            model = self.load_model(model_file)
            model = self.load_model(model_file)
        if model is None:
        except Exception as e:
            print(f"Failed loading SwinIR model {model_file}: {e}", file=sys.stderr)
            return img
            return img
        model = model.to(device_swinir, dtype=devices.dtype)
        model = model.to(device_swinir, dtype=devices.dtype)
        img = upscale(img, model)
        img = upscale(img, model)
@@ -49,15 +49,16 @@ class UpscalerSwinIR(Upscaler):
        return img
        return img


    def load_model(self, path, scale=4):
    def load_model(self, path, scale=4):
        if "http" in path:
        if path.startswith("http"):
            dl_name = "%s%s" % (self.model_name.replace(" ", "_"), ".pth")
            filename = modelloader.load_file_from_url(
            filename = load_file_from_url(url=path, model_dir=self.model_download_path, file_name=dl_name, progress=True)
                url=path,
                model_dir=self.model_download_path,
                file_name=f"{self.model_name.replace(' ', '_')}.pth",
            )
        else:
        else:
            filename = path
            filename = path
        if filename is None or not os.path.exists(filename):
            return None
        if filename.endswith(".v2.pth"):
        if filename.endswith(".v2.pth"):
            model = net2(
            model = Swin2SR(
                upscale=scale,
                upscale=scale,
                in_chans=3,
                in_chans=3,
                img_size=64,
                img_size=64,
@@ -72,7 +73,7 @@ class UpscalerSwinIR(Upscaler):
            )
            )
            params = None
            params = None
        else:
        else:
            model = net(
            model = SwinIR(
                upscale=scale,
                upscale=scale,
                in_chans=3,
                in_chans=3,
                img_size=64,
                img_size=64,
Loading