kt-test-account commited on
Commit
05258dc
·
1 Parent(s): a6da9a0
Files changed (1) hide show
  1. script.py +11 -13
script.py CHANGED
@@ -12,7 +12,7 @@ import numpy as np
12
 
13
  # Import your model and anything else you want
14
  # You can even install other packages included in your repo
15
- # However, during the evaluation the container will not have access to the internet.
16
  # So you must include everything you need in your model repo.
17
 
18
 
@@ -23,23 +23,21 @@ import torch
23
  def preprocess_v1(file_like):
24
  file_like.seek(0)
25
  decoder = VideoDecoder(file_like)
26
- frames = decoder[0 : -1 : 20]
27
  frames = frames.float() / 255.0
28
  return frames
29
 
30
 
31
-
32
-
33
  def preprocess(file_like):
34
  # Open the video file
35
  file_like.seek(0)
36
  container = av.open(file_like)
37
  frames = []
38
  for frame in container.decode(video=0):
39
- frame_array = frame.to_ndarray(format='rgb24')
40
  frame_tensor = torch.from_numpy(frame_array).permute(2, 0, 1).float()
41
  frames.append(frame_tensor)
42
-
43
  video_tensor = torch.stack(frames)
44
  return video_tensor
45
 
@@ -48,16 +46,16 @@ class Model(torch.nn.Module):
48
  def __init__(self):
49
  super(Model, self).__init__()
50
  self.fc1 = torch.nn.Linear(10, 5)
51
- self.threshold = 0.
52
 
53
  def forward(self, x):
54
- ## generates a random float the same size as x
55
- return torch.randn(x.shape[0]).to(x.device)
56
 
57
 
58
  # load the dataset. dataset will be automatically downloaded to /tmp/data during evaluation
59
  DATASET_PATH = "/tmp/data"
60
- dataset_remote = load_dataset(DATASET_PATH, split = "test", streaming = True)
61
 
62
 
63
  # load your model
@@ -92,11 +90,11 @@ for el in tqdm.tqdm(dataset_remote):
92
  # append your prediction
93
  # "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
94
 
95
- out.append(dict(id = el["id"], pred = pred, score = score))
96
  except Exception as e:
97
  print(e)
98
  print("failed", el["id"])
99
- out.append(dict(id = el["id"]))
100
 
101
  # save the final result and that's it
102
- pd.DataFrame(out).to_csv("submission.csv",index = False)
 
12
 
13
  # Import your model and anything else you want
14
  # You can even install other packages included in your repo
15
+ # However, during the evaluation the container will not have access to the internet.
16
  # So you must include everything you need in your model repo.
17
 
18
 
 
23
  def preprocess_v1(file_like):
24
  file_like.seek(0)
25
  decoder = VideoDecoder(file_like)
26
+ frames = decoder[0:-1:20]
27
  frames = frames.float() / 255.0
28
  return frames
29
 
30
 
 
 
31
  def preprocess(file_like):
32
  # Open the video file
33
  file_like.seek(0)
34
  container = av.open(file_like)
35
  frames = []
36
  for frame in container.decode(video=0):
37
+ frame_array = frame.to_ndarray(format="rgb24")
38
  frame_tensor = torch.from_numpy(frame_array).permute(2, 0, 1).float()
39
  frames.append(frame_tensor)
40
+
41
  video_tensor = torch.stack(frames)
42
  return video_tensor
43
 
 
46
  def __init__(self):
47
  super(Model, self).__init__()
48
  self.fc1 = torch.nn.Linear(10, 5)
49
+ self.threshold = 0.0
50
 
51
  def forward(self, x):
52
+ ## generates a random float the same size as x
53
+ return torch.randn(x.shape[0]).to(x.device)
54
 
55
 
56
  # load the dataset. dataset will be automatically downloaded to /tmp/data during evaluation
57
  DATASET_PATH = "/tmp/data"
58
+ dataset_remote = load_dataset(DATASET_PATH, split="test", streaming=True)
59
 
60
 
61
  # load your model
 
90
  # append your prediction
91
  # "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
92
 
93
+ out.append(dict(id=el["id"], pred=pred, score=score))
94
  except Exception as e:
95
  print(e)
96
  print("failed", el["id"])
97
+ out.append(dict(id=el["id"]))
98
 
99
  # save the final result and that's it
100
+ pd.DataFrame(out).to_csv("submission.csv", index=False)