Commit
·
4875545
1
Parent(s):
71736ce
updates
Browse files- .gitignore +2 -0
- models.py +11 -0
- preprocess.py +10 -0
- script.py +5 -4
.gitignore
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
__pycache__
|
| 2 |
+
submission.csv
|
models.py
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
|
| 3 |
+
class Model(torch.nn.Module):
|
| 4 |
+
def __init__(self):
|
| 5 |
+
super(Model, self).__init__()
|
| 6 |
+
self.fc1 = torch.nn.Linear(10, 5)
|
| 7 |
+
self.threshold = 0.
|
| 8 |
+
|
| 9 |
+
def forward(self, x):
|
| 10 |
+
## generates a random float the same size as x
|
| 11 |
+
return torch.randn(x.shape[0]).to(x.device)
|
preprocess.py
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import librosa
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
def preprocess(audio_file):
|
| 6 |
+
# Load the audio file
|
| 7 |
+
y, sr = librosa.load(audio_file, sr=None)
|
| 8 |
+
mfccs = librosa.feature.mfcc(y=y, sr=sr, n_mfcc=13)
|
| 9 |
+
tensor = torch.from_numpy(mfccs)[None]
|
| 10 |
+
return tensor
|
script.py
CHANGED
|
@@ -4,6 +4,7 @@ import numpy as np
|
|
| 4 |
import tqdm.auto as tqdm
|
| 5 |
import os
|
| 6 |
import io
|
|
|
|
| 7 |
|
| 8 |
# Import your model and anything else you want
|
| 9 |
# You can even install other packages included in your repo
|
|
@@ -14,7 +15,7 @@ import io
|
|
| 14 |
# It can be pulled here https://hub.docker.com/r/huggingface/competitions/tags
|
| 15 |
|
| 16 |
from models import Model
|
| 17 |
-
from preprocess import
|
| 18 |
|
| 19 |
|
| 20 |
# load the dataset. dataset will be automatically downloaded to /tmp/data during evaluation
|
|
@@ -38,7 +39,7 @@ for el in tqdm.tqdm(dataset_remote):
|
|
| 38 |
|
| 39 |
# if you are using libraries that expect a file. You can use BytesIO object
|
| 40 |
file_like = io.BytesIO(el["audio"]["bytes"])
|
| 41 |
-
tensor =
|
| 42 |
|
| 43 |
with torch.no_grad():
|
| 44 |
# soft decision (such as log likelihood score)
|
|
@@ -50,9 +51,9 @@ for el in tqdm.tqdm(dataset_remote):
|
|
| 50 |
pred = "generated" if score > model.threshold else "pristine"
|
| 51 |
|
| 52 |
# append your prediction
|
| 53 |
-
# "id" and "pred" are required. "score" will not be used in scoring but we encourage you to include it. We'll use for analysis of the results
|
| 54 |
|
| 55 |
-
out.append(dict(id = el["id"], pred = pred, score = score))
|
| 56 |
|
| 57 |
# save the final result and that's it
|
| 58 |
pd.DataFrame(out).to_csv("submission.csv",index = False)
|
|
|
|
| 4 |
import tqdm.auto as tqdm
|
| 5 |
import os
|
| 6 |
import io
|
| 7 |
+
import torch
|
| 8 |
|
| 9 |
# Import your model and anything else you want
|
| 10 |
# You can even install other packages included in your repo
|
|
|
|
| 15 |
# It can be pulled here https://hub.docker.com/r/huggingface/competitions/tags
|
| 16 |
|
| 17 |
from models import Model
|
| 18 |
+
from preprocess import preprocess
|
| 19 |
|
| 20 |
|
| 21 |
# load the dataset. dataset will be automatically downloaded to /tmp/data during evaluation
|
|
|
|
| 39 |
|
| 40 |
# if you are using libraries that expect a file. You can use BytesIO object
|
| 41 |
file_like = io.BytesIO(el["audio"]["bytes"])
|
| 42 |
+
tensor = preprocess(file_like)
|
| 43 |
|
| 44 |
with torch.no_grad():
|
| 45 |
# soft decision (such as log likelihood score)
|
|
|
|
| 51 |
pred = "generated" if score > model.threshold else "pristine"
|
| 52 |
|
| 53 |
# append your prediction
|
| 54 |
+
# "id" and "pred" are required. "score" will not be used in scoring but we encourage you to include it. We'll use it for analysis of the results
|
| 55 |
|
| 56 |
+
out.append(dict(id = el["id"], pred = pred, score = score))
|
| 57 |
|
| 58 |
# save the final result and that's it
|
| 59 |
pd.DataFrame(out).to_csv("submission.csv",index = False)
|