Spaces:
vztu
/
Runtime error

nanushio commited on
Commit
acc4b2f
1 Parent(s): a877246

- [MINOR] [SOURCE] [UPDATE] 1. update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -0
app.py CHANGED
@@ -23,6 +23,18 @@ mean_clip, std_clip = (
23
  torch.FloatTensor([68.50, 66.63, 70.32])
24
  )
25
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  def fuse_results(results: list):
27
  x = (results[0] + results[1] + results[2])
28
  return {
@@ -42,7 +54,19 @@ def inference_one_video(input_video):
42
 
43
  dopt = opt["data"]["val-ytugc"]["args"]
44
  temporal_samplers = {}
 
 
 
 
45
  for stype, sopt in dopt["sample_types"].items():
 
 
 
 
 
 
 
 
46
  temporal_samplers[stype] = UnifiedFrameSampler(
47
  sopt["clip_len"] // sopt["t_frag"],
48
  sopt["t_frag"],
 
23
  torch.FloatTensor([68.50, 66.63, 70.32])
24
  )
25
 
26
+ sample_interval = 30
27
+
28
+ def get_sampler_params(video_path):
29
+ vr = VideoReader(video_path)
30
+ total_frames = len(vr)
31
+ clip_len = (total_frames + sample_interval // 2) // sample_interval
32
+ if clip_len == 0:
33
+ clip_len = 1
34
+ t_frag = clip_len
35
+
36
+ return total_frames, clip_len, t_frag
37
+
38
  def fuse_results(results: list):
39
  x = (results[0] + results[1] + results[2])
40
  return {
 
54
 
55
  dopt = opt["data"]["val-ytugc"]["args"]
56
  temporal_samplers = {}
57
+
58
+ # auto decision of parameters of sampler
59
+ total_frames, clip_len, t_frag = get_sampler_params(input_video)
60
+
61
  for stype, sopt in dopt["sample_types"].items():
62
+ sopt["clip_len"] = clip_len
63
+ sopt["t_frag"] = t_frag
64
+ if stype == 'technical' or stype == 'aesthetic':
65
+ if total_frames > 1:
66
+ sopt["clip_len"] = clip_len * 2
67
+ if stype == 'technical':
68
+ sopt["aligned"] = sopt["clip_len"]
69
+ print(sopt["clip_len"], sopt["t_frag"])
70
  temporal_samplers[stype] = UnifiedFrameSampler(
71
  sopt["clip_len"] // sopt["t_frag"],
72
  sopt["t_frag"],