Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
os.system('pip install gradio --upgrade')
|
3 |
+
os.system('pip freeze')
|
4 |
+
import torch
|
5 |
+
import gradio as gr
|
6 |
+
model = torch.hub.load("PeterL1n/RobustVideoMatting", "mobilenetv3") # or "resnet50"
|
7 |
+
|
8 |
+
convert_video = torch.hub.load("PeterL1n/RobustVideoMatting", "converter")
|
9 |
+
|
10 |
+
def inference(video):
|
11 |
+
convert_video(
|
12 |
+
model, # The loaded model, can be on any device (cpu or cuda).
|
13 |
+
input_source=video, # A video file or an image sequence directory.
|
14 |
+
input_resize=(400, 400), # [Optional] Resize the input (also the output).
|
15 |
+
downsample_ratio=0.25, # [Optional] If None, make downsampled max size be 512px.
|
16 |
+
output_type='video', # Choose "video" or "png_sequence"
|
17 |
+
output_composition='com.mp4', # File path if video; directory path if png sequence.
|
18 |
+
output_alpha= None, # [Optional] Output the raw alpha prediction.
|
19 |
+
output_foreground= None, # [Optional] Output the raw foreground prediction.
|
20 |
+
output_video_mbps=4, # Output video mbps. Not needed for png sequence.
|
21 |
+
seq_chunk=7, # Process n frames at once for better parallelism.
|
22 |
+
num_workers=1, # Only for image sequence input. Reader threads.
|
23 |
+
progress=True # Print conversion progress.
|
24 |
+
)
|
25 |
+
return 'com.mp4'
|
26 |
+
|
27 |
+
title = "Robust Video Matting"
|
28 |
+
description = "Gradio demo for Robust Video Matting. To use it, simply upload your video, or click one of the examples to load them. Read more at the links below."
|
29 |
+
|
30 |
+
article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2108.11515'>Robust High-Resolution Video Matting with Temporal Guidance</a> | <a href='https://github.com/PeterL1n/RobustVideoMatting'>Github Repo</a></p>"
|
31 |
+
|
32 |
+
examples = [['pexels-darina-belonogova-7539228.mp4']]
|
33 |
+
gr.Interface(
|
34 |
+
inference,
|
35 |
+
gr.inputs.Video(label="Input"),
|
36 |
+
gr.outputs.Video(label="Output"),
|
37 |
+
title=title,
|
38 |
+
description=description,
|
39 |
+
article=article,
|
40 |
+
enable_queue=True,
|
41 |
+
examples=examples
|
42 |
+
).launch(debug=True)
|