Run this model with HF Jobs

Run basant18/MoBiLSTM-violence-detection on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.

Paste one of these prompts into your coding agent:

Fine-tune on my dataset

Use HF Jobs to fine-tune https://huggingface.co/basant18/MoBiLSTM-violence-detection. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.

Run batch inference

Use HF Jobs to run batch inference with https://huggingface.co/basant18/MoBiLSTM-violence-detection on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.

MoBiLSTM β€” Video Violence Detection (v1, 16 frames)

A video classifier that labels a short clip as NonViolence or Violence. It uses MobileNetV2 (ImageNet weights) to extract per-frame features and a Bidirectional LSTM to model how the frames change over time.

This is the first version (v1). A newer, better-evaluated version (v3, 32 frames, ~98% accuracy on a held-out validation split) is documented in the public Kaggle notebook: kaggle.com/code/basanttyasser/mobilstmv3

Full training notes for v1 are in MoBiLSTM_Violence_Detection.md.

Model details

Item Value
Feature extractor MobileNetV2 (ImageNet), last 40 layers trainable
Temporal model Bidirectional LSTM (32 units per direction)
Head Dense 256 β†’ 128 β†’ 64 β†’ 32 (ReLU, dropout 0.25) β†’ softmax (2 classes)
Input 16 frames per clip, 224 Γ— 224 Γ— 3, evenly spaced across the video, scaled to [0, 1]
Precision Mixed precision (mixed_float16)
File model.keras (~217 MB)

Training data

Real Life Violence Situations Dataset (Kaggle): 1,000 violence and 1,000 non-violence YouTube videos. Stratified 80 / 20 train / validation split.

Please cite the dataset authors: M. Soliman, M. Kamal, M. Nashed, Y. Mostafa, B. Chawky, D. Khattab, "Violence Recognition from Videos using Deep Learning Techniques", ICICIS 2019.

Training setup

  • Optimizer: SGD (learning rate 0.01, momentum 0.9), categorical cross-entropy
  • Callbacks: early stopping on val_accuracy (patience 10), ReduceLROnPlateau
  • Trained on Kaggle GPUs with automatic checkpoints and resume through Hugging Face

Results

Metric (last epoch) Value
Training accuracy 99.87%
Validation accuracy 95.31%
Validation loss 0.256

Note on evaluation. The classification report in MoBiLSTM_Violence_Detection.md (1,999 videos, 90% accuracy) was computed on the whole dataset, so it includes the training videos. It is not a held-out test result. Use the validation figures above for v1, and the v3 notebook for a cleaner held-out evaluation.

Limitations

  • Overfits: about 4.5 points between training (99.87%) and validation (95.31%) accuracy.
  • Trained only on one public dataset of YouTube clips. Accuracy on CCTV, low-light, or very different footage is unknown.
  • The whole-dataset report suggests a noticeable number of violent clips are missed (violence recall about 0.81), so it is not suitable for safety-critical use.
  • Only 16 frames are sampled per clip, so very short events in a long video can be missed.

Usage

import os
os.environ["KERAS_BACKEND"] = "tensorflow"
import cv2, numpy as np, keras

model = keras.saving.load_model("hf://basant18/MoBiLSTM-violence-detection")

def load_clip(path, n=16, size=224):
    cap = cv2.VideoCapture(path)
    frames = []
    while True:
        ok, f = cap.read()
        if not ok:
            break
        frames.append(cv2.cvtColor(cv2.resize(f, (size, size)), cv2.COLOR_BGR2RGB))
    cap.release()
    idx = np.linspace(0, len(frames) - 1, n, dtype=int)
    return np.array([frames[i] for i in idx], dtype="float32") / 255.0

probs = model.predict(load_clip("clip.mp4")[None, ...])[0]
print(dict(zip(["NonViolence", "Violence"], probs.round(3))))

The frame preprocessing above follows the training notes (evenly spaced frames, resize to 224 Γ— 224, scale to [0, 1]).

Related

Intended use

Educational and research use. Predictions should be reviewed by a person, not used on their own to act against someone.

Downloads last month
20
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support