Spaces:
Sleeping
Sleeping
IlayMalinyak
commited on
Commit
·
82a319f
1
Parent(s):
766ed77
locally tested
Browse files
requirements.txt
CHANGED
Binary files a/requirements.txt and b/requirements.txt differ
|
|
tasks/audio.py
CHANGED
@@ -10,13 +10,21 @@ from torch.utils.data import DataLoader
|
|
10 |
from .utils.evaluation import AudioEvaluationRequest
|
11 |
from .utils.emissions import tracker, clean_emissions_data, get_space_info
|
12 |
from .utils.data import FFTDataset
|
13 |
-
from .utils.models import DualEncoder, CNNKan
|
14 |
from .utils.train import Trainer
|
15 |
from .utils.data_utils import collate_fn, Container
|
16 |
import yaml
|
17 |
import asyncio
|
18 |
from huggingface_hub import login
|
19 |
from collections import OrderedDict
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
|
22 |
|
@@ -28,6 +36,28 @@ router = APIRouter()
|
|
28 |
DESCRIPTION = "Conformer"
|
29 |
ROUTE = "/audio"
|
30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
@router.post(ROUTE, tags=["Audio Task"],
|
33 |
description=DESCRIPTION)
|
@@ -69,10 +99,13 @@ async def evaluate_audio(request: AudioEvaluationRequest):
|
|
69 |
model_args = Container(**yaml.safe_load(open(args_path, 'r'))['CNNEncoder'])
|
70 |
model_args_f = Container(**yaml.safe_load(open(args_path, 'r'))['CNNEncoder_f'])
|
71 |
conformer_args = Container(**yaml.safe_load(open(args_path, 'r'))['Conformer'])
|
|
|
72 |
kan_args = Container(**yaml.safe_load(open(args_path, 'r'))['KAN'])
|
73 |
|
74 |
-
test_dataset = FFTDataset(test_dataset)
|
75 |
-
test_dl = DataLoader(test_dataset, batch_size=data_args.batch_size
|
|
|
|
|
76 |
|
77 |
model = CNNKan(model_args, conformer_args, kan_args.get_dict())
|
78 |
model = model.to(device)
|
|
|
10 |
from .utils.evaluation import AudioEvaluationRequest
|
11 |
from .utils.emissions import tracker, clean_emissions_data, get_space_info
|
12 |
from .utils.data import FFTDataset
|
13 |
+
from .utils.models import DualEncoder, CNNKan, CNNKanFeaturesEncoder
|
14 |
from .utils.train import Trainer
|
15 |
from .utils.data_utils import collate_fn, Container
|
16 |
import yaml
|
17 |
import asyncio
|
18 |
from huggingface_hub import login
|
19 |
from collections import OrderedDict
|
20 |
+
import xgboost as xgb
|
21 |
+
from tqdm import tqdm
|
22 |
+
from sklearn.metrics import accuracy_score, classification_report, roc_auc_score
|
23 |
+
from sklearn.model_selection import train_test_split
|
24 |
+
import warnings
|
25 |
+
import pandas as pd
|
26 |
+
|
27 |
+
warnings.filterwarnings("ignore")
|
28 |
|
29 |
|
30 |
|
|
|
36 |
DESCRIPTION = "Conformer"
|
37 |
ROUTE = "/audio"
|
38 |
|
39 |
+
def create_dataframe(ds, save_name='test'):
|
40 |
+
data = []
|
41 |
+
# Iterate over the dataset
|
42 |
+
pbar = tqdm(enumerate(ds))
|
43 |
+
for i, batch in pbar:
|
44 |
+
label = batch['label']
|
45 |
+
features = batch['audio']['features']
|
46 |
+
|
47 |
+
# Flatten the nested dictionary structure
|
48 |
+
feature_dict = {'label': label}
|
49 |
+
for k, v in features.items():
|
50 |
+
if isinstance(v, dict):
|
51 |
+
for sub_k, sub_v in v.items():
|
52 |
+
feature_dict[f"{k}_{sub_k}"] = sub_v[0].item() # Aggregate (e.g., mean)
|
53 |
+
data.append(feature_dict)
|
54 |
+
# Convert to DataFrame
|
55 |
+
df = pd.DataFrame(data)
|
56 |
+
print(os.getcwd())
|
57 |
+
df.to_csv(f"tasks/utils/dfs/{save_name}.csv", index=False)
|
58 |
+
X = df.drop(columns=['label'])
|
59 |
+
y = df['label']
|
60 |
+
return X, y
|
61 |
|
62 |
@router.post(ROUTE, tags=["Audio Task"],
|
63 |
description=DESCRIPTION)
|
|
|
99 |
model_args = Container(**yaml.safe_load(open(args_path, 'r'))['CNNEncoder'])
|
100 |
model_args_f = Container(**yaml.safe_load(open(args_path, 'r'))['CNNEncoder_f'])
|
101 |
conformer_args = Container(**yaml.safe_load(open(args_path, 'r'))['Conformer'])
|
102 |
+
boost_args = Container(**yaml.safe_load(open(args_path, 'r'))['XGBoost'])
|
103 |
kan_args = Container(**yaml.safe_load(open(args_path, 'r'))['KAN'])
|
104 |
|
105 |
+
test_dataset = FFTDataset(test_dataset, features=False)
|
106 |
+
test_dl = DataLoader(test_dataset, batch_size=data_args.batch_size)
|
107 |
+
|
108 |
+
# Watchlist to monitor performance on train and validation data
|
109 |
|
110 |
model = CNNKan(model_args, conformer_args, kan_args.get_dict())
|
111 |
model = model.to(device)
|
tasks/models/frugal_2025-02-01/CNNEncoder_frugal_2.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
tasks/models/frugal_2025-02-01/frugal_kan_features_2.pth
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f6e20edd364e79003a08cfd4221ec8fc312c16898b1e4871159a8fd1864b791e
|
3 |
+
size 1876605
|
tasks/run.py
CHANGED
@@ -172,8 +172,8 @@ print(num_xgb_features)
|
|
172 |
# model = DualEncoder(model_args, model_args_f, conformer_args)
|
173 |
# model = FasterKAN([18000,64,64,16,1])
|
174 |
# model = CNNKan(model_args, conformer_args, kan_args.get_dict())
|
175 |
-
|
176 |
-
model = CNNFeaturesEncoder(xgb_model,model_args)
|
177 |
# model.kan.speed()
|
178 |
# model = KanEncoder(kan_args.get_dict())
|
179 |
model = model.to(local_rank)
|
|
|
172 |
# model = DualEncoder(model_args, model_args_f, conformer_args)
|
173 |
# model = FasterKAN([18000,64,64,16,1])
|
174 |
# model = CNNKan(model_args, conformer_args, kan_args.get_dict())
|
175 |
+
model = CNNKanFeaturesEncoder(xgb_model, model_args, kan_args.get_dict())
|
176 |
+
# model = CNNFeaturesEncoder(xgb_model,model_args)
|
177 |
# model.kan.speed()
|
178 |
# model = KanEncoder(kan_args.get_dict())
|
179 |
model = model.to(local_rank)
|
tasks/utils/config.yaml
CHANGED
@@ -5,7 +5,7 @@ Data:
|
|
5 |
dataset: "FFTDataset"
|
6 |
data_dir: None
|
7 |
model_name: "CNNEncoder"
|
8 |
-
batch_size:
|
9 |
num_epochs: 10
|
10 |
exp_num: 2
|
11 |
max_len_spectra: 4096
|
|
|
5 |
dataset: "FFTDataset"
|
6 |
data_dir: None
|
7 |
model_name: "CNNEncoder"
|
8 |
+
batch_size: 4
|
9 |
num_epochs: 10
|
10 |
exp_num: 2
|
11 |
max_len_spectra: 4096
|
tasks/utils/dfs/train_val.csv
CHANGED
The diff for this file is too large to render.
See raw diff
|
|
tasks/utils/train.py
CHANGED
@@ -226,14 +226,14 @@ class Trainer(object):
|
|
226 |
|
227 |
def train_batch(self, batch, batch_idx, device):
|
228 |
x, fft, y = batch['audio']['array'], batch['audio']['fft_mag'], batch['label']
|
229 |
-
features = batch['audio']['features']
|
230 |
# cwt = batch['audio']['cwt_mag']
|
231 |
x = x.to(device).float()
|
232 |
fft = fft.to(device).float()
|
233 |
# cwt = cwt.to(device).float()
|
234 |
y = y.to(device).float()
|
235 |
x_fft = torch.cat((x.unsqueeze(dim=1), fft.unsqueeze(dim=1)), dim=1)
|
236 |
-
y_pred = self.model(x_fft
|
237 |
loss = self.criterion(y_pred, y)
|
238 |
loss.backward()
|
239 |
self.optimizer.step()
|
@@ -267,7 +267,7 @@ class Trainer(object):
|
|
267 |
|
268 |
def eval_batch(self, batch, batch_idx, device):
|
269 |
x, fft, y = batch['audio']['array'], batch['audio']['fft_mag'], batch['label']
|
270 |
-
features = batch['audio']['features']
|
271 |
|
272 |
# features = batch['audio']['features_arr'].to(device).float()
|
273 |
x = x.to(device).float()
|
@@ -275,7 +275,7 @@ class Trainer(object):
|
|
275 |
x_fft = torch.cat((x.unsqueeze(dim=1), fft.unsqueeze(dim=1)), dim=1)
|
276 |
y = y.to(device).float()
|
277 |
with torch.no_grad():
|
278 |
-
y_pred = self.model(x_fft
|
279 |
loss = self.criterion(y_pred.squeeze(), y)
|
280 |
probs = torch.sigmoid(y_pred)
|
281 |
cls_pred = (probs > 0.5).float()
|
|
|
226 |
|
227 |
def train_batch(self, batch, batch_idx, device):
|
228 |
x, fft, y = batch['audio']['array'], batch['audio']['fft_mag'], batch['label']
|
229 |
+
# features = batch['audio']['features']
|
230 |
# cwt = batch['audio']['cwt_mag']
|
231 |
x = x.to(device).float()
|
232 |
fft = fft.to(device).float()
|
233 |
# cwt = cwt.to(device).float()
|
234 |
y = y.to(device).float()
|
235 |
x_fft = torch.cat((x.unsqueeze(dim=1), fft.unsqueeze(dim=1)), dim=1)
|
236 |
+
y_pred = self.model(x_fft).squeeze()
|
237 |
loss = self.criterion(y_pred, y)
|
238 |
loss.backward()
|
239 |
self.optimizer.step()
|
|
|
267 |
|
268 |
def eval_batch(self, batch, batch_idx, device):
|
269 |
x, fft, y = batch['audio']['array'], batch['audio']['fft_mag'], batch['label']
|
270 |
+
# features = batch['audio']['features']
|
271 |
|
272 |
# features = batch['audio']['features_arr'].to(device).float()
|
273 |
x = x.to(device).float()
|
|
|
275 |
x_fft = torch.cat((x.unsqueeze(dim=1), fft.unsqueeze(dim=1)), dim=1)
|
276 |
y = y.to(device).float()
|
277 |
with torch.no_grad():
|
278 |
+
y_pred = self.model(x_fft).squeeze()
|
279 |
loss = self.criterion(y_pred.squeeze(), y)
|
280 |
probs = torch.sigmoid(y_pred)
|
281 |
cls_pred = (probs > 0.5).float()
|