kt-test-account commited on
Commit
c74c9ba
·
1 Parent(s): 4875545

adding time

Browse files
Files changed (1) hide show
  1. script.py +20 -12
script.py CHANGED
@@ -5,6 +5,7 @@ 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
@@ -32,28 +33,35 @@ model = Model().to(device)
32
  out = []
33
  for el in tqdm.tqdm(dataset_remote):
34
 
 
 
35
  # each element is a dict
36
  # el["id"] id of example and el["audio"] contains the audio file
37
  # el["audio"]["bytes"] contains bytes from reading the raw audio
38
  # el["audio"]["path"] containts the filename. This is just for reference and you cant actually load it
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)
46
- # positive score correspond to synthetic prediction
47
- # negative score correspond to pristine prediction
48
- score = model(tensor.to(device)).cpu().item()
49
 
50
- # we require a hard decision to be submited. so you need to pick a threshold
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)
 
5
  import os
6
  import io
7
  import torch
8
+ import time
9
 
10
  # Import your model and anything else you want
11
  # You can even install other packages included in your repo
 
33
  out = []
34
  for el in tqdm.tqdm(dataset_remote):
35
 
36
+ start_time = time.time()
37
+
38
  # each element is a dict
39
  # el["id"] id of example and el["audio"] contains the audio file
40
  # el["audio"]["bytes"] contains bytes from reading the raw audio
41
  # el["audio"]["path"] containts the filename. This is just for reference and you cant actually load it
42
 
43
  # if you are using libraries that expect a file. You can use BytesIO object
44
+ try:
45
+ file_like = io.BytesIO(el["audio"]["bytes"])
46
+ tensor = preprocess(file_like)
47
 
48
+ with torch.no_grad():
49
+ # soft decision (such as log likelihood score)
50
+ # positive score correspond to synthetic prediction
51
+ # negative score correspond to pristine prediction
52
+ score = model(tensor.to(device)).cpu().item()
53
 
54
+ # we require a hard decision to be submited. so you need to pick a threshold
55
+ pred = "generated" if score > model.threshold else "pristine"
56
 
57
+ # append your prediction
58
+ # "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
59
 
60
+ out.append(dict(id = el["id"], pred = pred, score = score, time = time.time() - start_time))
61
+ except Exception as e:
62
+ print(e)
63
+ print("failed", el["id"])
64
+ out.append(dict(id = el["id"]))
65
 
66
  # save the final result and that's it
67
  pd.DataFrame(out).to_csv("submission.csv",index = False)