Downloads · 30 days
0
Nikeytas/google-vit-best-crime-detector
google-vit-best-crime-detector is a video classification model from Nikeytas. Use it for the video classification task on the model card, and read the license before you ship it in a product. It is set up for pytorch. The card lists the license as mit.
This is a state-of-the-art Google ViT model fine-tuned for automated video crime detection, achieving an exceptional 85.28% F1 score on the UCF-Crime dataset.
Downloads · 30 days
0
Access
Public
Updated Jul 18, 2025
Repo size
343 MB
Likes
1
Public
Click a slice to open those files.
.pth343 MB · 100%
From the Hugging Face model README
This is a state-of-the-art Google ViT model fine-tuned for automated video crime detection, achieving an exceptional 85.28% F1 score on the UCF-Crime dataset.
Performance Tier: 🏆 CHAMPION TIER
Outstanding performance in the top 5% of models for this task
Model Type: Vision Transformer (Video Adapted)
Description: Vision Transformer adapted for video analysis with patch-based tokenization and multi-head self-attention
| Metric | Score | Benchmark Rank |
|---|---|---|
| F1 Score | 0.8528 | 🏆 CHAMPION TIER |
| Precision | 0.8357 (estimated) | Excellent |
| Recall | 0.8187 (estimated) | Excellent |
| Accuracy | 0.8102 (estimated) | High |
import torch
import torchvision.transforms as transforms
from pathlib import Path
# Load the model
model = torch.load('model.pth', map_location='cpu')
model.eval()
# Preprocessing pipeline
transform = transforms.Compose([
transforms.Resize((224, 224)),
transforms.ToTensor(),
transforms.Normalize(mean=[0.485, 0.456, 0.406],
std=[0.229, 0.224, 0.225])
])
# Inference function
def predict_crime(video_frames):
"""
Predict if video contains criminal activity
Args:
video_frames: List of PIL Images or torch.Tensor
Returns:
dict: {
'prediction': 'crime' or 'normal',
'confidence': float,
'f1_score': 0.8528
}
"""
with torch.no_grad():
if isinstance(video_frames, list):
# Process frame sequence
frames = torch.stack([transform(frame) for frame in video_frames])
frames = frames.unsqueeze(0) # Add batch dimension
else:
frames = video_frames
# Model prediction
outputs = model(frames)
probabilities = torch.softmax(outputs, dim=1)
predicted_class = torch.argmax(probabilities, dim=1)
confidence = torch.max(probabilities, dim=1)[0]
return {
'prediction': 'crime' if predicted_class.item() == 1 else 'normal',
'confidence': confidence.item(),
'model_f1': 0.8528
}
# Example usage
# result = predict_crime(your_video_frames)
# print(f"Prediction: {result['prediction']} (Confidence: {result['confidence']:.3f})")
import cv2
import numpy as np
from PIL import Image
def load_video_frames(video_path, max_frames=16):
"""Load video frames for crime detection"""
cap = cv2.VideoCapture(video_path)
frames = []
frame_count = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
step = max(1, frame_count // max_frames)
for i in range(0, frame_count, step):
cap.set(cv2.CAP_PROP_POS_FRAMES, i)
ret, frame = cap.read()
if ret:
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
frames.append(Image.fromarray(frame))
if len(frames) >= max_frames:
break
cap.release()
return frames
# Process video file
video_frames = load_video_frames("path/to/video.mp4")
result = predict_crime(video_frames)
✅ Appropriate: Surveillance assistance, forensic analysis, research
⚠️ Caution Required: Real-time law enforcement, automated decision-making
❌ Not Recommended: Sole basis for legal proceedings, unsupervised deployment
If you use this model in your research or applications, please cite:
@model{crime-detection-google-vit-best,
title = {Google ViT for Video Crime Detection},
author = {Nikeytas},
year = {2024},
publisher = {Hugging Face},
url = {https://huggingface.co/Nikeytas/google-vit-best-crime-detector},
note = {F1 Score: 0.8528, Performance Tier: 🏆 CHAMPION TIER}
}
Disclaimer: This model is provided for research and development purposes. Users are responsible for ensuring ethical and legal compliance in their specific use cases.