Skip to content

Commit

Permalink
feat: add frozen flag (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tohrusky committed Jan 1, 2024
1 parent 09be75f commit c1bf9ef
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/Release-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
- name: Build package
run: |
pdm install
pdm install --skip download_models
pdm build
- name: Publish a Python distribution to PyPI
Expand Down
5 changes: 5 additions & 0 deletions src/Final2x_core/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
from Final2x_core.src.SRqueue import SR_queue
from Final2x_core.src.utils.getConfig import SRCONFIG

_IS_FROZEN_ = False

if getattr(sys, "frozen", False):
# frozen
_IS_FROZEN_ = True
projectPATH = Path(sys.executable).parent.absolute()
else:
# unfrozen
Expand Down Expand Up @@ -62,6 +65,8 @@ def main() -> None:
else:
config.getConfigfromYaml(str(projectPATH / "config.yaml"), str(projectPATH / "models"))

config.isfrozen = _IS_FROZEN_

logger.info("config loaded")
logger.debug(config.outputpath)

Expand Down
5 changes: 4 additions & 1 deletion src/Final2x_core/src/SRFactory/REALCUGAN.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ def __init__(self) -> None:

@logger.catch(reraise=True)
def _init_SR_class(self) -> None:
from Final2x_core.src.SRncnn.REALCUGANncnn import REALCUGANncnn
if self._isfrozen:
from Final2x_core.src.SRncnn.REALCUGANncnn import REALCUGANncnn
else:
from realcugan_ncnn_py import Realcugan as REALCUGANncnn # type: ignore

if self._model == "RealCUGAN-se":
model_i = "models-se"
Expand Down
6 changes: 4 additions & 2 deletions src/Final2x_core/src/SRFactory/REALESRGAN.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ def __init__(self) -> None:

@logger.catch(reraise=True)
def _init_SR_class(self) -> None:
from Final2x_core.src.SRncnn.REALESRGANncnn import REALESRGANncnn

if self._isfrozen:
from Final2x_core.src.SRncnn.REALESRGANncnn import REALESRGANncnn
else:
from realesrgan_ncnn_py import Realesrgan as REALESRGANncnn # type: ignore
# model_dict = {
# 0: {"param": "realesr-animevideov3-x2.param", "bin": "realesr-animevideov3-x2.bin", "scale": 2},
# 1: {"param": "realesr-animevideov3-x3.param", "bin": "realesr-animevideov3-x3.bin", "scale": 3},
Expand Down
3 changes: 3 additions & 0 deletions src/Final2x_core/src/SRFactory/SRBaseClass.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
class SRBaseClass(ABC):
def __init__(self) -> None:
config = SRCONFIG()

self._isfrozen: bool = config.isfrozen # freeze model

self._targetscale: float = config.targetscale # user upscale factor
self._gpuid: int = config.gpuid # gpu id, -1 for cpu
self._tta: bool = config.tta # use tta
Expand Down
6 changes: 4 additions & 2 deletions src/Final2x_core/src/SRFactory/WAIFU2X.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ def __init__(self) -> None:

@logger.catch(reraise=True)
def _init_SR_class(self) -> None:
from Final2x_core.src.SRncnn.WAIFU2Xncnn import WAIFU2Xncnn

if self._isfrozen:
from Final2x_core.src.SRncnn.WAIFU2Xncnn import WAIFU2Xncnn
else:
from waifu2x_ncnn_py import Waifu2x as WAIFU2Xncnn # type: ignore
# waifu2x model name, can be "models-cunet",
# "models-upconv_7_anime_style_art_rgb" and
# "models-upconv_7_photo", default: models-cunet
Expand Down
1 change: 1 addition & 0 deletions src/Final2x_core/src/utils/getConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def __init__(self) -> None:
self._modelscale: int = 2
self._modelnoise: int = 0
self._inputpath: List[str] = []
self.isfrozen: bool = False

@logger.catch(reraise=True)
def getConfigfromYaml(self, configpath: str = "", modelpath: str = "") -> None:
Expand Down

0 comments on commit c1bf9ef

Please sign in to comment.