Skip to content

Commit

Permalink
Version 2.2.5
Browse files Browse the repository at this point in the history
  • Loading branch information
Labbeti committed Jul 20, 2021
1 parent acbb7d5 commit a80c742
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 25 deletions.
39 changes: 31 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ AudioSet (ADS) and Primate Vocalize Corpus (PVC) cannot be installed automatical
[comment]: <> (TODO : For PVC install !)

## Usage
The main scripts available are in directory ```standalone``` :
The main scripts available are in ```standalone``` directory :
```
standalone
├── deep_co_training.py
Expand All @@ -82,27 +82,49 @@ The code use Hydra for parsing args. The syntax of setting an argument is "name=

Example 1 : MixMatch on ESC10
```bash
python mixmatch.py dataset=esc10
python mixmatch.py data=esc10
```

Example 2 : Supervised+Weak on GSC
```bash
python supervised.py dataset=gsc expt.augm_train=weak bsize=256 epochs=300
python supervised.py data=gsc expt.augm_train=weak bsize=256 epochs=300
```

Example 3 : FixMatch+MixUp on UBS8K
```bash
python fixmatch.py dataset=ubs8K dataset.root="../data/UBS8K" expt=fixmatch_mixup bsize_s=128 bsize_u=128 epochs=300
python fixmatch.py data=ubs8K expt=fixmatch_mixup bsize_s=128 bsize_u=128 epochs=300
```
(note: default folds used are in "config/dataset/ubs8k.yaml")
(note: default folds used for UBS8K are in "config/data/ubs8k.yaml")

Example 4 : ReMixMatch on CIFAR-10
```bash
python remixmatch.py data=cifar10 model.n_input_channels=3
```

## List of main arguments

| Name | Description | Values | Default |
| --- | --- | --- | --- |
| data | Dataset used | ads, cifar10, esc10, fsd50k, gsc, pvc, ubs8k | esc10 |
| expt | Training method (experiment) used | *(depends of the python script, see the filenames in config/expt/ folder)* | *(depends of the python script)* |
| model | Pytorch model to use | mobilenetv1, mobilenetv2, vgg, wideresnet28 | wideresnet28 |
| optim | Optimizer used | adam, sgd | adam |
| sched | Learning rate scheduler | cosine, softcosine, none | softcosine |
| epochs | Number of training epochs | int | 1 |
| bsize | Batch size in SUP methods | int | 60 |
| ratio | Ratio of the training data used in SUP methods | float in [0, 1] | 1.0 |
| bsize_s | Batch size of supervised part in SSL methods | int | 30 |
| bsize_u | Batch size of unsupervised part in SSL methods | int | 30 |
| ratio_s | Ratio of the supervised training data used in SSL methods | float in [0, 1] | 0.1 |
| ratio_u | Ratio of the unsupervised training data used in SSL methods | float in [0, 1] | 0.9 |


## SSLH Package overview
```
sslh
├── callbacks
├── datamodules
│ ├── fully_supervised
│ ├── partial_supervised
│ ├── supervised
│ └── semi_supervised
├── datasets
├── expt
Expand All @@ -129,7 +151,7 @@ This repository has been created by Etienne Labbé (Labbeti on Github).

It contains also some code from the following authors :
- Léo Cancès (leocances on github)
- For AudioSet, ESC10, GSC, PVC and UBS8K datasets.
- For AudioSet, ESC10, GSC, PVC and UBS8K datasets base code.
- Qiuqiang Kong (qiuqiangkong on Github)
- For MobileNetV1 & V2 model implementation from [PANN](https://github.com/qiuqiangkong/audioset_tagging_cnn).

Expand Down Expand Up @@ -161,5 +183,6 @@ It contains also some code from the following authors :
| _s | Supervised |
| sched | Scheduler |
| SSL | Semi-Supervised Learning |
| SUP | Supervised Learning |
| _u | Unsupervised |
| UBS8K | UrbanSound8K dataset |
2 changes: 1 addition & 1 deletion config/data/gsc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ download: true
transform:
n_mels: 64
hop_length: 512
n_fft: 2048
n_fft: 2048
1 change: 1 addition & 0 deletions config/sched/cosine.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# @package _group_

# math.cos(7.0 / 16.0 * math.pi * min(step / n_steps, 1.0))
name: "CosineScheduler"
acronym: "cosine"
on_epoch: ${data.log_on_epoch}
1 change: 1 addition & 0 deletions config/sched/softcosine.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# @package _group_

# 0.5 * (1.0 + math.cos(math.pi * min(step / n_steps, 1.0)))
name: "SoftCosineScheduler"
acronym: "softcosine"
on_epoch: ${data.log_on_epoch}
1 change: 0 additions & 1 deletion post_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ for dir in logs boards
do
for dataset in ADS CIFAR10 ESC10 FSD50K GSC PVC UBS8K
do
echo "Building directory '$root/$dir/$dataset' ..."
mkdir -p $root/$dir/$dataset
done
done
Expand Down
2 changes: 1 addition & 1 deletion sslh/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
__email__ = 'etienne.labbe31@gmail.com'
__maintainer__ = 'Etienne Labbé'
__status__ = 'Released'
__version__ = '2.2.4'
__version__ = '2.2.5'
5 changes: 3 additions & 2 deletions sslh/datasets/esc50.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ def __init__(
download: bool = False,
transform: Module = None
) -> None:

super().__init__()

self.root = root
Expand Down Expand Up @@ -160,8 +159,10 @@ def download(self) -> None:
print('Dataset already downloaded and verified.')

else:
if not os.path.isdir(self.root):
os.makedirs(self.root)

archive_path = os.path.join(self.root, FOLDER_IN_ARCHIVE + '.zip')

download_url(self.url, self.root)
extract_archive(archive_path, self.root)

Expand Down
18 changes: 10 additions & 8 deletions sslh/datasets/ubs8k.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,24 @@


class URBANSOUND8K(Dataset):
N_CLASSES = 10
ROOT_DNAME: str = 'UrbanSound8K'
N_CLASSES: int = 10

def __init__(self, root: str, folds: List[int], resample_sr: int = 22050):
def __init__(self, root: str, folds: List[int], resample_sr: int = 22050) -> None:
"""
UBS8K dataset.
:param root: The directory path to the dataset root.
:param folds: The folds to use.
:param resample_sr:
:param resample_sr: The resample rate of the waveform.
"""
super().__init__()
self.root = root
self.folds = list(folds)
self.resample_sr = resample_sr

self.meta = self._load_metadata()
self.wav_dir = os.path.join(root, 'UrbanSound8K', 'audio')
self.wav_dir = os.path.join(root, self.ROOT_DNAME, 'audio')

def __getitem__(self, idx) -> Tuple[Tensor, int]:
filename = self.meta['filename'][idx]
Expand All @@ -45,10 +46,10 @@ def __len__(self) -> int:
return len(self.meta['filename'])

def _load_metadata(self) -> Dict[str, list]:
csv_path = os.path.join(self.root, 'UrbanSound8K', 'metadata', 'UrbanSound8K.csv')
csv_path = os.path.join(self.root, self.ROOT_DNAME, 'metadata', 'UrbanSound8K.csv')

with open(csv_path) as f:
lines = f.read().splitlines()
with open(csv_path) as file:
lines = file.read().splitlines()
lines = lines[1:] # remove the header

info = {'filename': [], 'fold': [], 'target': []}
Expand All @@ -69,7 +70,8 @@ def _to_mono(self, waveform: Tensor) -> Tensor:
if len(waveform.shape) == 2:
if waveform.shape[0] == 1:
return waveform
return waveform.mean(dim=0)
else:
return waveform.mean(dim=0)
else:
raise ValueError(
f'waveform tensor should be of shape (channels, time). currently is of shape {waveform.shape}'
Expand Down
4 changes: 3 additions & 1 deletion sslh/transforms/cifar10.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

import torch

from torchvision.transforms import ToTensor, Normalize
from typing import Callable, List, Optional

Expand Down Expand Up @@ -33,7 +35,7 @@ def get_transform_cifar10(


def get_target_transform_cifar10(smooth: Optional[float] = None) -> Callable:
return OneHot(N_CLASSES, smooth)
return OneHot(N_CLASSES, smooth, dtype=torch.float)


def get_self_transform_cifar10(**kwargs) -> Callable:
Expand Down
6 changes: 3 additions & 3 deletions sslh/utils/average_pred.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@


class AveragePred:
def __init__(self, history: int = 128):
def __init__(self, history: int = 128) -> None:
self.history = history
self.preds = []
self.cur_idx = 0

def reset(self):
def reset(self) -> None:
"""
Reset the history.
"""
self.preds = []
self.cur_idx = 0

def add_pred(self, pred: Tensor):
def add_pred(self, pred: Tensor) -> None:
"""
Add a batch of predictions of shape (bsize, n_classes) to the history for computing the classes distributions.
"""
Expand Down

0 comments on commit a80c742

Please sign in to comment.