nkululeko 0.82.4__py3-none-any.whl → 0.83.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
nkululeko/constants.py CHANGED
@@ -1,2 +1,2 @@
1
- VERSION="0.82.4"
1
+ VERSION="0.83.0"
2
2
  SAMPLING_RATE = 16000
nkululeko/experiment.py CHANGED
@@ -23,7 +23,7 @@ from nkululeko.plots import Plots
23
23
  from nkululeko.reporting.report import Report
24
24
  from nkululeko.runmanager import Runmanager
25
25
  from nkululeko.scaler import Scaler
26
- from nkululeko.test_predictor import Test_predictor
26
+ from nkululeko.test_predictor import TestPredictor
27
27
  from nkululeko.utils.util import Util
28
28
 
29
29
 
@@ -672,7 +672,7 @@ class Experiment:
672
672
  def predict_test_and_save(self, result_name):
673
673
  model = self.runmgr.get_best_model()
674
674
  model.set_testdata(self.df_test, self.feats_test)
675
- test_predictor = Test_predictor(
675
+ test_predictor = TestPredictor(
676
676
  model, self.df_test, self.label_encoder, result_name
677
677
  )
678
678
  test_predictor.predict_and_store()
nkululeko/modelrunner.py CHANGED
@@ -2,18 +2,16 @@
2
2
 
3
3
  import pandas as pd
4
4
 
5
- from nkululeko.utils.util import Util
6
5
  from nkululeko import glob_conf
7
- import nkululeko.glob_conf as glob_conf
6
+ from nkululeko.utils.util import Util
8
7
 
9
8
 
10
9
  class Modelrunner:
11
- """
12
- Class to model one run
13
- """
10
+ """Class to model one run."""
14
11
 
15
12
  def __init__(self, df_train, df_test, feats_train, feats_test, run):
16
- """Constructor setting up the dataframes
13
+ """Constructor setting up the dataframes.
14
+
17
15
  Args:
18
16
  df_train: train dataframe
19
17
  df_test: test dataframe
nkululeko/reporter.py CHANGED
@@ -3,7 +3,6 @@
3
3
  This module contains the Reporter class which is responsible for generating reports.
4
4
  """
5
5
 
6
-
7
6
  import ast
8
7
  import glob
9
8
  import json
@@ -12,16 +11,14 @@ import math
12
11
  import matplotlib.pyplot as plt
13
12
  import numpy as np
14
13
  from scipy.stats import pearsonr
15
- from sklearn.metrics import (
16
- ConfusionMatrixDisplay,
17
- accuracy_score,
18
- classification_report,
19
- confusion_matrix,
20
- mean_absolute_error,
21
- mean_squared_error,
22
- r2_score,
23
- recall_score,
24
- )
14
+ from sklearn.metrics import ConfusionMatrixDisplay
15
+ from sklearn.metrics import accuracy_score
16
+ from sklearn.metrics import classification_report
17
+ from sklearn.metrics import confusion_matrix
18
+ from sklearn.metrics import mean_absolute_error
19
+ from sklearn.metrics import mean_squared_error
20
+ from sklearn.metrics import r2_score
21
+ from sklearn.metrics import recall_score
25
22
  from sklearn.utils import resample
26
23
 
27
24
  import nkululeko.glob_conf as glob_conf
@@ -70,11 +67,9 @@ class Reporter:
70
67
  else:
71
68
  # regression experiment
72
69
  if self.measure == "mse":
73
- self.result.test = mean_squared_error(
74
- self.truths, self.preds)
70
+ self.result.test = mean_squared_error(self.truths, self.preds)
75
71
  elif self.measure == "mae":
76
- self.result.test = mean_absolute_error(
77
- self.truths, self.preds)
72
+ self.result.test = mean_absolute_error(self.truths, self.preds)
78
73
  elif self.measure == "ccc":
79
74
  self.result.test = self.ccc(self.truths, self.preds)
80
75
  if math.isnan(self.result.test):
@@ -115,7 +110,7 @@ def plot_per_speaker(self, result_df, plot_name, function):
115
110
  Args:
116
111
  * result_df: a pandas dataframe with columns: preds, truths and speaker
117
112
  * plot_name: a string with the name of the plot
118
- * function: a string with the function to use for each speaker,
113
+ * function: a string with the function to use for each speaker,
119
114
  can be 'mode' or 'mean'
120
115
 
121
116
  Returns:
@@ -185,8 +180,7 @@ def plot_per_speaker(self, result_df, plot_name, function):
185
180
  reg_res = f", {self.MEASURE}: {self.result.test:.3f}"
186
181
 
187
182
  if epoch != 0:
188
- plt.title(
189
- f"Confusion Matrix, UAR: {uar:.3f}{reg_res}, Epoch: {epoch}")
183
+ plt.title(f"Confusion Matrix, UAR: {uar:.3f}{reg_res}, Epoch: {epoch}")
190
184
  else:
191
185
  plt.title(f"Confusion Matrix, UAR: {uar:.3f}{reg_res}")
192
186
  img_path = f"{fig_dir}{plot_name}.{self.format}"
@@ -265,8 +259,7 @@ def plot_per_speaker(self, result_df, plot_name, function):
265
259
  import imageio
266
260
 
267
261
  fig_dir = self.util.get_path("fig_dir")
268
- filenames = glob.glob(
269
- fig_dir + f"{self.util.get_plot_name()}*_?_???_cnf.png")
262
+ filenames = glob.glob(fig_dir + f"{self.util.get_plot_name()}*_?_???_cnf.png")
270
263
  images = []
271
264
  for filename in filenames:
272
265
  images.append(imageio.imread(filename))
@@ -322,8 +315,7 @@ def plot_per_speaker(self, result_df, plot_name, function):
322
315
  var_pred = np.var(prediction, 0)
323
316
  v_pred = prediction - mean_pred
324
317
  v_gt = ground_truth - mean_gt
325
- cor = sum(v_pred * v_gt) / \
326
- (np.sqrt(sum(v_pred**2)) * np.sqrt(sum(v_gt**2)))
318
+ cor = sum(v_pred * v_gt) / (np.sqrt(sum(v_pred**2)) * np.sqrt(sum(v_gt**2)))
327
319
  sd_gt = np.std(ground_truth)
328
320
  sd_pred = np.std(prediction)
329
321
  numerator = 2 * cor * sd_gt * sd_pred
@@ -55,6 +55,7 @@ class Reporter:
55
55
  self.run = run
56
56
  self.epoch = epoch
57
57
  self.__set_measure()
58
+ self.filenameadd = ""
58
59
  self.cont_to_cat = False
59
60
  if len(self.truths) > 0 and len(self.preds) > 0:
60
61
  if self.util.exp_is_classification():
@@ -206,7 +207,7 @@ class Reporter:
206
207
  f"Confusion Matrix, UAR: {uar_str} "
207
208
  + f"(+-{up_str}/{low_str}) {reg_res}"
208
209
  )
209
- img_path = f"{fig_dir}{plot_name}.{self.format}"
210
+ img_path = f"{fig_dir}{plot_name}{self.filenameadd}.{self.format}"
210
211
  plt.savefig(img_path)
211
212
  fig.clear()
212
213
  plt.close(fig)
@@ -228,14 +229,17 @@ class Reporter:
228
229
  )
229
230
  # print(rpt)
230
231
  self.util.debug(rpt)
231
- file_name = f"{res_dir}{self.util.get_exp_name()}_conf.txt"
232
+ file_name = f"{res_dir}{self.util.get_exp_name()}{self.filenameadd}_conf.txt"
232
233
  with open(file_name, "w") as text_file:
233
234
  text_file.write(rpt)
234
235
 
236
+ def set_filename_add(self, my_string):
237
+ self.filenameadd = f"_{my_string}"
238
+
235
239
  def print_results(self, epoch):
236
240
  """Print all evaluation values to text file."""
237
241
  res_dir = self.util.get_path("res_dir")
238
- file_name = f"{res_dir}{self.util.get_exp_name()}_{epoch}.txt"
242
+ file_name = f"{res_dir}{self.util.get_exp_name()}_{epoch}{self.filenameadd}.txt"
239
243
  if self.util.exp_is_classification():
240
244
  labels = glob_conf.labels
241
245
  try:
@@ -1,21 +1,25 @@
1
- """ test_predictor.py
1
+ """test_predictor.py.
2
+
2
3
  Predict targets from a model and save as csv file.
3
4
 
4
5
  """
5
6
 
6
- import nkululeko.glob_conf as glob_conf
7
- from nkululeko.utils.util import Util
7
+ import ast
8
+
9
+ import numpy as np
8
10
  import pandas as pd
11
+ from sklearn.preprocessing import LabelEncoder
12
+
9
13
  from nkululeko.data.dataset import Dataset
10
14
  from nkululeko.feature_extractor import FeatureExtractor
15
+ import nkululeko.glob_conf as glob_conf
11
16
  from nkululeko.scaler import Scaler
12
- import numpy as np
13
- from sklearn.preprocessing import LabelEncoder
17
+ from nkululeko.utils.util import Util
14
18
 
15
19
 
16
- class Test_predictor:
20
+ class TestPredictor:
17
21
  def __init__(self, model, orig_df, labenc, name):
18
- """Constructor setting up name and configuration"""
22
+ """Constructor setting up name and configuration."""
19
23
  self.model = model
20
24
  self.orig_df = orig_df
21
25
  self.label_encoder = labenc
@@ -49,7 +53,14 @@ class Test_predictor:
49
53
  df[self.target] = labelenc.inverse_transform(predictions.tolist())
50
54
  df.to_csv(self.name)
51
55
  else:
56
+ test_dbs = ast.literal_eval(glob_conf.config["DATA"]["tests"])
57
+ test_dbs_string = "_".join(test_dbs)
52
58
  predictions = self.model.get_predictions()
59
+ report = self.model.predict()
60
+ report.set_filename_add(f"test-{test_dbs_string}")
61
+ self.util.print_best_results([report])
62
+ report.plot_confmatrix(self.util.get_plot_name(), 0)
63
+ report.print_results(0)
53
64
  # print(predictions)
54
65
  # df = pd.DataFrame(index=self.orig_df.index)
55
66
  # df["speaker"] = self.orig_df["speaker"]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: nkululeko
3
- Version: 0.82.4
3
+ Version: 0.83.0
4
4
  Summary: Machine learning audio prediction experiments based on templates
5
5
  Home-page: https://github.com/felixbur/nkululeko
6
6
  Author: Felix Burkhardt
@@ -333,6 +333,10 @@ F. Burkhardt, Johannes Wagner, Hagen Wierstorf, Florian Eyben and Björn Schulle
333
333
  Changelog
334
334
  =========
335
335
 
336
+ Version 0.83.0
337
+ --------------
338
+ * test module now prints out reports
339
+
336
340
  Version 0.82.4
337
341
  --------------
338
342
  * fixed bug in wavlm
@@ -2,31 +2,31 @@ nkululeko/__init__.py,sha256=62f8HiEzJ8rG2QlTFJXUCMpvuH3fKI33DoJSj33mscc,63
2
2
  nkululeko/aug_train.py,sha256=YhuZnS_WVWnun9G-M6g5n6rbRxoVREz6Zh7k6qprFNQ,3194
3
3
  nkululeko/augment.py,sha256=4MG0apTAG5RgkuJrYEjGgDdbodZWi_HweSPNI1JJ5QA,3051
4
4
  nkululeko/cacheddataset.py,sha256=lIJ6hUo5LoxSrzXtWV8mzwO7wRtUETWnOQ4ws2XfL1E,969
5
- nkululeko/constants.py,sha256=kp-581CniawYq15MP-eOYf2iEPJCoCdhJ8W3kRUgPhs,39
5
+ nkululeko/constants.py,sha256=NNx53OyRpXv780Ycj6Cdw4bDJfdvEn180CaN2PcmQkY,39
6
6
  nkululeko/demo.py,sha256=55kNFA2helMhOxD4yZuKg1JWDtlUUpxm-6uAnroIydI,3264
7
7
  nkululeko/demo_feats.py,sha256=sAeGFojhEj9WEDFtG3SzPBmyYJWLF2rkbpp65m8Ujo4,2025
8
8
  nkululeko/demo_predictor.py,sha256=-ggSHc3DXxRzjzcGB4qFBOMvKsfUdTkkde50BDrS9dA,4755
9
- nkululeko/experiment.py,sha256=CSEvQxK2_tzJyND5sUHQSc6MkRp1g6EVam8JX8txqps,29576
9
+ nkululeko/experiment.py,sha256=SRcB0ni0XLK910NSWTyRAe-Eoa6fVSKDCJlDJKyCzMc,29574
10
10
  nkululeko/explore.py,sha256=2wdoGRqldvsN1zCiWk0quSDgHHHUoF2UZOWQ1r-2OLM,2310
11
11
  nkululeko/export.py,sha256=mHeEAAmtZuxdyebLlbSzPrHSi9OMgJHbk35d3DTxRBc,4632
12
12
  nkululeko/feature_extractor.py,sha256=8mssYKmo4LclVI-hiLmJEDZ0ZPyDavFG2YwtXcrGzwM,3976
13
13
  nkululeko/file_checker.py,sha256=LoLnL8aHpW-axMQ46qbqrManTs5otG9ShpEZuz9iRSk,3474
14
14
  nkululeko/filter_data.py,sha256=w-X2mhKdYr5DxDIz50E5yzO6Jmzk4jjDBoXsgOOVtcA,7222
15
15
  nkululeko/glob_conf.py,sha256=iHiVSxDYgmYwdx6z0HuGUMSWrfZfufPHxHb60q2dLRY,453
16
- nkululeko/modelrunner.py,sha256=GuYsmUGSmJ0QxXxR8k0TZ47IDMtdGIMbm5nMq4Ix6tU,9335
16
+ nkululeko/modelrunner.py,sha256=GwDXcE2gDQXat4W0-HhHQ1BcUNCRBXMBQ4QycfHp_5c,9288
17
17
  nkululeko/multidb.py,sha256=fG3VukEWP1vreVN4gB1IRXxwwg4jLftsSEYtu0o1f78,5634
18
18
  nkululeko/nkuluflag.py,sha256=FCetTfgH69u4AwENgeCKVi3vBIR10Di67SfbupGQqfc,3354
19
19
  nkululeko/nkululeko.py,sha256=Kn3s2E3yyH8cJ7z6lkMxrnqtCxTu7-qfe9Zr_ONTD5g,1968
20
20
  nkululeko/plots.py,sha256=K88ZRPFGX_r03BT742H06Dde20xZYdltv7dxjgUiAFA,23025
21
21
  nkululeko/predict.py,sha256=sF091sSSLnEWcISx9ZcULLie3tY5XeFsQJd6b3vrxFg,2409
22
- nkululeko/reporter.py,sha256=mCy8er8z4e5hJ7XbOyy6BgZYZM6Lz-EKXHh4zlT0Zc8,12427
22
+ nkululeko/reporter.py,sha256=8mlIaKep4hM-tdRv8t98tK80rx3zOmVGXSORhiPc3as,12483
23
23
  nkululeko/resample.py,sha256=3WbxkwgyTe_fW38046Rjxk3knOkFdhqn2C4nfhbUurQ,2287
24
24
  nkululeko/runmanager.py,sha256=eTM1DNQKt1lxYhzt4vZyZluPXW9sWlIJHNQzex4lkJU,7624
25
25
  nkululeko/scaler.py,sha256=4nkIqoajkIkuTPK0Z02ifMN_awl6fP_i-GBYdoGYgGM,4101
26
26
  nkululeko/segment.py,sha256=YLKckX44tbvTb3LrdgYw9X4guzuF27sutl92z9DkpZU,4835
27
27
  nkululeko/syllable_nuclei.py,sha256=Sky-C__MeUDaxqHnDl2TGLLYOYvsahD35TUjWGeG31k,10047
28
28
  nkululeko/test.py,sha256=JRoLgqQJEhAIGetw-qlOUihSTTQ7O8DYafB0FlQESIQ,1525
29
- nkululeko/test_predictor.py,sha256=L2njNydYTX85_7RhHjfk1MN4JwE21tsBVuX4fY-XEjc,2753
29
+ nkululeko/test_predictor.py,sha256=L8XKrIweTf-oKeaGuDw_ZhtvzRUxFuWmOhva6jgf7-s,3148
30
30
  nkululeko/augmenting/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
31
31
  nkululeko/augmenting/augmenter.py,sha256=XAt0dpmlnKxqyysqCgV3rcz-pRIvOz7rU7dmGDCVAzs,2905
32
32
  nkululeko/augmenting/randomsplicer.py,sha256=Z5rxdKKUpuncLWuTS6xVfVKUeVbeiYU_dLRHQ5fcg4Y,2669
@@ -95,7 +95,7 @@ nkululeko/reporting/defines.py,sha256=IsY1YgKRMaABpylVKjBJgJ5bNCEbGCVA_E6pivraqS
95
95
  nkululeko/reporting/latex_writer.py,sha256=qiCRSmB4KOD_za4oHu5x-PhwjZohzfo8wecMOwlXZwc,1886
96
96
  nkululeko/reporting/report.py,sha256=W0rcigDdjBvxZQ3pZja_gvToILYvaZ1BFtnN2qFRfYI,1060
97
97
  nkululeko/reporting/report_item.py,sha256=siWeGNgo4bAE46YBMNcsdf3jTMTy76BO9Fi6DTvDig4,533
98
- nkululeko/reporting/reporter.py,sha256=wwpY0gA-8E8d26XH3DSmXm3X0BkBw2Y0YyEiUiNU_Y0,12670
98
+ nkululeko/reporting/reporter.py,sha256=eLqwKEUTQ7v5CedzhZP2617qmXGcvi0rjyyFLOBdxtQ,12841
99
99
  nkululeko/reporting/result.py,sha256=nSN5or-Py2GPRWHkWpGRh7UCi1W0er7WLEHz8fYLk-A,742
100
100
  nkululeko/segmenting/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
101
101
  nkululeko/segmenting/seg_inaspeechsegmenter.py,sha256=pmLHuXsaqvcdYxB4PSW9l1mbQWZZBJFhi_CGabqydas,1947
@@ -104,8 +104,8 @@ nkululeko/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
104
104
  nkululeko/utils/files.py,sha256=UiGAtZRWYjHSvlmPaTMtzyNNGE6qaLaxQkybctS7iRM,4021
105
105
  nkululeko/utils/stats.py,sha256=1yUq0FTOyqkU8TwUocJRYdJaqMU5SlOBBRUun9STo2M,2829
106
106
  nkululeko/utils/util.py,sha256=_Z6OMJ3f-8TdETW9eqJYY5hwNRS5XCt9azzRnqoTTZE,12330
107
- nkululeko-0.82.4.dist-info/LICENSE,sha256=0zGP5B_W35yAcGfHPS18Q2B8UhvLRY3dQq1MhpsJU_U,1076
108
- nkululeko-0.82.4.dist-info/METADATA,sha256=iVA5K6coH1oLy918OgAZoq6wqFXcfYIcuZBV1dOnI2g,35950
109
- nkululeko-0.82.4.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
110
- nkululeko-0.82.4.dist-info/top_level.txt,sha256=DPFNNSHPjUeVKj44dVANAjuVGRCC3MusJ08lc2a8xFA,10
111
- nkululeko-0.82.4.dist-info/RECORD,,
107
+ nkululeko-0.83.0.dist-info/LICENSE,sha256=0zGP5B_W35yAcGfHPS18Q2B8UhvLRY3dQq1MhpsJU_U,1076
108
+ nkululeko-0.83.0.dist-info/METADATA,sha256=20S7IpMbLE7irV0ikdaFNfdqdBEEywH7jjlJwur8smA,36018
109
+ nkululeko-0.83.0.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
110
+ nkululeko-0.83.0.dist-info/top_level.txt,sha256=DPFNNSHPjUeVKj44dVANAjuVGRCC3MusJ08lc2a8xFA,10
111
+ nkululeko-0.83.0.dist-info/RECORD,,