Spaces:
Sleeping
Sleeping
Marcos12886
commited on
Commit
•
1d21972
1
Parent(s):
166aa6c
Empezar a poner en carpeta aprolos8000
Browse files- .gitignore +2 -1
- app.py +3 -3
- model.py +12 -4
- models_config.json +11 -12
.gitignore
CHANGED
@@ -1,3 +1,4 @@
|
|
1 |
__pycache__
|
2 |
.venv
|
3 |
-
.vscode
|
|
|
|
1 |
__pycache__
|
2 |
.venv
|
3 |
+
.vscode
|
4 |
+
A-POR-LOS-8000
|
app.py
CHANGED
@@ -24,7 +24,7 @@ def call(audiopath, model, dataset_path, filter_white_noise):
|
|
24 |
|
25 |
def predict(audio_path_pred):
|
26 |
with torch.no_grad():
|
27 |
-
logits = call(audio_path_pred, model=model_class, dataset_path="data/mixed_data", filter_white_noise=True)
|
28 |
predicted_class_ids_class = torch.argmax(logits, dim=-1).item()
|
29 |
label_class = id2label_class[predicted_class_ids_class]
|
30 |
label_mapping = {0: 'Hambre', 1: 'Problemas para respirar', 2: 'Dolor', 3: 'Cansancio/Incomodidad'}
|
@@ -33,7 +33,7 @@ def predict(audio_path_pred):
|
|
33 |
|
34 |
def predict_stream(audio_path_stream):
|
35 |
with torch.no_grad():
|
36 |
-
logits = call(audio_path_stream, model=model_mon, dataset_path="data/baby_cry_detection", filter_white_noise=False)
|
37 |
probabilities = torch.nn.functional.softmax(logits, dim=-1)
|
38 |
crying_probabilities = probabilities[:, 1]
|
39 |
avg_crying_probability = crying_probabilities.mean()*100
|
@@ -45,7 +45,7 @@ def predict_stream(audio_path_stream):
|
|
45 |
|
46 |
def decibelios(audio_path_stream):
|
47 |
with torch.no_grad():
|
48 |
-
logits = call(audio_path_stream, model=model_mon, dataset_path="data/baby_cry_detection", filter_white_noise=False)
|
49 |
rms = torch.sqrt(torch.mean(torch.square(logits)))
|
50 |
db_level = 20 * torch.log10(rms + 1e-6).item()
|
51 |
return db_level
|
|
|
24 |
|
25 |
def predict(audio_path_pred):
|
26 |
with torch.no_grad():
|
27 |
+
logits = call(audio_path_pred, model=model_class, dataset_path="A-POR-LOS-8000/data/mixed_data", filter_white_noise=True)
|
28 |
predicted_class_ids_class = torch.argmax(logits, dim=-1).item()
|
29 |
label_class = id2label_class[predicted_class_ids_class]
|
30 |
label_mapping = {0: 'Hambre', 1: 'Problemas para respirar', 2: 'Dolor', 3: 'Cansancio/Incomodidad'}
|
|
|
33 |
|
34 |
def predict_stream(audio_path_stream):
|
35 |
with torch.no_grad():
|
36 |
+
logits = call(audio_path_stream, model=model_mon, dataset_path="A-POR-LOS-8000/data/baby_cry_detection", filter_white_noise=False)
|
37 |
probabilities = torch.nn.functional.softmax(logits, dim=-1)
|
38 |
crying_probabilities = probabilities[:, 1]
|
39 |
avg_crying_probability = crying_probabilities.mean()*100
|
|
|
45 |
|
46 |
def decibelios(audio_path_stream):
|
47 |
with torch.no_grad():
|
48 |
+
logits = call(audio_path_stream, model=model_mon, dataset_path="A-POR-LOS-8000/data/baby_cry_detection", filter_white_noise=False)
|
49 |
rms = torch.sqrt(torch.mean(torch.square(logits)))
|
50 |
db_level = 20 * torch.log10(rms + 1e-6).item()
|
51 |
return db_level
|
model.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import os
|
2 |
import json
|
3 |
import random
|
|
|
4 |
import torch
|
5 |
import torchaudio
|
6 |
from torch.utils.data import Dataset, DataLoader
|
@@ -187,11 +188,18 @@ def load_config(model_name):
|
|
187 |
return model_config
|
188 |
|
189 |
if __name__ == "__main__":
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
|
|
|
|
|
|
194 |
training_args = config["training_args"]
|
195 |
output_dir = config["output_dir"]
|
196 |
dataset_path = config["dataset_path"]
|
|
|
|
|
|
|
|
|
197 |
main(training_args, output_dir, dataset_path, filter_white_noise)
|
|
|
1 |
import os
|
2 |
import json
|
3 |
import random
|
4 |
+
import argparse
|
5 |
import torch
|
6 |
import torchaudio
|
7 |
from torch.utils.data import Dataset, DataLoader
|
|
|
188 |
return model_config
|
189 |
|
190 |
if __name__ == "__main__":
|
191 |
+
parser = argparse.ArgumentParser()
|
192 |
+
parser.add_argument(
|
193 |
+
"--n", choices=["mon", "class"],
|
194 |
+
required=True, help="Elegir qué modelo entrenar"
|
195 |
+
)
|
196 |
+
args = parser.parse_args()
|
197 |
+
config = load_config(args.n)
|
198 |
training_args = config["training_args"]
|
199 |
output_dir = config["output_dir"]
|
200 |
dataset_path = config["dataset_path"]
|
201 |
+
if args.n == "mon":
|
202 |
+
filter_white_noise = False
|
203 |
+
elif args.n == "class":
|
204 |
+
filter_white_noise = True
|
205 |
main(training_args, output_dir, dataset_path, filter_white_noise)
|
models_config.json
CHANGED
@@ -1,12 +1,12 @@
|
|
1 |
{
|
2 |
"mon": {
|
3 |
-
"dataset_path": "data/baby_cry_detection",
|
4 |
-
"output_dir": "distilhubert-finetuned-cry-detector",
|
5 |
"training_args": {
|
6 |
-
"num_train_epochs":
|
7 |
-
"learning_rate": 0.
|
8 |
"warmup_ratio": 0.001,
|
9 |
-
"output_dir": "distilhubert-finetuned-cry-detector",
|
10 |
"eval_strategy": "epoch",
|
11 |
"save_strategy": "epoch",
|
12 |
"lr_scheduler_type": "cosine",
|
@@ -27,13 +27,13 @@
|
|
27 |
}
|
28 |
},
|
29 |
"class": {
|
30 |
-
"dataset_path": "data/mixed_data",
|
31 |
-
"output_dir": "distilhubert-finetuned-mixed-data",
|
32 |
"training_args": {
|
33 |
-
"num_train_epochs":
|
34 |
-
"learning_rate": 0.
|
35 |
-
"warmup_ratio": 0.
|
36 |
-
"output_dir": "distilhubert-finetuned-mixed-data",
|
37 |
"eval_strategy": "epoch",
|
38 |
"save_strategy": "epoch",
|
39 |
"lr_scheduler_type": "cosine",
|
@@ -44,7 +44,6 @@
|
|
44 |
"gradient_checkpointing": true,
|
45 |
"load_best_model_at_end": true,
|
46 |
"greater_is_better": true,
|
47 |
-
"metric_for_best_model": "accuracy",
|
48 |
"optim": "adamw_torch",
|
49 |
"hub_strategy": "checkpoint",
|
50 |
"report_to": "tensorboard",
|
|
|
1 |
{
|
2 |
"mon": {
|
3 |
+
"dataset_path": "A-POR-LOS-8000/data/baby_cry_detection",
|
4 |
+
"output_dir": "A-POR-LOS-8000/distilhubert-finetuned-cry-detector",
|
5 |
"training_args": {
|
6 |
+
"num_train_epochs": 10,
|
7 |
+
"learning_rate": 0.00003,
|
8 |
"warmup_ratio": 0.001,
|
9 |
+
"output_dir": "A-POR-LOS-8000/distilhubert-finetuned-cry-detector",
|
10 |
"eval_strategy": "epoch",
|
11 |
"save_strategy": "epoch",
|
12 |
"lr_scheduler_type": "cosine",
|
|
|
27 |
}
|
28 |
},
|
29 |
"class": {
|
30 |
+
"dataset_path": "A-POR-LOS-8000/data/mixed_data",
|
31 |
+
"output_dir": "A-POR-LOS-8000/distilhubert-finetuned-mixed-data",
|
32 |
"training_args": {
|
33 |
+
"num_train_epochs": 15,
|
34 |
+
"learning_rate": 0.0003,
|
35 |
+
"warmup_ratio": 0.4,
|
36 |
+
"output_dir": "A-POR-LOS-8000/distilhubert-finetuned-mixed-data",
|
37 |
"eval_strategy": "epoch",
|
38 |
"save_strategy": "epoch",
|
39 |
"lr_scheduler_type": "cosine",
|
|
|
44 |
"gradient_checkpointing": true,
|
45 |
"load_best_model_at_end": true,
|
46 |
"greater_is_better": true,
|
|
|
47 |
"optim": "adamw_torch",
|
48 |
"hub_strategy": "checkpoint",
|
49 |
"report_to": "tensorboard",
|