Upload 8 files
Browse files- README.md +8 -6
- app的副本.py +98 -0
- cat1.jpeg +0 -0
- cat2.jpeg +0 -0
- cat3.jpeg +0 -0
- cat4.jpeg +0 -0
- packages.txt +1 -0
- requirements.txt +12 -0
README.md
CHANGED
@@ -1,10 +1,12 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
-
sdk:
|
|
|
|
|
7 |
pinned: false
|
8 |
---
|
9 |
|
10 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces
|
|
|
1 |
---
|
2 |
+
title: Frame Interpolation
|
3 |
+
emoji: 🐢
|
4 |
+
colorFrom: blue
|
5 |
+
colorTo: gray
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 3.1.4
|
8 |
+
app_file: app.py
|
9 |
pinned: false
|
10 |
---
|
11 |
|
12 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces#reference
|
app的副本.py
ADDED
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import sys
|
3 |
+
import numpy as np
|
4 |
+
import tensorflow as tf
|
5 |
+
import mediapy
|
6 |
+
from PIL import Image
|
7 |
+
import gradio as gr
|
8 |
+
from huggingface_hub import snapshot_download
|
9 |
+
|
10 |
+
# Clone the repository and add the path
|
11 |
+
os.system("git clone https://github.com/google-research/frame-interpolation")
|
12 |
+
sys.path.append("frame-interpolation")
|
13 |
+
|
14 |
+
# Import after appending the path
|
15 |
+
from eval import interpolator, util
|
16 |
+
|
17 |
+
def load_model(model_name):
|
18 |
+
model = interpolator.Interpolator(snapshot_download(repo_id=model_name), None)
|
19 |
+
return model
|
20 |
+
|
21 |
+
model_names = [
|
22 |
+
"akhaliq/frame-interpolation-film-style",
|
23 |
+
"NimaBoscarino/frame-interpolation_film_l1",
|
24 |
+
"NimaBoscarino/frame_interpolation_film_vgg",
|
25 |
+
]
|
26 |
+
|
27 |
+
models = {model_name: load_model(model_name) for model_name in model_names}
|
28 |
+
|
29 |
+
ffmpeg_path = util.get_ffmpeg_path()
|
30 |
+
mediapy.set_ffmpeg(ffmpeg_path)
|
31 |
+
|
32 |
+
def resize(width, img):
|
33 |
+
img = Image.fromarray(img)
|
34 |
+
wpercent = (width / float(img.size[0]))
|
35 |
+
hsize = int((float(img.size[1]) * float(wpercent)))
|
36 |
+
img = img.resize((width, hsize), Image.LANCZOS)
|
37 |
+
return img
|
38 |
+
|
39 |
+
def resize_and_crop(img_path, size, crop_origin="middle"):
|
40 |
+
img = Image.open(img_path)
|
41 |
+
img = img.resize(size, Image.LANCZOS)
|
42 |
+
return img
|
43 |
+
|
44 |
+
def resize_img(img1, img2_path):
|
45 |
+
img_target_size = Image.open(img1)
|
46 |
+
img_to_resize = resize_and_crop(
|
47 |
+
img2_path,
|
48 |
+
(img_target_size.size[0], img_target_size.size[1]), # set width and height to match img1
|
49 |
+
crop_origin="middle"
|
50 |
+
)
|
51 |
+
img_to_resize.save('resized_img2.png')
|
52 |
+
|
53 |
+
def predict(frame1, frame2, frame3, frame4, frame5, frame6, times_to_interpolate, model_name):
|
54 |
+
model = models[model_name]
|
55 |
+
|
56 |
+
# Resize all frames
|
57 |
+
frames = [resize(1080, frame) for frame in [frame1, frame2, frame3, frame4, frame5, frame6]]
|
58 |
+
|
59 |
+
# Save and resize images
|
60 |
+
for i, frame in enumerate(frames):
|
61 |
+
frame.save(f"test{i+1}.png")
|
62 |
+
if i > 0: # Resize all except the first frame
|
63 |
+
resize_img(f"test1.png", f"test{i+1}.png")
|
64 |
+
|
65 |
+
input_frames = [f"test{i+1}.png" for i in range(6)]
|
66 |
+
|
67 |
+
# Interpolate using the model
|
68 |
+
interpolated_frames = list(util.interpolate_recursively_from_files(input_frames, times_to_interpolate, model))
|
69 |
+
|
70 |
+
mediapy.write_video("out.mp4", interpolated_frames, fps=30)
|
71 |
+
return "out.mp4"
|
72 |
+
|
73 |
+
title = "frame-interpolation"
|
74 |
+
description = "Gradio demo for FILM: Frame Interpolation for Large Scene Motion. To use it, simply upload your images and add the times to interpolate number or click on one of the examples to load them. Read more at the links below."
|
75 |
+
article = "<p style='text-align: center'><a href='https://film-net.github.io/' target='_blank'>FILM: Frame Interpolation for Large Motion</a> | <a href='https://github.com/google-research/frame-interpolation' target='_blank'>Github Repo</a></p>"
|
76 |
+
examples = [
|
77 |
+
['cat3.jpeg', 'cat4.jpeg', 'cat5.jpeg', 'cat6.jpeg', 'cat7.jpeg', 'cat8.jpeg', 2, model_names[0]],
|
78 |
+
['cat1.jpeg', 'cat2.jpeg', 'cat3.jpeg', 'cat4.jpeg', 'cat5.jpeg', 'cat6.jpeg', 2, model_names[1]],
|
79 |
+
]
|
80 |
+
|
81 |
+
gr.Interface(
|
82 |
+
fn=predict,
|
83 |
+
inputs=[
|
84 |
+
gr.Image(label="First Frame"),
|
85 |
+
gr.Image(label="Second Frame"),
|
86 |
+
gr.Image(label="Third Frame"),
|
87 |
+
gr.Image(label="Fourth Frame"),
|
88 |
+
gr.Image(label="Fifth Frame"),
|
89 |
+
gr.Image(label="Sixth Frame"),
|
90 |
+
gr.Number(label="Times to Interpolate", value=2),
|
91 |
+
gr.Dropdown(label="Model", choices=model_names),
|
92 |
+
],
|
93 |
+
outputs=gr.Video(label="Interpolated Frames"),
|
94 |
+
title=title,
|
95 |
+
description=description,
|
96 |
+
article=article,
|
97 |
+
examples=examples,
|
98 |
+
).launch()
|
cat1.jpeg
ADDED
cat2.jpeg
ADDED
cat3.jpeg
ADDED
cat4.jpeg
ADDED
packages.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
ffmpeg
|
requirements.txt
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
tensorflow>=2.6.2 # The latest should include tensorflow-gpu
|
2 |
+
tensorflow-datasets>=4.4.0
|
3 |
+
tensorflow-addons>=0.15.0
|
4 |
+
absl-py>=0.12.0
|
5 |
+
gin-config>=0.5.0
|
6 |
+
parameterized>=0.8.1
|
7 |
+
mediapy>=1.0.3
|
8 |
+
scikit-image>=0.19.1
|
9 |
+
apache-beam>=2.34.0
|
10 |
+
google-cloud-bigquery-storage>=1.1.0 # Suppresses a harmless error from beam
|
11 |
+
natsort>=8.1.0
|
12 |
+
image-tools
|