Real-world Anomaly Detection in Surveillance Videos
- Publication
- CVPR 2018Conference
- First submitted to arXiv
- arXiv:1801.04264
Cite this paper · BibTeX
The citation identifies the linked source version. It cites the original paper and its authors.
@misc{anomalydetectionucfcrime2018,
title = {{Real-world Anomaly Detection in Surveillance Videos}},
author = {Waqas Sultani and Chen Chen and Mubarak Shah},
year = {2018},
eprint = {1801.04264},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/1801.04264}
}
On street corners, in banks and in stores, surveillance cameras keep multiplying, but the number of people watching the screens hasn't grown with them. One guard faces a whole wall of feeds, and the time when something actually happens may add up to a few seconds a day.
Video anomaly detection at the time mostly learned from normal footage alone. Sparse coding first builds a "dictionary" from normal clips, and at test time anything it reconstructs poorly counts as an anomaly; autoencoders work much the same way, raising an alarm when the reconstruction error is large. These methods assume that everything normal can be listed in full. Surveillance cameras film the real world, where day differs from night and weekdays differ from holidays, so normal behavior that hasn't shown up before is easily mistaken for an anomaly.
The datasets were a problem too. UCSD Ped1 and Ped2 have only 70 and 28 videos, all shot at one location, where the anomalies are bicycles or carts on the sidewalk; Avenue has 37, where the anomaly is someone throwing paper; UMN's five videos simply have people walk and then run; and the harassment, sudden illness and panic in BOSS are all played by actors.
Waqas Sultani of the Information Technology University in Pakistan, together with Chen Chen and Mubarak Shah of CRCV at the University of Central Florida, went in a different direction. Anomalous videos are used for training too, but each is labeled only with whether something happened in the video, not when it happened. To test the idea, they spent several months collecting and annotating a much larger dataset, which became UCF-Crime.
Defining the problem
If every segment of every video were labeled normal or anomalous, learning to rank would be simple to set up; anomalous segments just need to score higher than normal ones:
The trouble is annotation. A surveillance video easily runs from a few minutes to more than ten, the anomaly may last only a few seconds of it, and marking start and end times segment by segment is enormously laborious. Deciding "is there a fight in this video?", on the other hand, takes a single viewing.
So the authors wanted a way of training that consumes only video-level labels, and after training, the model still has to point out which part of the video had the incident.
Solving the problem

The video is the bag, the segments are what's inside
The authors borrow the setup of multiple instance learning (MIL). Each video is cut into 32 non-overlapping temporal segments; the whole video is a bag, and each segment is an instance.
A video containing an anomaly is a positive bag. At least one segment in it is anomalous, but nobody knows which. A normal video is a negative bag, and every segment in it is normal.
Since there's no telling which segment of a positive bag is the anomalous one, look at the most suspicious one. The ranking condition becomes a comparison between the highest score in each bag:
The top-scoring segment of a positive bag is the most likely place where something actually happened. The top-scoring segment of a negative bag is the normal segment that looks most like an anomaly, exactly the kind most prone to false alarms. Pushing these two scores apart trains "catch the anomaly" and "don't cry wolf" at the same time.
Writing the two bags' highest scores as and , this becomes a hinge loss:
Sparsity and smoothness
Comparing only the highest scores ignores the temporal structure of video. The authors add two constraints, both applied only to anomalous videos.
The first is sparsity. Real anomalies are usually short, and most segments of an anomalous video are still normal, so the scores of all its segments should add up to something small.
The second is smoothness. Video is continuous, so the anomaly scores of two adjacent segments shouldn't swing up and down.
These two terms are added after the ranking loss, and with a regularization term on the weights on top, that's the full objective. and are both set to .
The network itself is small
Features come from a pretrained C3D. Frames are first resized to 240×320 at 30 fps, FC6 features are computed once every 16 frames and L2-normalized, and the clip features within a segment are averaged into a 4096-dimensional segment feature.
Scoring is done by a three-layer fully connected network: 4096 dimensions in, then 512, 32 and 1 units, with 60% dropout between layers and a sigmoid on the last layer. The optimizer is Adagrad with a learning rate of 0.001, and each mini-batch randomly draws 30 positive bags and 30 negative bags.
The authors say they tried deeper networks and accuracy didn't improve; multi-scale, overlapping temporal segments made no difference either. The figure of 32 segments was set empirically.
The official code disagrees with the paper in two places. The Adagrad learning rate in the code is 0.01, ten times the paper's. And the ranking loss doesn't pair one anomalous video with one normal video; instead, each normal video's highest score is compared with the highest scores of all 30 anomalous videos in the batch, 30×30 hinge terms in all. Someone opened an issue in 2019 asking whether that line was a mistake, others were still chiming in with the same question in 2024, and the authors never responded.
UCF-Crime
The authors trained ten annotators to search YouTube and LiveLeak for surveillance footage, hunting for each kind of event with keywords in different languages such as French, Russian and Chinese. Edited videos, pranks, news clips, handheld footage, compilations and videos where the anomaly couldn't be made out were all thrown away.
They ended up with 950 unedited real-world anomalous videos, then collected 950 normal videos under the same conditions, for a total of 1900 videos and 128 hours.
The anomalies fall into 13 classes: abuse, arrest, arson, assault, road accident, burglary, explosion, fighting, robbery, shooting, stealing, shoplifting and vandalism. Class sizes are uneven, with 150 videos each for robbery and road accidents and only 50 for most classes.
| Dataset | Videos | Avg. frames | Total length |
|---|---|---|---|
| UCSD Ped1 | 70 | 201 | 5 min |
| UCSD Ped2 | 28 | 163 | 5 min |
| Avenue | 37 | 839 | 30 min |
| BOSS | 12 | 4,052 | 27 min |
| UCF-Crime | 1,900 | 7,247 | 128 h |
The training set has 800 normal and 810 anomalous videos; the test set has 150 normal and 140 anomalous. Training gets only video-level labels; for the anomalous test videos, several annotators each marked the start and end frames of the anomaly, and their marks were averaged.
Discussion
Evaluation uses frame-level ROC curves and AUC. The authors don't use EER, common in earlier work, on the grounds that EER measures poorly when the anomaly takes up only a small part of a long video.
| Method | AUC |
|---|---|
| Binary classifier (C3D + SVM) | 50.0 |
| Hasan et al. (autoencoder) | 50.6 |
| Lu et al. (sparse dictionary) | 65.51 |
| This paper, no constraints | 74.44 |
| This paper, sparsity + smoothness | 75.41 |

The binary classifier and the autoencoder both land around 50 AUC, about as good as a coin toss. Train a classifier with each whole anomalous video as one class, and most of what's in the features is normal footage, so the classifier gives almost every test video a very low score. The autoencoder learns normal patterns quite well, but it also gives high scores to normal footage it hasn't seen before.
The sparsity and smoothness constraints add just under 1 point of AUC. Most of the overall gain still comes from the simple fact of training on anomalous videos too.
The false alarm rate gives another angle. Using only the 150 normal test videos with a threshold of 50%, the autoencoder's false alarm rate is 27.2%, the sparse dictionary's 3.1%, and this paper's 1.9%.
How the model learns to find the spot

This figure shows the scores of one training video at different iteration counts. At 1000 iterations, the anomalous stretch and many normal segments all get high scores; as training goes on, the normal parts are gradually pushed down, and the high scores concentrate on the stretch where something actually happened.
The authors say the model eventually learns to "precisely localize" the anomaly. In the 8000-iteration panel, the score does rise where the anomaly begins, but it holds until around frame 480, while the annotated anomaly ends around frame 350. The start is right and the end is more than a hundred frames late; if that counts as precise, the standard is fairly generous.
Failure cases
The paper also shows two failure cases. In a night-time burglary video, someone climbs into an office through a window, but the scene is too dark and the model misses it; in the same video, flying insects in front of the lens trigger false alarms instead. In a normal video, a crowd suddenly gathers in the street to watch a relay race, and the model takes it for an anomaly.
Judging from these two examples, the "anomalies" the model catches look more like visual changes that are common in anomalous videos and rare in normal ones, such as a crowd suddenly gathering or the lens suddenly being blocked. Whether what happens on screen counts as a crime is something video-level labels can't teach it.
Using it for action recognition
The dataset also comes with the event class of every anomalous video. The authors take 50 videos per class, split them 75/25 into training and testing, and run four-fold cross-validation. C3D features with a nearest-neighbor classifier reach only 23.0% accuracy, and TCNN 28.4%.
Low image quality, long videos, anomalies that fill only a small part of them, and large changes in camera angle and lighting all make this hard going for ordinary action recognition models.
Conclusion
The method in this paper isn't complicated. Cut the video into 32 segments, compute C3D features, attach a small three-layer network, and use a MIL ranking loss to make the anomalous video's highest score beat the normal video's highest score.
Its most lasting influence comes from two choices. One is moving video anomaly detection from "learn only what's normal" to "learn both normal and anomalous, labeled only at the video level"; the other is the UCF-Crime dataset itself. For years afterward, weakly supervised video anomaly detection compared AUC on UCF-Crime almost without exception; what got swapped out was mostly the feature extractor and the scoring network, while the skeleton of cutting videos into segments and comparing top scores is still in use today.
As for the official code, getting a Python 2, Theano and Keras 1 stack running today means clearing several rounds of environment setup first, and the version-compatibility errors in the issue tracker have never been cleaned up.