-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from carlthome/add-pytest
Add unit test workflow
- Loading branch information
Showing
14 changed files
with
137 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
on: push | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: "3.x" | ||
cache: pip | ||
|
||
- name: Install dependencies | ||
run: make requirements | ||
|
||
- name: Install test runner | ||
run: pip install pytest pytest-cov | ||
|
||
- name: Run unit tests | ||
run: pytest --cov=src |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
[tool.isort] | ||
profile = "black" | ||
|
||
[tool.autoflake] | ||
remove_all_unused_imports = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
import torch | ||
import torch.nn as nn | ||
from torchvision.models import ResNet50_Weights, resnet50 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from src.data.freemusicarchive import FreeMusicArchive | ||
from src.data.gtzan import GTZAN | ||
from src.data.magnatagatune import MagnaTagATune | ||
from src.data.millionsongdataset import MillionSongDataset | ||
from src.data.nsynth import NSynthInstrument, NSynthPitch | ||
|
||
DATASETS = { | ||
"mtat": MagnaTagATune, | ||
"fma": FreeMusicArchive, | ||
"gtzan": GTZAN, | ||
"msd": MillionSongDataset, | ||
"nsynth_instrument": NSynthInstrument, | ||
"nsynth_pitch": NSynthPitch, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import argparse | ||
|
||
import lightning | ||
import torch | ||
from torch.utils.data import Dataset | ||
|
||
from src.architectures import resnet | ||
from src.modules.VICReg import VICReg | ||
|
||
|
||
class RandomDataset(Dataset): | ||
def __init__(self, subset, mixing, transforms) -> None: | ||
self.transforms = transforms | ||
|
||
def __getitem__(self, index: int): | ||
x = torch.rand(3, 128, 128, requires_grad=True) | ||
y = torch.rand(3, 128, 128, requires_grad=True) | ||
z = torch.rand(1, requires_grad=True) | ||
return (x, y), z | ||
|
||
def __len__(self) -> int: | ||
return 10 | ||
|
||
|
||
def test_train(): | ||
args = argparse.Namespace( | ||
batch_size=2, | ||
cov_coeff=1.0, | ||
devices=1, | ||
epochs=1, | ||
f_max=1.0, | ||
f_min=1.0, | ||
hop_length=1, | ||
mixing=False, | ||
n_fft=1, | ||
n_samples=2, | ||
normalize=False, | ||
num_workers=0, | ||
prefetch_factor=None, | ||
projector="2048-2-2048", | ||
sample_rate=3, | ||
sim_coeff=1.0, | ||
std_coeff=1.0, | ||
strategy="auto", | ||
weight_decay=1e-9, | ||
win_length=1, | ||
base_lr=1e-3, | ||
) | ||
|
||
backbone = resnet(pretrained=False) | ||
dataset = RandomDataset | ||
model = VICReg(args=args, dataset=dataset, backbone=backbone) | ||
|
||
trainer = lightning.Trainer(max_epochs=1) | ||
trainer.fit(model) | ||
|
||
assert trainer.state.finished |