Skip to content

Commit

Permalink
Added environment.yml. Updated README to reflect using environment.ym…
Browse files Browse the repository at this point in the history
…l. Updated code to work with tf2. Removed some unused dependencies.
  • Loading branch information
mdfirman committed Jun 24, 2021
1 parent 325f573 commit 2a9dcd9
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 34 deletions.
33 changes: 15 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,29 @@ An overview of predictions of biotic and anthropogenic activity on recordings of

## Requirements

The system has been tested using:
The system has been tested using the dependencies in `environment.yml`. Our code works with python 3.

- `Ubuntu 16.04`
- `python 2.7`
- The `anaconda` distribution (see [here](https://www.anaconda.com/download/) for download details).

Run the following commands to get suitable versions of the required libraries:

pip install -r https://raw.githubusercontent.com/Lasagne/Lasagne/v0.1/requirements.txt
pip install Lasagne==0.1
pip install --upgrade https://github.com/Lasagne/Lasagne/archive/master.zip
pip install nolearn
pip install librosa
pip install easydict
pip install tqdm
pip install git+git://github.com/mdfirman/ml_helpers.git@master

For training and testing we used a 2GB NVIDIA GPU. The computation requirements for classification are pretty low though, so a GPU should not be required.
You can create an environment with all the dependencies installed using:

```bash
conda env create -f environment.yml -n citynet
conda activate citynet
```

## How to classify a new audio file with CityNet

- Run `python demo.py` to classify an example audio file.
- Predictions should be saved in the folder `demo`.
- Your newly-created file `demo/prediction.pdf` should look identical to the provided file `demo/reference_prediction.pdf`:

## How to classify multiple audio files

You can run CityNet on a folder of audio files with:

Editing `demo.py` should allow you to classify your own audio files.
```bash
python multi_predict.py path/to/audio/files
```

## Hardware requirements

For training and testing we used a 2GB NVIDIA GPU. The computation requirements for classification are pretty low though, so a GPU should not be required.
4 changes: 2 additions & 2 deletions demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import zipfile
import numpy as np
import pickle
from six.moves import urllib
import urllib
import matplotlib.pyplot as plt
import sys
sys.path.append('lib')
Expand Down Expand Up @@ -42,7 +42,7 @@
for classifier_type in ['biotic', 'anthrop']:

with open('tf_models/%s/network_opts.yaml' % classifier_type) as f:
options = yaml.load(f)
options = yaml.full_load(f)

model_path = 'tf_models/%s/weights_99.pkl-1' % classifier_type

Expand Down
9 changes: 4 additions & 5 deletions lib/train_helpers.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import numpy as np
import os
import sys
import yaml
import collections
import tensorflow as tf
from tensorflow import layers
from tensorflow.contrib import slim
import tensorflow.compat.v1 as tf
import tf_slim as slim
import minibatch_generators as mbg


Expand Down Expand Up @@ -125,6 +122,8 @@ def __iter__(self): ##, num_per_class, seed=None
def create_net(SPEC_HEIGHT, HWW_X, LEARN_LOG, NUM_FILTERS,
WIGGLE_ROOM, CONV_FILTER_WIDTH, NUM_DENSE_UNITS, DO_BATCH_NORM):

tf.compat.v1.disable_eager_execution()

channels = 4
net = collections.OrderedDict()

Expand Down
6 changes: 1 addition & 5 deletions multi_predict.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import os
import sys
import yaml
import zipfile
import numpy as np
import pickle
from six.moves import urllib
import matplotlib.pyplot as plt
import sys
sys.path.append('lib')

Expand All @@ -29,7 +25,7 @@
for classifier_type in ['biotic', 'anthrop']:

with open('tf_models/%s/network_opts.yaml' % classifier_type) as f:
options = yaml.load(f)
options = yaml.full_load(f)

model_path = 'tf_models/%s/weights_99.pkl-1' % classifier_type

Expand Down
5 changes: 1 addition & 4 deletions prediction/tf_classifier.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import os
import sys
import yaml
import numpy as np
from time import time
import pickle
from collections import namedtuple

import tensorflow as tf
import tensorflow.compat.v1 as tf
import librosa
from librosa.feature import melspectrogram
from scipy.io import wavfile
Expand Down

0 comments on commit 2a9dcd9

Please sign in to comment.