Spaces:
Paused
Paused
clear gpu vram for film
Browse files- libs/film/eval/interpolator.py +6 -0
- libs/film/predict.py +3 -0
- main.py +11 -2
libs/film/eval/interpolator.py
CHANGED
|
@@ -149,6 +149,10 @@ class Interpolator:
|
|
| 149 |
self._align = align or None
|
| 150 |
self._block_shape = block_shape or None
|
| 151 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
def interpolate(self, x0: np.ndarray, x1: np.ndarray,
|
| 153 |
dt: np.ndarray) -> np.ndarray:
|
| 154 |
"""Generates an interpolated frame between given two batches of frames.
|
|
@@ -171,6 +175,8 @@ class Interpolator:
|
|
| 171 |
result = self._model(inputs, training=False)
|
| 172 |
image = result['image']
|
| 173 |
|
|
|
|
|
|
|
| 174 |
if self._align is not None:
|
| 175 |
image = tf.image.crop_to_bounding_box(image, **bbox_to_crop)
|
| 176 |
return image.numpy()
|
|
|
|
| 149 |
self._align = align or None
|
| 150 |
self._block_shape = block_shape or None
|
| 151 |
|
| 152 |
+
def __del__(self):
|
| 153 |
+
del self._model
|
| 154 |
+
tf.keras.backend.clear_session()
|
| 155 |
+
|
| 156 |
def interpolate(self, x0: np.ndarray, x1: np.ndarray,
|
| 157 |
dt: np.ndarray) -> np.ndarray:
|
| 158 |
"""Generates an interpolated frame between given two batches of frames.
|
|
|
|
| 175 |
result = self._model(inputs, training=False)
|
| 176 |
image = result['image']
|
| 177 |
|
| 178 |
+
del self._model
|
| 179 |
+
|
| 180 |
if self._align is not None:
|
| 181 |
image = tf.image.crop_to_bounding_box(image, **bbox_to_crop)
|
| 182 |
return image.numpy()
|
libs/film/predict.py
CHANGED
|
@@ -68,4 +68,7 @@ class Predictor(cog.BasePredictor):
|
|
| 68 |
input_frames, times_to_interpolate, self.interpolator))
|
| 69 |
print('Interpolated frames generated.')
|
| 70 |
|
|
|
|
|
|
|
|
|
|
| 71 |
return frames
|
|
|
|
| 68 |
input_frames, times_to_interpolate, self.interpolator))
|
| 69 |
print('Interpolated frames generated.')
|
| 70 |
|
| 71 |
+
del self.interpolator
|
| 72 |
+
tf.keras.backend.clear_session()
|
| 73 |
+
|
| 74 |
return frames
|
main.py
CHANGED
|
@@ -64,7 +64,8 @@ import requests
|
|
| 64 |
import json
|
| 65 |
|
| 66 |
from huggingface_hub import hf_hub_download, HfApi
|
| 67 |
-
|
|
|
|
| 68 |
|
| 69 |
# Inputs ===================================================================================================
|
| 70 |
|
|
@@ -1220,7 +1221,7 @@ def run_app(images, video_path, train_steps=100, inference_steps=10, fps=12, bg_
|
|
| 1220 |
return out_vid+'.webm', results
|
| 1221 |
|
| 1222 |
|
| 1223 |
-
def
|
| 1224 |
film = Predictor()
|
| 1225 |
film.setup()
|
| 1226 |
|
|
@@ -1238,8 +1239,16 @@ def run_interpolate_frames(frame1, frame2, times_to_interp):
|
|
| 1238 |
for r in results:
|
| 1239 |
r.thumbnail((width, height))
|
| 1240 |
|
|
|
|
|
|
|
| 1241 |
return results, getThumbnails(results)
|
| 1242 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1243 |
|
| 1244 |
"""
|
| 1245 |
train_steps = 100
|
|
|
|
| 64 |
import json
|
| 65 |
|
| 66 |
from huggingface_hub import hf_hub_download, HfApi
|
| 67 |
+
from numba import cuda
|
| 68 |
+
from multiprocessing import Pool
|
| 69 |
|
| 70 |
# Inputs ===================================================================================================
|
| 71 |
|
|
|
|
| 1221 |
return out_vid+'.webm', results
|
| 1222 |
|
| 1223 |
|
| 1224 |
+
def interpolate_frames(frame1, frame2, times_to_interp):
|
| 1225 |
film = Predictor()
|
| 1226 |
film.setup()
|
| 1227 |
|
|
|
|
| 1239 |
for r in results:
|
| 1240 |
r.thumbnail((width, height))
|
| 1241 |
|
| 1242 |
+
del film
|
| 1243 |
+
|
| 1244 |
return results, getThumbnails(results)
|
| 1245 |
|
| 1246 |
+
def run_interpolate_frames(frame1, frame2, times_to_interp):
|
| 1247 |
+
with Pool() as pool:
|
| 1248 |
+
results = pool.starmap(interpolate_frames, [(frame1, frame2, times_to_interp)])
|
| 1249 |
+
print(results[0])
|
| 1250 |
+
return results[0]
|
| 1251 |
+
|
| 1252 |
|
| 1253 |
"""
|
| 1254 |
train_steps = 100
|