(video_file)
| 56 | |
| 57 | #Perform classification |
| 58 | def classify(video_file): |
| 59 | if video_file is None: |
| 60 | return {"No video": 1.0} |
| 61 | |
| 62 | Z = d2.extract_dinov2_embeddings([video_file], device=device) |
| 63 | features = d2.features_from_Z(Z) |
| 64 | |
| 65 | if isinstance(features, torch.Tensor): |
| 66 | features = features.cpu().numpy() |
| 67 | |
| 68 | x = (features - mean.squeeze()) / std.squeeze() |
| 69 | x = x.astype(np.float32) |
| 70 | x_tensor = torch.from_numpy(x).unsqueeze(0).to(device) |
| 71 | |
| 72 | with torch.no_grad(): |
| 73 | logits = model(x_tensor) |
| 74 | prob = torch.sigmoid(logits).cpu().numpy().item() |
| 75 | |
| 76 | return {"REAL": prob, "FAKE": 1 - prob} |
| 77 | |
| 78 | with gr.Blocks(title="ReStrav Classifier") as demo: |
| 79 |
nothing calls this directly
no outgoing calls
no test coverage detected