Skip to content

Commit

Permalink
update tensorflow
Browse files Browse the repository at this point in the history
  • Loading branch information
gferraro committed May 8, 2023
1 parent f21f9d0 commit f6900e1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
13 changes: 11 additions & 2 deletions Melt/identify_bird.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def load_samples(
n_mels=80,
fmin=50,
fmax=11000,
channels=1,
):
logging.debug(
"Loading samples with length %s stride %s hop length %s and mean_sub %s mfcc %s break %s htk %s n mels %s fmin %s fmax %s",
Expand Down Expand Up @@ -99,7 +100,10 @@ def load_samples(
strides_per = math.ceil(segment_length / 2.0 / stride) + 1
mel_samples = mel_samples[:-strides_per]
break

mel = librosa.power_to_db(mel, ref=np.max)
mel = tf.expand_dims(mel, axis=2)

if use_mfcc:
mfcc = librosa.feature.mfcc(
y=data,
Expand All @@ -117,15 +121,16 @@ def load_samples(
mel_m = tf.reduce_mean(mel, axis=1)
mel_m = tf.expand_dims(mel_m, axis=1)
mel = mel - mel_m

if channels > 1:
mel = tf.repeat(mel, channels, axis=2)
mel_samples.append(mel)
i += 1
return np.array(mel_samples), len(frames) / sr


def load_model(model_path):
logging.debug("Loading %s", model_path)
model_path = Path(model_path)
logging.debug("Loading %s", str(model_path))
model = tf.keras.models.load_model(
str(model_path),
compile=False,
Expand All @@ -152,6 +157,7 @@ def classify(file, model_file):
htk = meta.get("htk", False)
fmin = meta.get("fmin", 50)
fmax = meta.get("fmax", 11000)
channels = meta.get("channels", 1)

samples, length = load_samples(
file,
Expand All @@ -165,7 +171,10 @@ def classify(file, model_file):
n_mels=n_mels,
fmin=fmin,
fmax=fmax,
channels=channels,
)
if len(samples) == 0:
return [], length
predictions = model.predict(samples, verbose=0)
tracks = []
start = 0
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ h5py~=3.1.0
librosa~=0.9.2
numpy~=1.23.0
scipy~=1.9.3
tensorflow~=2.10.1
tensorflow~=2.11.0
Wave~=0.0.2
numba
argparse==1.4.0
2 changes: 1 addition & 1 deletion run
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ fi

dir=$(readlink -f "$(dirname "$source")")
filename=$(basename "$source")
docker run -it -v "$dir":/io 9f6f98e8a556 --morepork-model /io/"$2" --bird-model /io/"$3" /io/"$filename"
docker run -it -v "$dir":/io cacophony-audio --morepork-model /io/"$2" --bird-model /io/"$3" /io/"$filename"

0 comments on commit f6900e1

Please sign in to comment.