Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
CHANGED
@@ -29,6 +29,7 @@ def get_demo_call(video_name):
|
|
29 |
return ump_out
|
30 |
|
31 |
def call_pitch(pitch):
|
|
|
32 |
std = (0.2104, 0.1986, 0.1829)
|
33 |
mean = (0.3939, 0.3817, 0.3314)
|
34 |
# Convert the mean and std to tensors
|
@@ -37,7 +38,7 @@ def call_pitch(pitch):
|
|
37 |
ump_out = get_demo_call(pitch)
|
38 |
pitch_tensor = (read_video(pitch,pts_unit='sec')[0].permute(-1,0,1,2)).unsqueeze(0)/255
|
39 |
pitch_tensor = (pitch_tensor-mean)/std #normalize the pitch tensor
|
40 |
-
video_length = pitch_tensor.shape[2]
|
41 |
model = MobileNetSmall3D()
|
42 |
model.load_state_dict(torch.load('weights/MobileNetSmall.pth',map_location=torch.device('cpu')))
|
43 |
model.eval()
|
@@ -47,7 +48,9 @@ def call_pitch(pitch):
|
|
47 |
output = model(pitch_tensor)
|
48 |
output = F.softmax(output,dim=1)
|
49 |
final_call = classify_pitch(output)
|
50 |
-
#time.sleep(video_length) #wait until the video is done to return the call
|
|
|
|
|
51 |
|
52 |
return final_call,ump_out
|
53 |
|
|
|
29 |
return ump_out
|
30 |
|
31 |
def call_pitch(pitch):
|
32 |
+
start = time.time()
|
33 |
std = (0.2104, 0.1986, 0.1829)
|
34 |
mean = (0.3939, 0.3817, 0.3314)
|
35 |
# Convert the mean and std to tensors
|
|
|
38 |
ump_out = get_demo_call(pitch)
|
39 |
pitch_tensor = (read_video(pitch,pts_unit='sec')[0].permute(-1,0,1,2)).unsqueeze(0)/255
|
40 |
pitch_tensor = (pitch_tensor-mean)/std #normalize the pitch tensor
|
41 |
+
video_length = pitch_tensor.shape[2] #get video length to wait for the video to finish
|
42 |
model = MobileNetSmall3D()
|
43 |
model.load_state_dict(torch.load('weights/MobileNetSmall.pth',map_location=torch.device('cpu')))
|
44 |
model.eval()
|
|
|
48 |
output = model(pitch_tensor)
|
49 |
output = F.softmax(output,dim=1)
|
50 |
final_call = classify_pitch(output)
|
51 |
+
# time.sleep(video_length-1.5) #wait until the video is done to return the call
|
52 |
+
while time.time() - start < (video_length-5)/15: #wait until the video is done to return the call and go 2 frames early to seem speedy
|
53 |
+
time.sleep(0.1)
|
54 |
|
55 |
return final_call,ump_out
|
56 |
|