Skip to content
Open
Show file tree
Hide file tree
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
11 changes: 5 additions & 6 deletions src/perth/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ class Config:
},
}

@classmethod
def get_default_models_dir(cls) -> str:
return os.path.join(os.path.dirname(__file__), "perth_net", "pretrained")

def __init__(self, config_path: Optional[str] = None):
"""
Initialize configuration with default values and optional user config.
Expand All @@ -47,12 +51,7 @@ def __init__(self, config_path: Optional[str] = None):
self._config[section] = values.copy()

# Set default models directory
self._config["perth"]["models_dir"] = os.path.join(
os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
"perth",
"perth_net",
"pretrained",
)
self._config["perth"]["models_dir"] = self.get_default_models_dir()

# Load user config if provided
if config_path and os.path.exists(config_path):
Expand Down
6 changes: 3 additions & 3 deletions src/perth/perth_net/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from importlib.resources import files

PREPACKAGED_MODELS_DIR = files(__name__).joinpath("pretrained")
from .perth_net_implicit.perth_watermarker import PerthImplicitWatermarker # noqa: E402, F401
from ..config import Config

PREPACKAGED_MODELS_DIR = Config.get_default_models_dir() # For backward compatibility
7 changes: 5 additions & 2 deletions src/perth/perth_net/perth_net_implicit/perth_watermarker.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from librosa import resample

from .model.perth_net import PerthNet
from .. import PREPACKAGED_MODELS_DIR
from perth.watermarker import WatermarkerBase


Expand All @@ -17,12 +16,16 @@ class PerthImplicitWatermarker(WatermarkerBase):
def __init__(
self,
run_name: str = "implicit",
models_dir=PREPACKAGED_MODELS_DIR,
models_dir=None,
device="cpu",
perth_net=None,
):
assert (run_name is None) or (perth_net is None)
if perth_net is None:
if not models_dir:
from perth.config import Config

models_dir = Config.get_default_models_dir()
self.perth_net = PerthNet.load(run_name, models_dir).to(device)
else:
self.perth_net = perth_net.to(device)
Expand Down