Skip to content

Commit

Permalink
fix black errors
Browse files Browse the repository at this point in the history
  • Loading branch information
parisa-zahedi committed Jun 26, 2024
1 parent 14da727 commit 477e227
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 30 deletions.
1 change: 1 addition & 0 deletions bioacoustics/classifier/data_preparation_dl.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Script to prepare train and test data to feed into a model"""

import glob
import os
import numpy as np
Expand Down
1 change: 1 addition & 0 deletions bioacoustics/classifier/data_preparation_svm.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Data preparation for SVM classifier."""

import pandas as pd
import numpy as np
import glob
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" Module that uses scikit-learn for grid search on the dropout rate """

import tensorflow as tf
from sklearn.model_selection import GridSearchCV
from scikeras.wrappers import KerasClassifier
Expand Down Expand Up @@ -62,6 +63,7 @@ def create_model(init_mode, dropout_rate, weight_constraint):

return model


if __name__ == "__main__":
parser = parse_arguments()
args = parser.parse_args()
Expand Down Expand Up @@ -125,4 +127,3 @@ def create_model(init_mode, dropout_rate, weight_constraint):
# save model
estimator = grid_result.best_estimator_
dump(estimator, args.output_dir + "best_estimator.joblib")

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" Module that uses scikit-learn for grid search on the dropout rate """

import tensorflow as tf
from sklearn.model_selection import GridSearchCV
from scikeras.wrappers import KerasClassifier
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" Module that uses scikit-learn for grid search on the dropout rate """

import tensorflow as tf
from sklearn.model_selection import GridSearchCV
from scikeras.wrappers import KerasClassifier
Expand Down
26 changes: 13 additions & 13 deletions bioacoustics/classifier/model/acoustic_model.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Script of a base class for acoustic models"""

import os
from abc import ABC
import pickle
Expand Down Expand Up @@ -28,13 +29,13 @@ def _compile(self, learning_rate):
learning_rate: float
Learning rate for adam optimizer
"""
optimizer = keras.optimizers.Adam(learning_rate=learning_rate) #, decay=0.001
optimizer = keras.optimizers.Adam(learning_rate=learning_rate) # , decay=0.001

# Compile the model
self.acoustic_model.compile(
loss="binary_crossentropy", #"categorical_crossentropy"
metrics=['accuracy'], #Recall()
optimizer=optimizer
loss="binary_crossentropy", # "categorical_crossentropy"
metrics=["accuracy"], # Recall()
optimizer=optimizer,
)

# Display model architecture summary
Expand Down Expand Up @@ -151,7 +152,6 @@ def apply_model(
self._predict(x_test)

def predict_model(self, x_test, file_path, dl_model):

"""Load a trained model and make a prediction
Parameters
Expand Down Expand Up @@ -203,17 +203,17 @@ def plot_measures(self, history, file_path, title=""):
Title of the graph
"""
# summarize history for loss
plt.plot(history.history['loss'])
plt.plot(history.history['val_loss'])
plt.title('model loss')
plt.ylabel('loss')
plt.xlabel('epoch')
plt.legend(['train', 'val'], loc='upper left')
fp_loss = os.path.join(file_path, 'loss.png')
plt.plot(history.history["loss"])
plt.plot(history.history["val_loss"])
plt.title("model loss")
plt.ylabel("loss")
plt.xlabel("epoch")
plt.legend(["train", "val"], loc="upper left")
fp_loss = os.path.join(file_path, "loss.png")
plt.savefig(fp_loss)

# convert the history.history dict to a pandas DataFrame:
hist_df = pd.DataFrame(history.history)
hist_csv_file = os.path.join(file_path, "history.csv")
with open(hist_csv_file, mode='w') as f:
with open(hist_csv_file, mode="w") as f:
hist_df.to_csv(f)
2 changes: 1 addition & 1 deletion bioacoustics/classifier/model/cnn10_model.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""A class for acoustic model with 10 nn blocks"""

from acoustic_model import AcousticModel

import tensorflow as tf
Expand Down Expand Up @@ -59,7 +60,6 @@ def _make_cnn_model(self, init_mode, dropout_rate, weight_constraint):
input_shape=input_shape,
data_format=data_format,
padding="same",

kernel_regularizer=regularizers.l2(l=0.01),
kernel_initializer=init_mode,
kernel_constraint=MaxNorm(weight_constraint),
Expand Down
22 changes: 11 additions & 11 deletions bioacoustics/feature_extraction/acoustic_features/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ def _readFeaturesFunctions(self):
featuresRefUnique[i] = str(i_feature)
# -----> Then extend to all domains
for i, domain in enumerate(self.domains):
self.featuresFunctions[
i * self.n_features : (i + 1) * self.n_features
] = featuresFunctionsUnique
self.featuresFunctions[i * self.n_features : (i + 1) * self.n_features] = (
featuresFunctionsUnique
)
self.featuresOptArguments[
i * self.n_features : (i + 1) * self.n_features
] = featuresOptArgumentsUnique
Expand Down Expand Up @@ -240,15 +240,15 @@ def _computation(self, signals, fs):
new_dictionary.update(
self.featuresOptArguments[i * self.n_features + j]
)
self.featuresValues[
i * self.n_features + j
] = self.featuresFunctions[i * self.n_features + j](
signals[i], new_dictionary
self.featuresValues[i * self.n_features + j] = (
self.featuresFunctions[i * self.n_features + j](
signals[i], new_dictionary
)
)
# Otherwise directly compute feature value.
else:
self.featuresValues[
i * self.n_features + j
] = self.featuresFunctions[i * self.n_features + j](
signals[i], self.intermValues
self.featuresValues[i * self.n_features + j] = (
self.featuresFunctions[i * self.n_features + j](
signals[i], self.intermValues
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,7 @@ def energy_kurtosis(signal, arg_dict):
E_kur = 0
else:
E_kur = (
(1 / len(signal) / 2)
* np.sum((E_u / len(signal) - E_bar) ** 4)
/ E_bar**4
(1 / len(signal) / 2) * np.sum((E_u / len(signal) - E_bar) ** 4) / E_bar**4
)
if np.isfinite(E_kur):
return E_kur
Expand Down
1 change: 1 addition & 0 deletions bioacoustics/wav_processing/chunk_wav/make_chunks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Script to make .wav files of the same length."""

import os
import glob
import argparse
Expand Down
2 changes: 1 addition & 1 deletion bioacoustics/wav_processing/condensation/extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def detect_vocalizations(

# get all indexes of dbs rows of every band that we're
# interested in
for (low, high) in freqs:
for low, high in freqs:
idx_low = (np.abs(f - low)).argmin() - 1
idx_low = 0 if idx_low < 0 else idx_low
idx_high = (np.abs(f - high)).argmin() + 1
Expand Down

0 comments on commit 477e227

Please sign in to comment.