Skip to content

Commit

Permalink
refactor: change to absolute imports and package structure
Browse files Browse the repository at this point in the history
  • Loading branch information
roedoejet committed Oct 3, 2022
1 parent d0b7cd9 commit 64d5310
Show file tree
Hide file tree
Showing 39 changed files with 104 additions and 49 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ logs
*.ckpt
preprocessed
.vscode
*egg-info
9 changes: 0 additions & 9 deletions SmallTeamSpeech/config/__init__.py

This file was deleted.

6 changes: 6 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ Have a look at [Contributing.md](Contributing.md) for the full details on the
Conventional Commit messages we prefer, our code formatting conventions, and
our Git hooks.

You can then interactively install the package by running the following command from the project root:

```sh
pip install -e .
```

## Tests

Run unit tests by `python3 -m unittest tests/test_configs.py`
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[isort]
known_first_party = SmallTeamSpeech,config,dataloader,model,preprocessor,tests,text,utils,vocoder
known_first_party = smts
multi_line_output=3
include_trailing_comma=True
force_grid_wrap=0
Expand Down
47 changes: 47 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
""" Setup for smts
"""
import datetime as dt
from os import path

from setuptools import find_packages, setup

build_no = dt.datetime.today().strftime("%Y%m%d")

# Ugly hack to read the current version number without importing g2p:
# (works by )
with open("smts/_version.py", "r", encoding="utf8") as version_file:
namespace = {} # type: ignore
exec(version_file.read(), namespace)
VERSION = namespace["VERSION"] + "." + build_no

this_directory = path.abspath(path.dirname(__file__))

with open(path.join(this_directory, "readme.md"), encoding="utf8") as f:
long_description = f.read()

with open(path.join(this_directory, "requirements.txt"), encoding="utf8") as f:
REQS = f.read().splitlines()

setup(
name="smts",
python_requires=">=3.9",
version=VERSION,
author="Aidan Pine",
author_email="hello@aidanpine.ca",
license="MIT",
url="https://github.com/roedoejet/SmallTeamSpeech",
description="Text-to-Speech Synthesis for the Speech Generation for Indigenous Language Education Small Teams Project",
long_description=long_description,
long_description_content_type="text/markdown",
platform=["any"],
packages=find_packages(),
include_package_data=True,
install_requires=REQS,
entry_points={"console_scripts": ["smts = smts.cli:app"]},
zip_safe=False,
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
)
File renamed without changes.
1 change: 1 addition & 0 deletions smts/_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VERSION = "0.0.1"
2 changes: 1 addition & 1 deletion cli.py → smts/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import typer
from loguru import logger

from SmallTeamSpeech.config import CONFIGS
from smts.config import CONFIGS

app = typer.Typer()

Expand Down
11 changes: 11 additions & 0 deletions smts/config/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from typing import Any, Dict

from smts.config.base_config import BaseConfig
from smts.config.lj_config import BaseConfig as LJConfig

CONFIGS: Dict[str, Any] = {"base": BaseConfig(), "lj": LJConfig()}


class ConfigError(Exception):
def __init__(self, msg):
super().__init__(msg)
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from torch.nn import functional as F

from utils import (
from smts.utils import (
collapse_whitespace,
generic_dict_loader,
load_lj_metadata_hifigan,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from torch.nn import functional as F

from utils import (
from smts.utils import (
collapse_whitespace,
generic_dict_loader,
load_lj_metadata_hifigan,
Expand Down Expand Up @@ -81,7 +81,7 @@
"train_data_workers": 4,
"val_data_workers": 1,
"logger": { # Uses Tensorboard
"name": "LJ",
"name": "test",
"save_dir": "./logs",
"sub_dir": str(int(datetime.today().timestamp())),
"version": "base",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import torch
from torch.utils.data import DataLoader, Dataset, random_split

from config.base_config import BaseConfig
from smts.config.base_config import BaseConfig


class BaseDataModule(pl.LightningDataModule):
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
from torch.nn import AvgPool1d, Conv1d, Conv2d, ConvTranspose1d
from torch.nn.utils import remove_weight_norm, spectral_norm, weight_norm

from config.base_config import BaseConfig
from model.utils import create_depthwise_separable_convolution
from utils import get_spectral_transform, plot_spectrogram
from smts.config.base_config import BaseConfig
from smts.model.utils import create_depthwise_separable_convolution
from smts.utils import get_spectral_transform, plot_spectrogram


def init_weights(m, mean=0.0, std=0.01):
Expand Down
4 changes: 2 additions & 2 deletions SmallTeamSpeech/preprocess.py → smts/preprocess.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from config import CONFIGS
from preprocessor import Preprocessor
from smts.config import CONFIGS
from smts.preprocessor import Preprocessor

CONFIG = CONFIGS["lj"]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
from torchaudio.sox_effects import apply_effects_tensor
from tqdm import tqdm

from config import ConfigError
from text import TextProcessor
from utils import get_spectral_transform, read_textgrid, write_filelist
from smts.config import ConfigError
from smts.text import TextProcessor
from smts.utils import get_spectral_transform, read_textgrid, write_filelist


class Preprocessor:
Expand Down
10 changes: 5 additions & 5 deletions SmallTeamSpeech/run_tests.py → smts/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@

from loguru import logger

from tests.test_configs import ConfigTest
from tests.test_dataloader import DataLoaderTest
from tests.test_model import ModelTest
from tests.test_preprocessing import PreprocessingTest
from tests.test_text import TextTest
from smts.tests.test_configs import ConfigTest
from smts.tests.test_dataloader import DataLoaderTest
from smts.tests.test_model import ModelTest
from smts.tests.test_preprocessing import PreprocessingTest
from smts.tests.test_text import TextTest

# Unit tests

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import math
from unittest import TestCase

from config import CONFIGS
from config.base_config import (
from smts.config import CONFIGS
from smts.config.base_config import (
BASE_MODEL_HPARAMS,
BASE_PREPROCESSING_HPARAMS,
BASE_TRAINING_HPARAMS,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from unittest import TestCase

from config.base_config import BaseConfig
from dataloader import BaseDataModule, HiFiGANDataModule, SpecDataset
from smts.config.base_config import BaseConfig
from smts.dataloader import BaseDataModule, HiFiGANDataModule, SpecDataset


class DataLoaderTest(TestCase):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from unittest import TestCase

from config import BaseConfig
from model.vocoder.hifigan import HiFiGAN
from smts.config import BaseConfig
from smts.model.vocoder.hifigan import HiFiGAN


class ModelTest(TestCase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

from torch import float32

from config.base_config import BaseConfig
from preprocessor import Preprocessor
from utils import read_filelist
from smts.config.base_config import BaseConfig
from smts.preprocessor import Preprocessor
from smts.utils import read_filelist


class PreprocessingTest(TestCase):
Expand All @@ -27,7 +27,7 @@ def setUp(self) -> None:
self.tempdir = tempfile.mkdtemp(prefix=tempdir_prefix, dir=".")
print(f"tmpdir={self.tempdir}")
self.tempdir = Path(self.tempdir) # type: ignore
self.filelist = read_filelist(self.data_dir / "metadata.csv")
self.filelist = read_filelist(self.data_dir / "metadata.csv") # type: ignore
self.preprocessor = Preprocessor(BaseConfig())

def tearDown(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from unicodedata import normalize
from unittest import TestCase

from config import BaseConfig
from text import TextProcessor
from smts.config import BaseConfig
from smts.text import TextProcessor


class TextTest(TestCase):
Expand Down
6 changes: 3 additions & 3 deletions SmallTeamSpeech/text/__init__.py → smts/text/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
from loguru import logger
from nltk.tokenize import RegexpTokenizer

from config import ConfigError
from config.base_config import BaseConfig
from text.features import get_features
from smts.config import ConfigError
from smts.config.base_config import BaseConfig
from smts.text.features import get_features


class TextProcessor:
Expand Down
File renamed without changes.
7 changes: 3 additions & 4 deletions SmallTeamSpeech/train.py → smts/train.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import os

from pytorch_lightning import Trainer
from pytorch_lightning.callbacks import ModelCheckpoint
from pytorch_lightning.loggers import TensorBoardLogger

from config import CONFIGS
from dataloader import HiFiGANDataModule
from model.vocoder.hifigan import HiFiGAN
from pytorch_lightning import Trainer
from pytorch_lightning.callbacks import ModelCheckpoint
from pytorch_lightning.loggers import TensorBoardLogger

CONFIG = CONFIGS["lj"]

Expand Down
3 changes: 1 addition & 2 deletions SmallTeamSpeech/tune.py → smts/tune.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from pytorch_lightning import Trainer

from config import CONFIGS
from dataloader import HiFiGANDataModule
from model.vocoder.hifigan import HiFiGAN
from pytorch_lightning import Trainer

CONFIG = CONFIGS["lj"]

Expand Down
File renamed without changes.

0 comments on commit 64d5310

Please sign in to comment.