Skip to content

Commit

Permalink
Merge pull request #10 from harritaylor/dev
Browse files Browse the repository at this point in the history
Dev merge
  • Loading branch information
Harri Taylor authored Feb 24, 2020
2 parents f5ec66c + e392ec4 commit 9331251
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 287 deletions.
202 changes: 0 additions & 202 deletions LICENSE

This file was deleted.

36 changes: 14 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,27 @@
# Torch VGGish
A PyTorch port of [VGGish](https://github.com/tensorflow/models/tree/master/research/audioset)<sup>1</sup>,
# VGGish
A `torch`-compatible port of [VGGish](https://github.com/tensorflow/models/tree/master/research/audioset)<sup>[1]</sup>,
a feature embedding frontend for audio classification models. The weights are ported directly from the tensorflow model, so embeddings created using `torchvggish` will be identical.

## Quick start
There are two options: you can install the last stable version from pypi, or clone this repo and install.
```shell script
# optional: create virtual env
cd torchvggish && python3 -m venv .env
source activate .env/bin/activate

pip install -i https://test.pypi.org/simple/ torchvggish==0.1

# OR get the latest version
git clone [email protected]:harritaylor/torchvggish.git
pip install -r requirements.txt
```
## Usage
Barebones example of creating embeddings from an `example` wav file:

```python
from torchvggish import vggish, vggish_input
import torch

model = torch.hub.load('harritaylor/torchvggish', 'vggish')
model.eval()

# Initialise model and download weights
embedding_model = vggish()
embedding_model.eval()
# Download an example audio file
import urllib
url, filename = ("http://soundbible.com/grab.php?id=1698&type=wav", "bus_chatter.wav")
try: urllib.URLopener().retrieve(url, filename)
except: urllib.request.urlretrieve(url, filename)

example = vggish_input.wavfile_to_examples("example.wav")
embeddings = embedding_model.forward(example)
model.forward(filename)
```

<hr>
1. S. Hershey et al., ‘CNN Architectures for Large-Scale Audio Classification’,\
[1] S. Hershey et al., ‘CNN Architectures for Large-Scale Audio Classification’,\
in International Conference on Acoustics, Speech and Signal Processing (ICASSP),2017\
Available: https://arxiv.org/abs/1609.09430, https://ai.google/research/pubs/pub45611

Expand Down
15 changes: 15 additions & 0 deletions hubconf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
dependencies = ['torch', 'numpy', 'resampy', 'soundfile']

from torchvggish.vggish import VGGish

model_urls = {
'vggish': 'https://github.com/harritaylor/torchvggish/'
'releases/download/v0.1/vggish-10086976.pth',
'pca': 'https://github.com/harritaylor/torchvggish/'
'releases/download/v0.1/vggish_pca_params-970ea276.pth'
}


def vggish(**kwargs):
model = VGGish(urls=model_urls, **kwargs)
return model
10 changes: 0 additions & 10 deletions requirements.txt

This file was deleted.

25 changes: 0 additions & 25 deletions setup.py

This file was deleted.

Binary file added test.wav
Binary file not shown.
5 changes: 0 additions & 5 deletions torchvggish/__init__.py

This file was deleted.

Loading

0 comments on commit 9331251

Please sign in to comment.