Commit 7c09c7fa authored by Alexander Fuchs's avatar Alexander Fuchs
Browse files

Merge branch 'master' of git.spsc.tugraz.at:fuchs/kaggle_birdcall

parents 26ea3f7b ecc32797
config:
HOME=/home/TUG/fuchs-tug
PATH=/home/TUG/fuchs-tug/miniconda3/envs/tensorflow_2_2/bin:/home/TUG/fuchs-tug/miniconda3/condabin:/home/TUG/fuchs-tug/miniconda3/bin:/home/TUG/fuchs-tug/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
LD_LIBRARY_PATH=
name: tensorflow_2_2
channels:
- defaults
......@@ -181,5 +173,4 @@ dependencies:
- zlib=1.2.11=h7b6447c_3
- pip:
- parameterized==0.7.4
prefix: /home/TUG/fuchs-tug/miniconda3/envs/tensorflow_2_2
......@@ -86,8 +86,8 @@ def learning_rate_fn(epoch):
FLAGS = flags.FLAGS
flags.DEFINE_string('model_dir', '/tmp', 'save directory name')
flags.DEFINE_string('data_dir', '/tmp', 'data directory name')
flags.DEFINE_string('model_dir', 'models/saved_models', 'save directory name')
flags.DEFINE_string('data_dir', 'data/cornell_birdcall_recognition_mini', 'data directory name')
flags.DEFINE_integer('epochs', 300, 'number of epochs')
flags.DEFINE_integer('batch_size', 32, 'Mini-batch size')
flags.DEFINE_float('dropout_rate', 0.0, 'dropout rate for the dense blocks')
......@@ -99,18 +99,13 @@ flags.DEFINE_float('training_percentage', 90, 'Percentage of the training data u
flags.DEFINE_boolean('load_model', False, 'Bool indicating if the model should be loaded')
def main(argv):
try:
task_id = int(os.environ['SLURM_ARRAY_TASK_ID'])
except KeyError:
task_id = 0
model_save_dir = FLAGS.model_dir
data_dir = FLAGS.data_dir
print("Saving model to : " + str(model_save_dir))
......@@ -126,7 +121,7 @@ def main(argv):
training_percentage = FLAGS.training_percentage
preload_samples = FLAGS.preload_samples
model_save_dir+="_batch_size_"+str(batch_size)+"_dropout_rate_"+str(dropout_rate)+"_learning_rate_"+str(lr)+"_weight_decay_"+str(weight_decay)
model_save_dir += "_batch_size_"+str(batch_size)+"_dropout_rate_"+str(dropout_rate)+"_learning_rate_"+str(lr)+"_weight_decay_"+str(weight_decay)
ds_train = Dataset(data_dir,is_training_set = True)
n_total = ds_train.n_samples
......
"""
Row-wise micro averaged F1 score for Cornell Birdcall Identification
https://www.kaggle.com/c/birdsong-recognition/overview
code/notebook from https://www.kaggle.com/ihelon/row-wise-micro-averaged-f1-score-metric
"""
from typing import List
def row_wise_micro_averaged_f1_score(
y_true: List[str],
y_pred: List[str]
) -> float:
"""
Compute row-wise micro averaged f1 score
Parameters
----------
y_true : List[str]
Target list of strings of a space separated birds names
y_pred : List[str]
Predicted list of strings of a space separated birds names
Returns
-------
float
Row-wise micro averaged F1 score
"""
n_rows = len(y_true)
f1_score = 0.
for true_row, predicted_row in zip(y_true, y_pred):
f1_score += micro_f1_similarity(true_row, predicted_row) / n_rows
return f1_score
def micro_f1_similarity(
y_true: str,
y_pred: str
) -> float:
"""
Compute micro f1 similarity for 1 row
Parameters
----------
y_true : str
True string of a space separated birds names
y_pred : str
Predicted string of a space separated birds names
Returns
-------
float
Micro F1 similarity
0.5
"""
true_labels = y_true.split()
pred_labels = y_pred.split()
true_pos, false_pos, false_neg = 0, 0, 0
for true_elem in true_labels:
if true_elem in pred_labels:
true_pos += 1
else:
false_neg += 1
for pred_el in pred_labels:
if pred_el not in true_labels:
false_pos += 1
f1_similarity = 2 * true_pos / (2 * true_pos + false_neg + false_pos)
return f1_similarity
......@@ -98,7 +98,6 @@ class Summaries(object):
with self.summary_writers['train'].as_default():
tf.summary.scalar(key,self.lr_summaries[key].result(), step=epoch)
def reset_summaries(self):
for key in self.scalar_summaries.keys():
self.scalar_summaries[key].reset_states()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment