Spaces:
Running on Zero
Running on Zero
prismaudio-project commited on
Commit ·
3277c58
1
Parent(s): 8be4220
fix
Browse files
app.py
CHANGED
|
@@ -245,6 +245,22 @@ def extract_video_frames(video_path: str):
|
|
| 245 |
return clip_chunk, sync_chunk, duration_sec
|
| 246 |
|
| 247 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 248 |
# ==================== Feature Extraction ====================
|
| 249 |
@spaces.GPU
|
| 250 |
def extract_features_gpu(clip_chunk, sync_chunk, caption):
|
|
|
|
| 245 |
return clip_chunk, sync_chunk, duration_sec
|
| 246 |
|
| 247 |
|
| 248 |
+
def extract_features_cpu(clip_chunk, sync_chunk, caption):
|
| 249 |
+
model = _MODELS["feature_extractor"]
|
| 250 |
+
|
| 251 |
+
info = {}
|
| 252 |
+
with torch.no_grad():
|
| 253 |
+
# videoprism 是 CPU
|
| 254 |
+
clip_input = torch.from_numpy(clip_chunk).unsqueeze(0)
|
| 255 |
+
video_feat, frame_embed, _, text_feat = \
|
| 256 |
+
model.encode_video_and_text_with_videoprism(clip_input, [caption])
|
| 257 |
+
|
| 258 |
+
info['global_video_features'] = torch.tensor(np.array(video_feat)).squeeze(0).cpu()
|
| 259 |
+
info['video_features'] = torch.tensor(np.array(frame_embed)).squeeze(0).cpu()
|
| 260 |
+
info['global_text_features'] = torch.tensor(np.array(text_feat)).squeeze(0).cpu()
|
| 261 |
+
|
| 262 |
+
return info
|
| 263 |
+
|
| 264 |
# ==================== Feature Extraction ====================
|
| 265 |
@spaces.GPU
|
| 266 |
def extract_features_gpu(clip_chunk, sync_chunk, caption):
|