Downloads · 30 days
0
Nikeytas/densenet121-best-crime-detector
densenet121-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 DenseNet-121 model fine-tuned for automated video crime detection, achieving an exceptional 81.98% F1 score on the UCF-Crime dataset.
Downloads · 30 days
0
Access
Public
Updated Jul 18, 2025
Repo size
101 MB
Likes
1
Public
Click a slice to open those files.
.pth101 MB · 100%
From the Hugging Face model README
This is a state-of-the-art DenseNet-121 model fine-tuned for automated video crime detection, achieving an exceptional 81.98% F1 score on the UCF-Crime dataset.
Performance Tier: 🥇 EXCELLENT TIER
Excellent performance suitable for production deployment
Model Type: Convolutional Neural Network
Description: Densely Connected Convolutional Network optimized for efficient video frame analysis with feature reuse
| Metric | Score | Benchmark Rank |
|---|---|---|
| F1 Score | 0.8198 | 🥇 EXCELLENT TIER |
| Precision | 0.8034 (estimated) | Excellent |
| Recall | 0.7870 (estimated) | Excellent |
| Accuracy | 0.7788 (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.8198
}
"""
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.8198
}
# 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-densenet121-best,
title = {DenseNet-121 for Video Crime Detection},
author = {Nikeytas},
year = {2024},
publisher = {Hugging Face},
url = {https://huggingface.co/Nikeytas/densenet121-best-crime-detector},
note = {F1 Score: 0.8198, Performance Tier: 🥇 EXCELLENT 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.