Views
No views yet
videomae-base on a subset of UCF Crime. Starting from that checkpoint, this model was further fine-tuned on the Bus Violence Dataset to close the domain gap to public-transport surveillance footage.jinmang2/ucf_crime) — inherited from the base checkpoint| Model | n | Accuracy | Error | FPR | FNR | Precision | Recall | TP | TN | FP | FN |
|---|---|---|---|---|---|---|---|---|---|---|---|
| Nikeytas/videomae-crime-detector-production-v1 (zero-shot, no bus-violence fine-tuning) | 280 | 0.48 | 0.52 | 0.64 | 0.40 | 0.48 | 0.60 | 84 | 50 | 90 | 56 |
| This model (fine-tuned on Bus Violence Dataset) | 280 | 0.87 | 0.13 | 0.11 | 0.14 | 0.88 | 0.86 | 120 | 124 | 16 | 20 |
pip install transformers torch torchvision opencv-python pillow1import torch
2from transformers import AutoModelForVideoClassification, AutoProcessor
3import cv2
4import numpy as np
5
6# Load model and processor
7model = AutoModelForVideoClassification.from_pretrained("<your-repo-id>")
8processor = AutoProcessor.from_pretrained("<your-repo-id>")
9
10def classify_video(video_path, num_frames=16):
11 cap = cv2.VideoCapture(video_path)
12 frames = []
13
14 total_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
15 indices = np.linspace(0, total_frames - 1, num_frames, dtype=int)
16
17 for idx in indices:
18 cap.set(cv2.CAP_PROP_POS_FRAMES, idx)
19 ret, frame = cap.read()
20 if ret:
21 frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
22 frames.append(frame_rgb)
23 cap.release()
24
25 inputs = processor(frames, return_tensors="pt")
26 with torch.no_grad():
27 outputs = model(**inputs)
28 predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
29 predicted_class = torch.argmax(predictions, dim=-1).item()
30 confidence = predictions[0][predicted_class].item()
31
32 label = "Violent" if predicted_class == 1 else "Non-Violent"
33 return label, confidence
34
35video_path = "path/to/your/video.mp4"
36prediction, confidence = classify_video(video_path)
37print(f"Prediction: {prediction} (Confidence: {confidence:.3f})")