Commit
·
7d60514
1
Parent(s):
a47dac3
Initial version 🥳
Browse files
app.py
CHANGED
|
@@ -9,20 +9,19 @@ from skimage.transform import resize
|
|
| 9 |
from skimage import img_as_ubyte
|
| 10 |
from skimage.color import rgb2gray
|
| 11 |
|
| 12 |
-
|
| 13 |
-
from tensorflow import keras
|
| 14 |
|
| 15 |
# load model
|
| 16 |
-
model = keras
|
| 17 |
|
| 18 |
# Examples
|
| 19 |
samples = []
|
| 20 |
-
|
| 21 |
-
for video in
|
| 22 |
samples.append([f'asset/source/{video}', 0.5, True])
|
| 23 |
|
| 24 |
|
| 25 |
-
def inference(
|
| 26 |
split_pred = 0.4, # predict 0.6% of video
|
| 27 |
predict_one = False, # Whether to predict a sliding one frame or all frames at once
|
| 28 |
output_name = 'output.mp4',
|
|
@@ -30,19 +29,19 @@ def inference(driving,
|
|
| 30 |
cpu = False,
|
| 31 |
):
|
| 32 |
|
| 33 |
-
#
|
| 34 |
-
reader = imageio.get_reader(
|
| 35 |
fps = reader.get_meta_data()['fps']
|
| 36 |
-
|
| 37 |
try:
|
| 38 |
for im in reader:
|
| 39 |
-
|
| 40 |
except RuntimeError:
|
| 41 |
pass
|
| 42 |
reader.close()
|
| 43 |
-
|
| 44 |
|
| 45 |
-
example = np.array(
|
| 46 |
print(example.shape)
|
| 47 |
# Pick the first/last ten frames from the example.
|
| 48 |
start_pred_id = int(split_pred * example.shape[0]) # prediction starts from frame start_pred_id
|
|
|
|
| 9 |
from skimage import img_as_ubyte
|
| 10 |
from skimage.color import rgb2gray
|
| 11 |
|
| 12 |
+
from huggingface_hub.keras_mixin import from_pretrained_keras
|
|
|
|
| 13 |
|
| 14 |
# load model
|
| 15 |
+
model = from_pretrained_keras("keras-io/conv-lstm")
|
| 16 |
|
| 17 |
# Examples
|
| 18 |
samples = []
|
| 19 |
+
example_source = os.listdir('asset/source')
|
| 20 |
+
for video in example_source:
|
| 21 |
samples.append([f'asset/source/{video}', 0.5, True])
|
| 22 |
|
| 23 |
|
| 24 |
+
def inference(source,
|
| 25 |
split_pred = 0.4, # predict 0.6% of video
|
| 26 |
predict_one = False, # Whether to predict a sliding one frame or all frames at once
|
| 27 |
output_name = 'output.mp4',
|
|
|
|
| 29 |
cpu = False,
|
| 30 |
):
|
| 31 |
|
| 32 |
+
# source
|
| 33 |
+
reader = imageio.get_reader(source)
|
| 34 |
fps = reader.get_meta_data()['fps']
|
| 35 |
+
source_video = []
|
| 36 |
try:
|
| 37 |
for im in reader:
|
| 38 |
+
source_video.append(im)
|
| 39 |
except RuntimeError:
|
| 40 |
pass
|
| 41 |
reader.close()
|
| 42 |
+
source_video = [rgb2gray(resize(frame, (64, 64)))[..., np.newaxis] for frame in source_video]
|
| 43 |
|
| 44 |
+
example = np.array(source_video)
|
| 45 |
print(example.shape)
|
| 46 |
# Pick the first/last ten frames from the example.
|
| 47 |
start_pred_id = int(split_pred * example.shape[0]) # prediction starts from frame start_pred_id
|