nkululeko 0.89.2__py3-none-any.whl → 0.90.1__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/aug_train.py +6 -4
- nkululeko/augment.py +8 -6
- nkululeko/augmenting/augmenter.py +4 -4
- nkululeko/augmenting/randomsplicer.py +12 -9
- nkululeko/augmenting/randomsplicing.py +2 -3
- nkululeko/augmenting/resampler.py +9 -6
- nkululeko/autopredict/ap_age.py +4 -2
- nkululeko/autopredict/ap_arousal.py +4 -2
- nkululeko/autopredict/ap_dominance.py +3 -2
- nkululeko/autopredict/ap_gender.py +4 -2
- nkululeko/autopredict/ap_mos.py +5 -2
- nkululeko/autopredict/ap_pesq.py +5 -2
- nkululeko/autopredict/ap_sdr.py +5 -2
- nkululeko/autopredict/ap_snr.py +5 -2
- nkululeko/autopredict/ap_stoi.py +5 -2
- nkululeko/autopredict/ap_valence.py +4 -2
- nkululeko/autopredict/estimate_snr.py +10 -14
- nkululeko/cacheddataset.py +1 -1
- nkululeko/constants.py +1 -1
- nkululeko/data/dataset.py +19 -16
- nkululeko/data/dataset_csv.py +5 -3
- nkululeko/demo-ft.py +29 -0
- nkululeko/demo_feats.py +5 -4
- nkululeko/demo_predictor.py +3 -4
- nkululeko/ensemble.py +27 -28
- nkululeko/experiment.py +11 -7
- nkululeko/experiment_felix.py +728 -0
- nkululeko/explore.py +1 -0
- nkululeko/export.py +7 -5
- nkululeko/feat_extract/feats_agender.py +5 -4
- nkululeko/feat_extract/feats_agender_agender.py +7 -6
- nkululeko/feat_extract/feats_analyser.py +18 -16
- nkululeko/feat_extract/feats_ast.py +9 -8
- nkululeko/feat_extract/feats_auddim.py +3 -5
- nkululeko/feat_extract/feats_audmodel.py +2 -2
- nkululeko/feat_extract/feats_clap.py +9 -12
- nkululeko/feat_extract/feats_hubert.py +2 -3
- nkululeko/feat_extract/feats_import.py +5 -4
- nkululeko/feat_extract/feats_mld.py +3 -5
- nkululeko/feat_extract/feats_mos.py +4 -3
- nkululeko/feat_extract/feats_opensmile.py +4 -3
- nkululeko/feat_extract/feats_oxbow.py +5 -4
- nkululeko/feat_extract/feats_praat.py +4 -7
- nkululeko/feat_extract/feats_snr.py +3 -5
- nkululeko/feat_extract/feats_spectra.py +8 -9
- nkululeko/feat_extract/feats_spkrec.py +6 -11
- nkululeko/feat_extract/feats_squim.py +2 -4
- nkululeko/feat_extract/feats_trill.py +2 -5
- nkululeko/feat_extract/feats_wav2vec2.py +8 -4
- nkululeko/feat_extract/feats_wavlm.py +2 -3
- nkululeko/feat_extract/feats_whisper.py +4 -6
- nkululeko/feat_extract/featureset.py +4 -2
- nkululeko/feat_extract/feinberg_praat.py +1 -3
- nkululeko/feat_extract/transformer_feature_extractor.py +147 -0
- nkululeko/file_checker.py +3 -3
- nkululeko/filter_data.py +3 -1
- nkululeko/fixedsegment.py +83 -0
- nkululeko/models/model.py +3 -5
- nkululeko/models/model_bayes.py +1 -0
- nkululeko/models/model_cnn.py +4 -6
- nkululeko/models/model_gmm.py +13 -9
- nkululeko/models/model_knn.py +1 -0
- nkululeko/models/model_knn_reg.py +1 -0
- nkululeko/models/model_lin_reg.py +1 -0
- nkululeko/models/model_mlp.py +2 -3
- nkululeko/models/model_mlp_regression.py +1 -6
- nkululeko/models/model_svm.py +2 -2
- nkululeko/models/model_svr.py +1 -0
- nkululeko/models/model_tree.py +2 -3
- nkululeko/models/model_tree_reg.py +1 -0
- nkululeko/models/model_tuned.py +54 -33
- nkululeko/models/model_xgb.py +1 -0
- nkululeko/models/model_xgr.py +1 -0
- nkululeko/multidb.py +1 -0
- nkululeko/nkululeko.py +1 -1
- nkululeko/plots.py +1 -1
- nkululeko/predict.py +4 -5
- nkululeko/reporting/defines.py +6 -8
- nkululeko/reporting/latex_writer.py +3 -3
- nkululeko/reporting/report.py +2 -2
- nkululeko/reporting/report_item.py +1 -0
- nkululeko/reporting/reporter.py +20 -19
- nkululeko/resample.py +8 -12
- nkululeko/resample_cli.py +99 -0
- nkululeko/runmanager.py +3 -1
- nkululeko/scaler.py +1 -1
- nkululeko/segment.py +6 -5
- nkululeko/segmenting/seg_inaspeechsegmenter.py +3 -3
- nkululeko/segmenting/seg_silero.py +4 -4
- nkululeko/syllable_nuclei.py +9 -22
- nkululeko/test_pretrain.py +6 -7
- nkululeko/utils/stats.py +0 -1
- nkululeko/utils/util.py +2 -3
- {nkululeko-0.89.2.dist-info → nkululeko-0.90.1.dist-info}/METADATA +12 -2
- nkululeko-0.90.1.dist-info/RECORD +119 -0
- {nkululeko-0.89.2.dist-info → nkululeko-0.90.1.dist-info}/WHEEL +1 -1
- nkululeko-0.89.2.dist-info/RECORD +0 -114
- {nkululeko-0.89.2.dist-info → nkululeko-0.90.1.dist-info}/LICENSE +0 -0
- {nkululeko-0.89.2.dist-info → nkululeko-0.90.1.dist-info}/top_level.txt +0 -0
nkululeko/explore.py
CHANGED
@@ -19,6 +19,7 @@ The script can be run from the command line with the `--config` argument to spec
|
|
19
19
|
the configuration file to use. If no configuration file is provided, it will look
|
20
20
|
for an `exp.ini` file in the same directory as the script.
|
21
21
|
"""
|
22
|
+
|
22
23
|
# explore.py
|
23
24
|
# explore the feature sets
|
24
25
|
|
nkululeko/export.py
CHANGED
@@ -1,16 +1,18 @@
|
|
1
1
|
# export.py
|
2
2
|
# export the loaded training and test sets to it's own folder
|
3
3
|
|
4
|
-
import
|
5
|
-
import pandas as pd
|
4
|
+
import argparse
|
6
5
|
import configparser
|
6
|
+
import os
|
7
|
+
import shutil
|
8
|
+
|
7
9
|
import audeer
|
8
|
-
import argparse
|
9
10
|
import audiofile
|
11
|
+
import pandas as pd
|
12
|
+
|
13
|
+
from nkululeko.constants import VERSION
|
10
14
|
from nkululeko.experiment import Experiment
|
11
15
|
from nkululeko.utils.util import Util
|
12
|
-
from nkululeko.constants import VERSION
|
13
|
-
import shutil
|
14
16
|
|
15
17
|
|
16
18
|
def main(src_dir):
|
@@ -1,16 +1,17 @@
|
|
1
1
|
# feats_agender.py
|
2
2
|
|
3
|
-
from nkululeko.feat_extract.featureset import Featureset
|
4
3
|
import os
|
5
4
|
|
6
5
|
# import pandas as pd
|
7
6
|
import audeer
|
8
|
-
import
|
7
|
+
import audinterface
|
9
8
|
import audonnx
|
10
9
|
import numpy as np
|
11
|
-
import audinterface
|
12
10
|
import torch
|
13
11
|
|
12
|
+
import nkululeko.glob_conf as glob_conf
|
13
|
+
from nkululeko.feat_extract.featureset import Featureset
|
14
|
+
|
14
15
|
|
15
16
|
class AgenderSet(Featureset):
|
16
17
|
"""
|
@@ -37,7 +38,7 @@ class AgenderSet(Featureset):
|
|
37
38
|
cuda = "cuda" if torch.cuda.is_available() else "cpu"
|
38
39
|
device = self.util.config_val("MODEL", "device", cuda)
|
39
40
|
self.model = audonnx.load(model_root, device=device)
|
40
|
-
self.util.debug(
|
41
|
+
self.util.debug("initialized agender model")
|
41
42
|
self.model_loaded = True
|
42
43
|
|
43
44
|
def extract(self):
|
@@ -1,14 +1,16 @@
|
|
1
1
|
# feats_audmodel_dim.py
|
2
|
-
from nkululeko.feat_extract.featureset import Featureset
|
3
2
|
import os
|
4
|
-
|
3
|
+
|
5
4
|
import audeer
|
6
|
-
import
|
5
|
+
import audinterface
|
7
6
|
import audonnx
|
8
7
|
import numpy as np
|
9
|
-
import audinterface
|
10
8
|
import torch
|
11
9
|
|
10
|
+
import nkululeko.glob_conf as glob_conf
|
11
|
+
from nkululeko.feat_extract.featureset import Featureset
|
12
|
+
|
13
|
+
|
12
14
|
class Agender_agenderSet(Featureset):
|
13
15
|
"""
|
14
16
|
Age and gender predictions from the wav2vec2. based model finetuned on agender, described in the paper
|
@@ -29,8 +31,7 @@ class Agender_agenderSet(Featureset):
|
|
29
31
|
if not os.path.isdir(model_root):
|
30
32
|
cache_root = audeer.mkdir("cache")
|
31
33
|
model_root = audeer.mkdir(model_root)
|
32
|
-
archive_path = audeer.download_url(
|
33
|
-
model_url, cache_root, verbose=True)
|
34
|
+
archive_path = audeer.download_url(model_url, cache_root, verbose=True)
|
34
35
|
audeer.extract_archive(archive_path, model_root)
|
35
36
|
cuda = "cuda" if torch.cuda.is_available() else "cpu"
|
36
37
|
device = self.util.config_val("MODEL", "device", cuda)
|
@@ -1,18 +1,18 @@
|
|
1
1
|
# feats_analyser.py
|
2
2
|
import ast
|
3
|
+
|
4
|
+
import matplotlib.pyplot as plt
|
3
5
|
import pandas as pd
|
4
6
|
from sklearn.inspection import permutation_importance
|
5
|
-
from sklearn.linear_model import LogisticRegression
|
6
|
-
from sklearn.tree import DecisionTreeClassifier
|
7
|
-
|
8
|
-
from sklearn.tree import DecisionTreeRegressor
|
9
|
-
import matplotlib.pyplot as plt
|
10
|
-
from nkululeko.utils.util import Util
|
11
|
-
from nkululeko.utils.stats import normalize
|
12
|
-
from nkululeko.plots import Plots
|
7
|
+
from sklearn.linear_model import LinearRegression, LogisticRegression
|
8
|
+
from sklearn.tree import DecisionTreeClassifier, DecisionTreeRegressor
|
9
|
+
|
13
10
|
import nkululeko.glob_conf as glob_conf
|
14
|
-
from nkululeko.
|
11
|
+
from nkululeko.plots import Plots
|
15
12
|
from nkululeko.reporting.defines import Header
|
13
|
+
from nkululeko.reporting.report_item import ReportItem
|
14
|
+
from nkululeko.utils.stats import normalize
|
15
|
+
from nkululeko.utils.util import Util
|
16
16
|
|
17
17
|
|
18
18
|
class FeatureAnalyser:
|
@@ -58,9 +58,9 @@ class FeatureAnalyser:
|
|
58
58
|
model_func = model.clf.predict
|
59
59
|
else:
|
60
60
|
raise Exception("Model not supported for SHAP analysis")
|
61
|
-
|
61
|
+
|
62
62
|
self.util.debug(f"using SHAP explainer for {model_name} model")
|
63
|
-
|
63
|
+
|
64
64
|
explainer = shap.Explainer(
|
65
65
|
model_func,
|
66
66
|
self.features,
|
@@ -68,14 +68,14 @@ class FeatureAnalyser:
|
|
68
68
|
algorithm="permutation",
|
69
69
|
npermutations=5,
|
70
70
|
)
|
71
|
-
|
71
|
+
|
72
72
|
self.util.debug("computing SHAP values...")
|
73
73
|
shap_values = explainer(self.features)
|
74
74
|
self.util.to_pickle(shap_values, name)
|
75
75
|
else:
|
76
76
|
shap_values = self.util.from_pickle(name)
|
77
77
|
# plt.figure()
|
78
|
-
plt.close(
|
78
|
+
plt.close("all")
|
79
79
|
plt.tight_layout()
|
80
80
|
shap.plots.bar(shap_values)
|
81
81
|
fig_dir = self.util.get_path("fig_dir") + "../" # one up because of the runs
|
@@ -272,7 +272,7 @@ class FeatureAnalyser:
|
|
272
272
|
fig = ax.figure
|
273
273
|
fig.clear()
|
274
274
|
plt.close(fig)
|
275
|
-
caption =
|
275
|
+
caption = "Feature importance"
|
276
276
|
if permutation:
|
277
277
|
caption += " based on permutation of features."
|
278
278
|
glob_conf.report.add_item(
|
@@ -285,7 +285,9 @@ class FeatureAnalyser:
|
|
285
285
|
)
|
286
286
|
|
287
287
|
# print feature importance values to file and debug and save to result
|
288
|
-
self.util.debug(
|
288
|
+
self.util.debug(
|
289
|
+
f"Importance features from {model_name}: features = \n{df_imp['feats'].values.tolist()}"
|
290
|
+
)
|
289
291
|
# result file
|
290
292
|
res_dir = self.util.get_path("res_dir")
|
291
293
|
filename = f"_EXPL_{model_name}"
|
@@ -300,7 +302,7 @@ class FeatureAnalyser:
|
|
300
302
|
|
301
303
|
df_imp.to_csv(filename, mode="a")
|
302
304
|
self.util.debug(f"Saved feature importance values to {filename}")
|
303
|
-
|
305
|
+
|
304
306
|
# check if feature distributions should be plotted
|
305
307
|
plot_feats = self.util.config_val("EXPL", "feature_distributions", False)
|
306
308
|
if plot_feats:
|
@@ -4,10 +4,9 @@ import os
|
|
4
4
|
import numpy as np
|
5
5
|
import pandas as pd
|
6
6
|
import torch
|
7
|
-
import torch.nn.functional as F
|
8
7
|
import torchaudio
|
9
8
|
from tqdm import tqdm
|
10
|
-
from transformers import
|
9
|
+
from transformers import ASTModel, AutoProcessor
|
11
10
|
|
12
11
|
import nkululeko.glob_conf as glob_conf
|
13
12
|
from nkululeko.feat_extract.featureset import Featureset
|
@@ -34,7 +33,6 @@ class Ast(Featureset):
|
|
34
33
|
self.model.eval()
|
35
34
|
self.model_initialized = True
|
36
35
|
|
37
|
-
|
38
36
|
def extract(self):
|
39
37
|
"""Extract the features or load them from disk if present."""
|
40
38
|
store = self.util.get_path("store")
|
@@ -80,11 +78,12 @@ class Ast(Featureset):
|
|
80
78
|
f"got nan: {self.df.shape} {self.df.isnull().sum().sum()}"
|
81
79
|
)
|
82
80
|
|
83
|
-
|
84
81
|
def get_embeddings(self, signal, sampling_rate, file):
|
85
82
|
"""Extract embeddings from raw audio signal."""
|
86
83
|
try:
|
87
|
-
inputs = self.processor(
|
84
|
+
inputs = self.processor(
|
85
|
+
signal.numpy(), sampling_rate=sampling_rate, return_tensors="pt"
|
86
|
+
)
|
88
87
|
|
89
88
|
inputs = {k: v.to(self.device) for k, v in inputs.items()}
|
90
89
|
|
@@ -102,14 +101,16 @@ class Ast(Featureset):
|
|
102
101
|
|
103
102
|
# print(f"hs shape: {embeddings.shape}")
|
104
103
|
# hs shape: (1, 768)
|
105
|
-
|
104
|
+
|
106
105
|
except Exception as e:
|
107
|
-
self.util.error(
|
106
|
+
self.util.error(
|
107
|
+
f"Error extracting embeddings for file {file}: {str(e)}, fill with"
|
108
|
+
)
|
108
109
|
return np.zeros(
|
109
110
|
self.model.config.hidden_size
|
110
111
|
) # Return zero vector on error
|
111
112
|
return embeddings.ravel()
|
112
|
-
|
113
|
+
|
113
114
|
def extract_sample(self, signal, sr):
|
114
115
|
self.init_model()
|
115
116
|
feats = self.get_embeddings(signal, sr, "no file")
|
@@ -1,16 +1,14 @@
|
|
1
1
|
# feats_audmodel_dim.py
|
2
2
|
import os
|
3
3
|
|
4
|
-
import numpy as np
|
5
|
-
import pandas as pd
|
6
|
-
import torch
|
7
|
-
|
8
4
|
import audeer
|
9
5
|
import audinterface
|
10
6
|
import audonnx
|
7
|
+
import numpy as np
|
8
|
+
import torch
|
11
9
|
|
12
|
-
from nkululeko.feat_extract.featureset import Featureset
|
13
10
|
import nkululeko.glob_conf as glob_conf
|
11
|
+
from nkululeko.feat_extract.featureset import Featureset
|
14
12
|
|
15
13
|
|
16
14
|
class AuddimSet(Featureset):
|
@@ -4,10 +4,10 @@ import os
|
|
4
4
|
import audeer
|
5
5
|
import audinterface
|
6
6
|
import audonnx
|
7
|
-
import nkululeko.glob_conf as glob_conf
|
8
7
|
import numpy as np
|
9
|
-
import pandas as pd
|
10
8
|
import torch
|
9
|
+
|
10
|
+
import nkululeko.glob_conf as glob_conf
|
11
11
|
from nkululeko.feat_extract.featureset import Featureset
|
12
12
|
|
13
13
|
|
@@ -1,14 +1,14 @@
|
|
1
1
|
# feats_clap.py
|
2
2
|
|
3
|
-
from nkululeko.utils.util import Util
|
4
|
-
from nkululeko.feat_extract.featureset import Featureset
|
5
3
|
import os
|
4
|
+
|
5
|
+
import audiofile
|
6
|
+
import laion_clap
|
6
7
|
import pandas as pd
|
7
8
|
from tqdm import tqdm
|
8
|
-
|
9
|
+
|
9
10
|
import nkululeko.glob_conf as glob_conf
|
10
|
-
import
|
11
|
-
import audiofile
|
11
|
+
from nkululeko.feat_extract.featureset import Featureset
|
12
12
|
|
13
13
|
|
14
14
|
class ClapSet(Featureset):
|
@@ -26,21 +26,19 @@ class ClapSet(Featureset):
|
|
26
26
|
self.util.debug("loading clap model...")
|
27
27
|
self.model = laion_clap.CLAP_Module(enable_fusion=False)
|
28
28
|
self.model.load_ckpt() # download the default pretrained checkpoint.
|
29
|
-
print(
|
29
|
+
print("loaded clap model")
|
30
30
|
|
31
31
|
def extract(self):
|
32
32
|
"""Extract the features or load them from disk if present."""
|
33
33
|
store = self.util.get_path("store")
|
34
34
|
store_format = self.util.config_val("FEATS", "store_format", "pkl")
|
35
35
|
storage = f"{store}{self.name}.{store_format}"
|
36
|
-
extract = self.util.config_val(
|
37
|
-
"FEATS", "needs_feature_extraction", False)
|
36
|
+
extract = self.util.config_val("FEATS", "needs_feature_extraction", False)
|
38
37
|
no_reuse = eval(self.util.config_val("FEATS", "no_reuse", "False"))
|
39
38
|
if extract or no_reuse or not os.path.isfile(storage):
|
40
39
|
if not self.model_initialized:
|
41
40
|
self.init_model()
|
42
|
-
self.util.debug(
|
43
|
-
"extracting clap embeddings, this might take a while...")
|
41
|
+
self.util.debug("extracting clap embeddings, this might take a while...")
|
44
42
|
emb_series = pd.Series(index=self.data_df.index, dtype=object)
|
45
43
|
length = len(self.data_df.index)
|
46
44
|
for idx, (file, start, end) in enumerate(
|
@@ -54,8 +52,7 @@ class ClapSet(Featureset):
|
|
54
52
|
)
|
55
53
|
emb = self.get_embeddings(signal, sampling_rate)
|
56
54
|
emb_series[idx] = emb
|
57
|
-
self.df = pd.DataFrame(
|
58
|
-
emb_series.values.tolist(), index=self.data_df.index)
|
55
|
+
self.df = pd.DataFrame(emb_series.values.tolist(), index=self.data_df.index)
|
59
56
|
self.util.write_store(self.df, storage, store_format)
|
60
57
|
try:
|
61
58
|
glob_conf.config["DATA"]["needs_feature_extraction"] = "false"
|
@@ -10,11 +10,10 @@ import pandas as pd
|
|
10
10
|
import torch
|
11
11
|
import torchaudio
|
12
12
|
from tqdm import tqdm
|
13
|
-
from transformers import HubertModel
|
14
|
-
from transformers import Wav2Vec2FeatureExtractor
|
13
|
+
from transformers import HubertModel, Wav2Vec2FeatureExtractor
|
15
14
|
|
16
|
-
from nkululeko.feat_extract.featureset import Featureset
|
17
15
|
import nkululeko.glob_conf as glob_conf
|
16
|
+
from nkululeko.feat_extract.featureset import Featureset
|
18
17
|
|
19
18
|
|
20
19
|
class Hubert(Featureset):
|
@@ -1,10 +1,11 @@
|
|
1
1
|
# feats_import.py
|
2
2
|
|
3
|
-
import os
|
4
3
|
import ast
|
4
|
+
import os
|
5
|
+
|
5
6
|
import audformat
|
6
7
|
import pandas as pd
|
7
|
-
|
8
|
+
|
8
9
|
from nkululeko.feat_extract.featureset import Featureset
|
9
10
|
|
10
11
|
|
@@ -20,11 +21,11 @@ class ImportSet(Featureset):
|
|
20
21
|
try:
|
21
22
|
feat_import_files = self.util.config_val("FEATS", "import_file", False)
|
22
23
|
feat_import_files = ast.literal_eval(feat_import_files)
|
23
|
-
except ValueError
|
24
|
+
except ValueError:
|
24
25
|
self.util.error(
|
25
26
|
"feature type == import needs import_file = ['file1', 'filex']"
|
26
27
|
)
|
27
|
-
except SyntaxError
|
28
|
+
except SyntaxError:
|
28
29
|
if type(feat_import_files) == str:
|
29
30
|
feat_import_files = [feat_import_files]
|
30
31
|
else:
|
@@ -1,11 +1,9 @@
|
|
1
1
|
# mld_fset.py
|
2
|
-
from nkululeko.feat_extract.featureset import Featureset
|
3
|
-
import sys
|
4
2
|
import os
|
5
|
-
import
|
6
|
-
|
7
|
-
from nkululeko.utils.util import Util
|
3
|
+
import sys
|
4
|
+
|
8
5
|
import nkululeko.glob_conf as glob_conf
|
6
|
+
from nkululeko.feat_extract.featureset import Featureset
|
9
7
|
|
10
8
|
|
11
9
|
class MLD_set(Featureset):
|
@@ -12,15 +12,16 @@ pip install --pre torch torchvision torchaudio --extra-index-url https://downloa
|
|
12
12
|
"""
|
13
13
|
|
14
14
|
import os
|
15
|
+
|
16
|
+
import audiofile
|
15
17
|
import pandas as pd
|
16
|
-
from tqdm import tqdm
|
17
18
|
import torch
|
18
19
|
import torchaudio
|
19
20
|
from torchaudio.pipelines import SQUIM_SUBJECTIVE
|
20
21
|
from torchaudio.utils import download_asset
|
21
|
-
import
|
22
|
+
from tqdm import tqdm
|
23
|
+
|
22
24
|
import nkululeko.glob_conf as glob_conf
|
23
|
-
from nkululeko.utils.util import Util
|
24
25
|
from nkululeko.feat_extract.featureset import Featureset
|
25
26
|
|
26
27
|
|
@@ -1,10 +1,11 @@
|
|
1
1
|
# opensmileset.py
|
2
|
-
from nkululeko.feat_extract.featureset import Featureset
|
3
2
|
import os
|
3
|
+
|
4
|
+
import opensmile
|
4
5
|
import pandas as pd
|
6
|
+
|
5
7
|
import nkululeko.glob_conf as glob_conf
|
6
|
-
import
|
7
|
-
import opensmile
|
8
|
+
from nkululeko.feat_extract.featureset import Featureset
|
8
9
|
|
9
10
|
|
10
11
|
class Opensmileset(Featureset):
|
@@ -1,10 +1,11 @@
|
|
1
1
|
# feats_oxbow.py
|
2
2
|
|
3
|
-
from nkululeko.utils.util import Util
|
4
|
-
from nkululeko.feat_extract.featureset import Featureset
|
5
3
|
import os
|
6
|
-
|
4
|
+
|
7
5
|
import opensmile
|
6
|
+
import pandas as pd
|
7
|
+
|
8
|
+
from nkululeko.feat_extract.featureset import Featureset
|
8
9
|
|
9
10
|
|
10
11
|
class Openxbow(Featureset):
|
@@ -53,7 +54,7 @@ class Openxbow(Featureset):
|
|
53
54
|
# check if JAR file exist
|
54
55
|
if not os.path.isfile(f"{xbow_path}/openXBOW.jar"):
|
55
56
|
# download using wget if not exist and locate in xbow_path
|
56
|
-
os.system(
|
57
|
+
os.system("git clone https://github.com/openXBOW/openXBOW")
|
57
58
|
# get the size of the codebook
|
58
59
|
size = self.util.config_val("FEATS", "size", 500)
|
59
60
|
# get the number of assignements
|
@@ -1,13 +1,12 @@
|
|
1
1
|
# feats_praat.py
|
2
|
-
import ast
|
3
2
|
import os
|
4
3
|
|
5
4
|
import numpy as np
|
6
5
|
import pandas as pd
|
7
6
|
|
7
|
+
import nkululeko.glob_conf as glob_conf
|
8
8
|
from nkululeko.feat_extract import feinberg_praat
|
9
9
|
from nkululeko.feat_extract.featureset import Featureset
|
10
|
-
import nkululeko.glob_conf as glob_conf
|
11
10
|
|
12
11
|
|
13
12
|
class PraatSet(Featureset):
|
@@ -26,12 +25,10 @@ class PraatSet(Featureset):
|
|
26
25
|
store = self.util.get_path("store")
|
27
26
|
store_format = self.util.config_val("FEATS", "store_format", "pkl")
|
28
27
|
storage = f"{store}{self.name}.{store_format}"
|
29
|
-
extract = self.util.config_val(
|
30
|
-
"FEATS", "needs_feature_extraction", False)
|
28
|
+
extract = self.util.config_val("FEATS", "needs_feature_extraction", False)
|
31
29
|
no_reuse = eval(self.util.config_val("FEATS", "no_reuse", "False"))
|
32
30
|
if extract or no_reuse or not os.path.isfile(storage):
|
33
|
-
self.util.debug(
|
34
|
-
"extracting Praat features, this might take a while...")
|
31
|
+
self.util.debug("extracting Praat features, this might take a while...")
|
35
32
|
self.df = feinberg_praat.compute_features(self.data_df.index)
|
36
33
|
self.df = self.df.set_index(self.data_df.index)
|
37
34
|
for i, col in enumerate(self.df.columns):
|
@@ -54,8 +51,8 @@ class PraatSet(Featureset):
|
|
54
51
|
self.df = self.df.astype(float)
|
55
52
|
|
56
53
|
def extract_sample(self, signal, sr):
|
57
|
-
import audiofile
|
58
54
|
import audformat
|
55
|
+
import audiofile
|
59
56
|
|
60
57
|
tmp_audio_names = ["praat_audio_tmp.wav"]
|
61
58
|
audiofile.write(tmp_audio_names[0], signal, sr)
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
SNR (signal to noise ratio) is extracted as acoustic features.
|
4
4
|
"""
|
5
|
+
|
5
6
|
import os
|
6
7
|
|
7
8
|
import audiofile
|
@@ -11,7 +12,6 @@ from tqdm import tqdm
|
|
11
12
|
import nkululeko.glob_conf as glob_conf
|
12
13
|
from nkululeko.autopredict.estimate_snr import SNREstimator
|
13
14
|
from nkululeko.feat_extract.featureset import Featureset
|
14
|
-
from nkululeko.utils.util import Util
|
15
15
|
|
16
16
|
|
17
17
|
class SNRSet(Featureset):
|
@@ -28,8 +28,7 @@ class SNRSet(Featureset):
|
|
28
28
|
store = self.util.get_path("store")
|
29
29
|
store_format = self.util.config_val("FEATS", "store_format", "pkl")
|
30
30
|
storage = f"{store}{self.name}.{store_format}"
|
31
|
-
extract = self.util.config_val(
|
32
|
-
"FEATS", "needs_feature_extraction", False)
|
31
|
+
extract = self.util.config_val("FEATS", "needs_feature_extraction", False)
|
33
32
|
no_reuse = eval(self.util.config_val("FEATS", "no_reuse", "False"))
|
34
33
|
if extract or no_reuse or not os.path.isfile(storage):
|
35
34
|
self.util.debug("estimating SNR, this might take a while...")
|
@@ -46,8 +45,7 @@ class SNRSet(Featureset):
|
|
46
45
|
snr = self.get_snr(signal[0], sampling_rate)
|
47
46
|
snr_series[idx] = snr
|
48
47
|
print("")
|
49
|
-
self.df = pd.DataFrame(
|
50
|
-
snr_series.values.tolist(), index=self.data_df.index)
|
48
|
+
self.df = pd.DataFrame(snr_series.values.tolist(), index=self.data_df.index)
|
51
49
|
self.df.columns = ["snr"]
|
52
50
|
self.util.write_store(self.df, storage, store_format)
|
53
51
|
try:
|
@@ -6,21 +6,20 @@ Inspired by code from Su Lei
|
|
6
6
|
"""
|
7
7
|
|
8
8
|
import os
|
9
|
+
import pathlib
|
10
|
+
|
11
|
+
import audeer
|
12
|
+
import matplotlib.pyplot as plt
|
13
|
+
import numpy as np
|
14
|
+
import pandas as pd
|
9
15
|
import torchaudio
|
10
16
|
import torchaudio.transforms as T
|
11
|
-
import torch
|
12
|
-
from torch.utils.data import Dataset
|
13
17
|
from PIL import Image, ImageOps
|
14
|
-
import pandas as pd
|
15
|
-
import numpy as np
|
16
|
-
import matplotlib.pyplot as plt
|
17
18
|
from tqdm import tqdm
|
18
|
-
import pathlib
|
19
|
-
import audeer
|
20
19
|
|
21
|
-
from nkululeko.feat_extract.featureset import Featureset
|
22
|
-
from nkululeko.constants import SAMPLING_RATE
|
23
20
|
import nkululeko.glob_conf as glob_conf
|
21
|
+
from nkululeko.constants import SAMPLING_RATE
|
22
|
+
from nkululeko.feat_extract.featureset import Featureset
|
24
23
|
|
25
24
|
|
26
25
|
class Spectraloader(Featureset):
|
@@ -7,14 +7,15 @@
|
|
7
7
|
|
8
8
|
import os
|
9
9
|
|
10
|
-
import nkululeko.glob_conf as glob_conf
|
11
10
|
import pandas as pd
|
12
11
|
import torch
|
13
12
|
import torchaudio
|
14
|
-
from nkululeko.feat_extract.featureset import Featureset
|
15
13
|
from speechbrain.inference import EncoderClassifier
|
16
14
|
from tqdm import tqdm
|
17
15
|
|
16
|
+
import nkululeko.glob_conf as glob_conf
|
17
|
+
from nkululeko.feat_extract.featureset import Featureset
|
18
|
+
|
18
19
|
# from transformers import HubertModel, Wav2Vec2FeatureExtractor
|
19
20
|
|
20
21
|
|
@@ -49,16 +50,12 @@ class Spkrec(Featureset):
|
|
49
50
|
"""Extract the features or load them from disk if present."""
|
50
51
|
store = self.util.get_path("store")
|
51
52
|
storage = f"{store}{self.name}.pkl"
|
52
|
-
extract = self.util.config_val(
|
53
|
-
"FEATS", "needs_feature_extraction", False
|
54
|
-
)
|
53
|
+
extract = self.util.config_val("FEATS", "needs_feature_extraction", False)
|
55
54
|
no_reuse = eval(self.util.config_val("FEATS", "no_reuse", "False"))
|
56
55
|
if extract or no_reuse or not os.path.isfile(storage):
|
57
56
|
if not self.classifier_initialized:
|
58
57
|
self.init_model()
|
59
|
-
self.util.debug(
|
60
|
-
"extracting Spkrec embeddings, this might take a while..."
|
61
|
-
)
|
58
|
+
self.util.debug("extracting Spkrec embeddings, this might take a while...")
|
62
59
|
emb_series = pd.Series(index=self.data_df.index, dtype=object)
|
63
60
|
length = len(self.data_df.index)
|
64
61
|
for idx, (file, start, end) in enumerate(
|
@@ -77,9 +74,7 @@ class Spkrec(Featureset):
|
|
77
74
|
# fill series with embeddings
|
78
75
|
emb_series.iloc[idx] = emb
|
79
76
|
# print(f"emb_series shape: {emb_series.shape}")
|
80
|
-
self.df = pd.DataFrame(
|
81
|
-
emb_series.values.tolist(), index=self.data_df.index
|
82
|
-
)
|
77
|
+
self.df = pd.DataFrame(emb_series.values.tolist(), index=self.data_df.index)
|
83
78
|
print(f"df shape: {self.df.shape}")
|
84
79
|
self.df.to_pickle(storage)
|
85
80
|
try:
|
@@ -14,17 +14,15 @@ pip install --pre torch torchvision torchaudio --extra-index-url https://downloa
|
|
14
14
|
|
15
15
|
import os
|
16
16
|
|
17
|
+
import audiofile
|
17
18
|
import pandas as pd
|
18
19
|
import torch
|
19
20
|
import torchaudio
|
20
21
|
from torchaudio.pipelines import SQUIM_OBJECTIVE
|
21
22
|
from tqdm import tqdm
|
22
23
|
|
23
|
-
import audiofile
|
24
|
-
|
25
|
-
from nkululeko.feat_extract.featureset import Featureset
|
26
24
|
import nkululeko.glob_conf as glob_conf
|
27
|
-
from nkululeko.
|
25
|
+
from nkululeko.feat_extract.featureset import Featureset
|
28
26
|
|
29
27
|
|
30
28
|
class SquimSet(Featureset):
|
@@ -1,17 +1,14 @@
|
|
1
1
|
# feats_trill.py
|
2
2
|
import os
|
3
3
|
|
4
|
+
import audiofile as af
|
4
5
|
import pandas as pd
|
5
6
|
import tensorflow as tf
|
6
7
|
import tensorflow_hub as hub
|
7
8
|
from tqdm import tqdm
|
8
9
|
|
9
|
-
import audiofile as af
|
10
|
-
|
11
|
-
from nkululeko.feat_extract.featureset import Featureset
|
12
10
|
import nkululeko.glob_conf as glob_conf
|
13
|
-
from nkululeko.
|
14
|
-
|
11
|
+
from nkululeko.feat_extract.featureset import Featureset
|
15
12
|
|
16
13
|
# Import TF 2.X and make sure we're running eager.
|
17
14
|
assert tf.executing_eagerly()
|
@@ -7,14 +7,16 @@ Currently only supports wav2vec2
|
|
7
7
|
"""
|
8
8
|
|
9
9
|
import os
|
10
|
-
|
10
|
+
|
11
11
|
import pandas as pd
|
12
12
|
import torch
|
13
13
|
import torchaudio
|
14
|
-
from transformers import Wav2Vec2FeatureExtractor, Wav2Vec2Model
|
15
14
|
import transformers
|
16
|
-
from
|
15
|
+
from tqdm import tqdm
|
16
|
+
from transformers import Wav2Vec2FeatureExtractor, Wav2Vec2Model
|
17
|
+
|
17
18
|
import nkululeko.glob_conf as glob_conf
|
19
|
+
from nkululeko.feat_extract.featureset import Featureset
|
18
20
|
|
19
21
|
|
20
22
|
class Wav2vec2(Featureset):
|
@@ -47,7 +49,9 @@ class Wav2vec2(Featureset):
|
|
47
49
|
config.num_hidden_layers = layer_num - hidden_layer
|
48
50
|
self.util.debug(f"using hidden layer #{config.num_hidden_layers}")
|
49
51
|
self.processor = Wav2Vec2FeatureExtractor.from_pretrained(model_path)
|
50
|
-
self.model = Wav2Vec2Model.from_pretrained(model_path, config=config).to(
|
52
|
+
self.model = Wav2Vec2Model.from_pretrained(model_path, config=config).to(
|
53
|
+
self.device
|
54
|
+
)
|
51
55
|
print(f"intialized Wav2vec model on {self.device}")
|
52
56
|
self.model.eval()
|
53
57
|
self.model_initialized = True
|