Aryanikale23 commited on
Commit
233b873
1 Parent(s): c420afa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -15
app.py CHANGED
@@ -1,6 +1,6 @@
1
  import cv2
2
- import gradio as gr
3
  import imutils
 
4
  import numpy as np
5
  import torch
6
  from pytorchvideo.transforms import (
@@ -51,8 +51,7 @@ def parse_video(video_file):
51
  prop = (
52
  cv2.cv.CV_CAP_PROP_FRAME_COUNT
53
  if imutils.is_cv2()
54
- else cv2.CAP_PROP_FRAME_COUNT
55
- )
56
  total = int(vs.get(prop))
57
  print("[INFO] {} total frames in video".format(total))
58
 
@@ -91,13 +90,9 @@ def preprocess_video(frames: list):
91
  # to make it compatible with the model. Finally, we add a batch dimension so that our video
92
  # classification model can operate on it.
93
  video_tensor = torch.tensor(np.array(frames).astype(frames[0].dtype))
94
- video_tensor = video_tensor.permute(
95
- 3, 0, 1, 2
96
- ) # (num_channels, num_frames, height, width)
97
  video_tensor_pp = VAL_TRANSFORMS(video_tensor)
98
- video_tensor_pp = video_tensor_pp.permute(
99
- 1, 0, 2, 3
100
- ) # (num_frames, num_channels, height, width)
101
  video_tensor_pp = video_tensor_pp.unsqueeze(0)
102
  return video_tensor_pp.to(DEVICE)
103
 
@@ -115,16 +110,10 @@ def infer(video_file):
115
  confidences = {LABELS[i]: float(softmax_scores[i]) for i in range(len(LABELS))}
116
  return confidences
117
 
118
-
119
  gr.Interface(
120
  fn=infer,
121
  inputs=gr.Video(type="file"),
122
  outputs=gr.Label(num_top_classes=3),
123
- examples=[
124
- ["examples/babycrawling.mp4"],
125
- ["examples/baseball.mp4"],
126
- ["examples/balancebeam.mp4"],
127
- ],
128
  title="VideoMAE fine-tuned on a subset of UCF-101",
129
  description=(
130
  "Gradio demo for VideoMAE for video classification. To use it, simply upload your video or click one of the"
 
1
  import cv2
 
2
  import imutils
3
+ import gradio as gr
4
  import numpy as np
5
  import torch
6
  from pytorchvideo.transforms import (
 
51
  prop = (
52
  cv2.cv.CV_CAP_PROP_FRAME_COUNT
53
  if imutils.is_cv2()
54
+ else cv2.CAP_PROP_FRAME_COUNT)
 
55
  total = int(vs.get(prop))
56
  print("[INFO] {} total frames in video".format(total))
57
 
 
90
  # to make it compatible with the model. Finally, we add a batch dimension so that our video
91
  # classification model can operate on it.
92
  video_tensor = torch.tensor(np.array(frames).astype(frames[0].dtype))
93
+ video_tensor = video_tensor.permute(3, 0, 1, 2) # (num_channels, num_frames, height, width)
 
 
94
  video_tensor_pp = VAL_TRANSFORMS(video_tensor)
95
+ video_tensor_pp = video_tensor_pp.permute(1, 0, 2, 3) # (num_frames, num_channels, height, width)
 
 
96
  video_tensor_pp = video_tensor_pp.unsqueeze(0)
97
  return video_tensor_pp.to(DEVICE)
98
 
 
110
  confidences = {LABELS[i]: float(softmax_scores[i]) for i in range(len(LABELS))}
111
  return confidences
112
 
 
113
  gr.Interface(
114
  fn=infer,
115
  inputs=gr.Video(type="file"),
116
  outputs=gr.Label(num_top_classes=3),
 
 
 
 
 
117
  title="VideoMAE fine-tuned on a subset of UCF-101",
118
  description=(
119
  "Gradio demo for VideoMAE for video classification. To use it, simply upload your video or click one of the"