Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DRAFT] Reorganize repository to a somewhat standardized format #1

Draft
wants to merge 18 commits into
base: main
Choose a base branch
from
Draft
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
7 changes: 3 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
__pycache__
.python-version

# Datasets
# Directories
datasets/

# Outputs
runs
runs/
reference_models/heidenreich/datasets/

# Miscellaneous
**/.DS_Store
Expand Down
1 change: 0 additions & 1 deletion data/__init__.py

This file was deleted.

52 changes: 52 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
[build-system]
requires = ["hatchling", "hatch-requirements-txt"]
build-backend = "hatchling.build"

[project]
name = "timbre"
version = "0"
# dependencies = []
requires-python = ">=3.8"
authors = [{ name = "Quinn Ouyang", email = "qouyang3+timbre@illinois.edu" }]
# maintainers = [
# { name = "Quinn qouyang", email = "qouyang3+timbre@illinois.edu" },
# ]
# description = ""
readme = "README.md"
# license = {file = "LICENSE"}
# keywords = []
classifiers = [
"Development Status :: 1 - Planning",
"Intended Audience :: Education",
"Intended Audience :: Science/Research",
# "License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3.8",
"Topic :: Scientific/Engineering :: Artificial Intelligence",
"Topic :: Multimedia :: Sound/Audio :: Sound Synthesis",
]
dynamic = ["dependencies"]

[project.urls]
# homepage = ""
source = "https://github.com/quinnouyang/timbre"
github = "https://github.com/quinnouyang/timbre.git"
# download = ""
# changelog = ""
# documentation = ""
issues = "https://github.com/quinnouyang/timbre/issues"

[tool.hatch.metadata]
allow-direct-references = true

[tool.hatch.metadata.hooks.requirements_txt]
files = ["requirements.txt"]

# [tool.hatch.metadata.hooks.requirements_txt.optional-dependencies]
# cli = ["requirements-dev.txt"]

[tool.black]
extend-exclude = "reference_models"

[tool.isort]
profile = "black"
skip_glob = ["reference_models"]
7 changes: 5 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
black
ipykernel
isort
librosa
matplotlib
scipy
pip
tensorboard
torch
torch_tb_profiler
torchaudio
torchvision
tqdm
yapecs
28 changes: 0 additions & 28 deletions setup.py

This file was deleted.

20 changes: 18 additions & 2 deletions timbre/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,18 @@
from .model.train.utils import train, test, plot
from .model.vae import VAE, VAEOutput
###############################################################################
# Configuration
###############################################################################


import yapecs

from .config import defaults

yapecs.configure("timbre", defaults)

###############################################################################
# Module
###############################################################################

# from .train import ...
from . import data, model
from .config.defaults import *
Empty file added timbre/config/__init__.py
Empty file.
99 changes: 99 additions & 0 deletions timbre/config/defaults.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# Based off of https://github.com/maxrmorrison/deep-learning-project-template/blob/main/NAME/config/defaults.py

from datetime import datetime
from pathlib import Path

from torch.utils.tensorboard.writer import SummaryWriter

from .utils import get_device, should_pin_memory

# Configuration name
CONFIG = "defaults"


###############################################################################
# Data
###############################################################################

# Dataset names
DATASETS = ["nsynth"]

# EVALUATION_DATASETS = DATASETS


###############################################################################
# Directories
###############################################################################

_PACKAGE_DIR = Path(__file__).parent.parent

# For assets to bundle with pip release
# ASSETS_DIR = _PACKAGE_DIR / "assets"

_ROOT_DIR = _PACKAGE_DIR.parent

_DATA_DIR = _ROOT_DIR / "datasets"

# For preprocessed features
# CACHE_DIR = _DATA_DIR / "cache"

# For unprocessed datasets
SOURCES_DIR = _DATA_DIR / "sources"

# For preprocessed datasets
PREPROCESSED_DIR = _DATA_DIR / "preprocessed"

# For training and adaptation artifacts
RUNS_DIR = _ROOT_DIR / "runs"

# For evaluation artifacts
# EVAL_DIR = _ROOT_DIR.parent / "eval"


###############################################################################
# Training
###############################################################################


# Batch size per gpu
BATCH_SIZE = 128

# Steps between saving checkpoints
# CHECKPOINT_INTERVAL = 25000

# Training steps
# STEPS = 300000

# Worker threads for data loading
NUM_WORKERS = 8

# RANDOM_SEED = 1234

# [TODO] Formalize these options

LEARN_RATE = 1e-3
WEIGHT_DECAY = 1e-2
NUM_EPOCHS = 64
# INPUT_DIM = 16064
INPUT_DIM = 2048
LATENT_DIM = 2
# HIDDEN_DIM = 8064
HIDDEN_DIM = 1024

DEVICE = get_device()

USE_PIN_MEMORY = should_pin_memory()
DATETIME_NOW = datetime.now().strftime("%Y%m%d-%H%M%S")
WRITER = SummaryWriter(RUNS_DIR / f"log_{DATETIME_NOW}")


###############################################################################
# Evaluation
###############################################################################


# Steps between tensorboard logging
# EVALUATION_INTERVAL = 2500 # steps

# Steps to perform for tensorboard logging
# DEFAULT_EVALUATION_STEPS = 16
14 changes: 14 additions & 0 deletions timbre/config/malleus.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from pathlib import Path

MODULE = "timbre"

# Configuration name
CONFIG = "malleus"

_DATA_DIR = Path("/") / "mnt" / "data" / "quinn" / "timbre"

# For unprocessed datasets
SOURCES_DIR = _DATA_DIR / "sources"

# For preprocessed features
PREPROCESSED_DIR = _DATA_DIR / "preprocessed"
13 changes: 13 additions & 0 deletions timbre/config/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import torch


def get_device() -> torch.device:
return torch.device(
"cuda"
if torch.cuda.is_available()
else "mps" if torch.backends.mps.is_available() else "cpu"
)


def should_pin_memory() -> bool:
return get_device() == "cuda"
Empty file added timbre/data/__init__.py
Empty file.
29 changes: 13 additions & 16 deletions data/utils/nsynth.py → timbre/data/nsynth.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import json

from argparse import ArgumentParser
from contextlib import suppress
from os import path, listdir
from os import listdir, path
from pathlib import Path
from typing import Any, Literal, NamedTuple

from torch import Tensor, float32
from torch.utils.data import Dataset
from typing import NamedTuple, Literal, Any
from torchaudio import load, transforms

transform_melspec = transforms.MelSpectrogram(n_fft=512, n_mels=64)
Expand Down Expand Up @@ -43,17 +43,17 @@ class NSynthDataset(Dataset):

Parameters
----------
`annotations_file` : `str` | `Path`
Path to the JSON file containing the annotations
`audio_dir` : `str` | `Path`
Path to the directory containing the audio files
`source_dir` : `str` | `Path`
Path to a subset of the unprocessed NSynth dataset directory containing `examples.json` and `audio` directory
"""

def __init__(
self,
annotations_file: str | Path,
audio_dir: str | Path,
) -> None:
def __init__(self, source_dir: str | Path) -> None:
if isinstance(source_dir, str):
source_dir = Path(source_dir)

annotations_file = source_dir / "examples.json"
audio_dir = source_dir / "audio"

with open(annotations_file, "r") as f:
self.annotations: dict[str, Any] = json.load(f)
self.keys = sorted(self.annotations.keys()) # note_strs
Expand Down Expand Up @@ -109,9 +109,6 @@ def __getitem__(self, i: int) -> Tensor:

print(f"TEST: Loading NSynthDataset and printing its last example")

D = NSynthDataset(
path.join(args.subset_path, "examples.json"),
path.join(args.subset_path, "audio"),
)
D = NSynthDataset(args.subset_path)

print(D[-1])
Empty file added timbre/model/__init__.py
Empty file.
33 changes: 0 additions & 33 deletions timbre/model/config/single.py

This file was deleted.

Loading