Back to paper library
arXiv 2023IEEE TCSVT 2024Anomaly detectionPaper notes

BN-WVAD

Spot the Outlier

Original paper

BatchNorm-based Weakly Supervised Video Anomaly Detection

Paper authors

Yixuan Zhou · Yi Qu · Xing Xu · Fumin Shen · Jingkuan Song · Heng Tao Shen

First submitted to arXiv
arXiv:2311.15367
Cite this paper · BibTeX

The citation identifies the linked source version. It cites the original paper and its authors.

@misc{anomalydetectionbnwvad2023,
  title = {{BatchNorm-based Weakly Supervised Video Anomaly Detection}},
  author = {Yixuan Zhou and Yi Qu and Xing Xu and Fumin Shen and Jingkuan Song and Heng Tao Shen},
  year = {2023},
  eprint = {2311.15367},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2311.15367}
}
On this page

However many modules a weakly supervised video anomaly detection method wraps around itself, there's one step inside that they all share. During training, nobody knows which segments of an anomalous video actually contain the incident, so you first have to set a criterion, pick out the most suspicious few segments, and train on them as pseudo-labels.

RTFM's criterion is the feature norm, where a large norm means suspicious; UR-DMU's is how much a segment looks like the anomaly memory. The way they pick is much the same too, always taking the top kk segments by score from each video.

Yixuan Zhou, Yi Qu, Fumin Shen, Xing Xu, Jingkuan Song and Heng Tao Shen of the University of Electronic Science and Technology of China turned their attention to a layer that every network has and hardly anyone gives a second look, BatchNorm.

Defining the problem

The authors list three problems with existing methods.

First, the criteria for picking suspicious segments are unreliable. The feature norm rests on the premise that "anomalous segments have larger norms," which is merely a plausible-looking assumption; picking with learned attention or memories is a black box.

Second, taking a fixed number of segments from every video ignores how much the anomaly ratio varies from video to video. Some videos have only a few seconds of incident; in others the fighting runs from start to finish. The XD-Violence test set has an especially large number of videos with high and scattered anomaly ratios. Pick only kk segments from each, and the videos with high anomaly ratios lose a whole lot of useful anomalous segments.

Third, wrong picks are bound to happen. As soon as normal segments are taken as anomalous and used to train the classifier, those wrong labels lead the classifier astray, and MIL can only mitigate this, not cure it.

Solving the problem

Original Figure 2. A sketch of the BatchNorm mean and the MPP loss. On the left, before training, a black arrow on the horizontal axis marks the BatchNorm mean, surrounded by the gray outline of a normal distribution; green dots are normal segments from normal videos and orange dots are normal segments from anomalous videos, mostly falling inside the distribution; orange crosses are anomalous segments, lying out on both sides of the distribution, with their distance to the mean labeled DFM. Green arrows pull normal segments outside the distribution toward the mean, and red arrows push anomalous segments outward. On the right, after training, the normal segments cluster around the mean and the anomalous segments have been pushed far outside the distribution.
Original Figure 2, Zhou et al., from PDF page 2, arXiv license, scholarly quotation.

The BatchNorm mean is "normal"

By convention, weakly supervised video anomaly detection fills each mini-batch with half normal videos and half anomalous videos. Normal videos are all normal segments, and most of an anomalous video is normal segments too, so the vast majority of segments in a batch are normal.

BatchNorm already computes the mean and variance of features over the whole batch. With a batch made up like this, the mean is determined mainly by normal segments and can serve as a reference point for "normal," while anomalous segments look more like outliers. What's more, this reference point also absorbs the normal segments inside anomalous videos, a part the authors think explicit memory modules like UR-DMU's don't make good use of.

The paper also cites the central limit theorem to say that the features in a batch follow a normal distribution. Strictly speaking, the central limit theorem is about the distribution of the sample mean, which is a different matter from what the features themselves look like, but this has no effect on how the method that follows works.

DFM: how far from the mean

If the mean stands for normal, the farther a segment is from it, the more suspicious it is. The authors call this distance DFM (divergence of feature from mean) and compute it as a Mahalanobis distance with a diagonal covariance:

DFM(x)=(x−μ^)⊤Σ−1(x−μ^)\mathrm{DFM}(x) = \sqrt{(x - \hat{\mu})^{\top} \Sigma^{-1} (x - \hat{\mu})}

Σ\Sigma is a diagonal matrix with the per-dimension variances σ^2\hat{\sigma}^2 on its diagonal. The μ^\hat{\mu} and σ^2\hat{\sigma}^2 here are BatchNorm's running statistics, the long-term statistics kept as an exponential moving average with momentum 0.1, rather than the values of a single batch. That's more stable, and training and testing use the same reference point.

To make DFM more discriminative, the authors design the MPP (mean-based pull-push) loss. The idea is borrowed from triplet loss, except that the anchor is always the mean μ^\hat{\mu}. The KK segments with the largest DFM in normal videos are the positives, to be pulled back near the mean; the KK segments with the largest DFM in anomalous videos are the negatives, to be pushed farther away:

Lmpp=1K∑k=1Kmax⁡(0, m+DFM(xkn)−DFM(xka))\begin{aligned} \mathcal{L}_{mpp} = \frac{1}{K} \sum_{k=1}^{K} \max\big(0,\ & m + \mathrm{DFM}(x^n_k) \\ & - \mathrm{DFM}(x^a_k)\big) \end{aligned}

The margin mm is set to 1. The paper's equation leaves out the outer max⁡(0,⋅)\max(0, \cdot); the official code uses PyTorch's TripletMarginWithDistanceLoss, which has it.

Pick per video, and per batch too

Original Figure 4. A sketch of three selection strategies. Four rows stand for four anomalous videos in a batch, five segments each, with criterion scores in the cells; both selection ratios are 40%. (a) Each video picks its two highest-scoring cells, so the 0.8 and 0.7 in the fourth row aren't selected. (b) The whole batch picks its eight highest-scoring cells together, so all four cells of the fourth row are chosen, while the first row, with its 0.3 and 0.4, gets none. (c) The union of (a) and (b); blue cells are picked per video, and green cells are the extras added by batch-level picking.
Original Figure 4, Zhou et al., from PDF page 5, arXiv license, scholarly quotation.

For the second problem, the authors' guess is that the anomaly ratio varies a lot from one video to another, but stays relatively stable over a whole batch. So besides picking a fixed proportion from each video (sample-level selection, SLS), you can also lay out all the anomalous videos in a batch together and pick from them as a whole (batch-level selection, BLS).

In the figure's example, picking two cells per video takes only two from the fourth video, even though it has four high-scoring cells. Picking eight cells across the batch takes all of the fourth video, but the first video, whose anomaly scores are all low, doesn't get a single cell picked. The union of the two is the authors' sample-batch selection (SBS).

Selection ratios are set per dataset. UCF-Crime picks 10% per video and 20% per batch; XD-Violence picks 20% per video and 40% per batch.

The classifier sees only normal videos

Original Figure 3. The overall architecture of BN-WVAD. Paired normal and anomalous videos go through a frozen I3D and a feature enhancer to get X^e, followed by Conv1d, BatchNorm and ReLU. Normal videos use per-video selection (SLS) and anomalous videos use SBS; the selected features and the BatchNorm mean together give the MPP loss, with the mean as the anchor, the selected normal features pulled inward and the anomalous features pushed outward. The anomaly classifier on the right, made of Conv1d and a Sigmoid, is trained only with L_nor on normal videos; the final anomaly score is the element-wise product of the classifier output and DFM.
Original Figure 3, Zhou et al., from PDF page 4, arXiv license, scholarly quotation.

For the third problem, the authors' answer is blunt. The classifier never takes an anomaly label at all.

The classifier is trained only on normal videos, pushing the output scores of all their segments toward 0:

Lnor=∑b∥C(ReLU(BN(Xbn)))∥2\mathcal{L}_{nor} = \sum_{b} \big\lVert C(\mathrm{ReLU}(\mathrm{BN}(X^n_b))) \big\rVert_2

The suspicious segments that get picked are used only for the MPP loss and never directly as positives for the classifier. Since they're never treated as positives, wrongly picked segments have no way to teach the classifier bad habits.

The final anomaly score multiplies two signals, the classifier's output and DFM:

Score=C(ReLU(BN(Xh)))⋅DFM(Xh)\mathrm{Score} = C(\mathrm{ReLU}(\mathrm{BN}(X^h))) \cdot \mathrm{DFM}(X^h)

In the implementation, the features follow UR-DMU's setup, with I3D features interpolated to 200 segments and passed through UR-DMU's Transformer feature enhancer. After that come two Conv1d layers with kernel size 1 and outputs of 32 and 16 dimensions, each followed by BatchNorm and ReLU and each with its own MPP loss, weighted 5 and 20; the two layers' DFMs are added together. Adam, learning rate 10−410^{-4}, 3000 training iterations.

Discussion

Main results

MethodUCF-Crime AUCXD-Violence AP
RTFM84.3077.81
UR-DMU (paper)86.9781.66
UR-DMU (this paper's rerun)86.23—
BN-WVAD87.2484.93

Both datasets use RGB features only. On XD-Violence the gain is more than 3 points, beating even multimodal methods that need audio; with audio features concatenated, it reaches 85.26.

On UCF-Crime, it's only 0.27 above the number in the UR-DMU paper. The authors' take is that the gain may be small, but it's considerable when compared with the 86.23 they got by rerunning UR-DMU with its official code. This argument will come up again shortly.

Ablations

SettingUCF-Crime AUCXD-Violence AP
Only Lnor\mathcal{L}_{nor}, with Dropout65.2161.54
BatchNorm instead82.9772.99
+ DFM and MPP86.4483.33
+ batch-level selection87.2484.93

The second row is interesting. With the classifier trained only on normal videos and no anomaly supervision at all, simply replacing Dropout with BatchNorm takes UCF-Crime from 65 to 83, on par with several early weakly supervised methods. The authors' explanation is that anomalous videos sit in the same batch and take part in BatchNorm's statistics, so when gradients flow back through BatchNorm, they carry information about the anomalous features.

Batch-level selection adds 1.6 points on XD-Violence, more noticeably than on UCF-Crime, in line with XD-Violence's high anomaly ratio.

DFM also transfers to other methods. Replacing RTFM's norm criterion with DFM takes UCF-Crime from 84.11 to 85.58 and XD-Violence from 74.80 to 80.10. The other way round, switching BN-WVAD's DFM back to the norm costs 1.4 and 2.9 points on the two datasets.

The loss ablation shows DFM's share of the work more clearly. Trained with only Lnor\mathcal{L}_{nor} and MPP, DFM alone as the score gives 87.1 on UCF-Crime, the classifier by itself 86.8, and their product 87.2. On UCF-Crime, DFM does most of the work. Adding an anomaly loss that trains the classifier on the picked segments actually makes things worse, costing 6 points on XD-Violence, which bears out the design principle of "keep wrongly picked segments away from the classifier."

How to set the selection ratio

The authors swept both selection ratios. On UCF-Crime the best is 20% per batch, which they point out is close to the overall anomaly ratio of 18.2% in the UCF-Crime test set; the XD-Violence test set's anomaly ratio is 49.8%, and its best batch-level ratio is 40%.

The match is intuitive, but in real deployment nobody knows the anomaly ratio of their own test data, so this hyperparameter has to be estimated some other way. Using batch-level selection alone, without per-video selection, also hurts noticeably, because events that appear rarely in a batch, such as XD-Violence's abuse class, get crowded out entirely by the more common fighting.

Reproduction

The official code is public, adapted from UR-DMU's code, but it contains only the XD-Violence training code and one XD-Violence checkpoint.

UCF-Crime, one of the paper's headline numbers, isn't in the repository. When someone asked for it in December 2023, the authors replied that the UCF-Crime code was being reorganized and "will be updated soon," and asked everyone to "stay tuned." The repository's last commit dates from before that reply, November 30, 2023 (nearly three years tuned in, and nothing but static). Another issue asking the authors to release UCF-Crime weights got no reply at all.

So the community had to do it themselves. One person adapted a UCF-Crime version, got only 82% AUC at first, reached 84.8% at best after several reruns, and shared the packaged code in an issue. XD-Violence does have official code, and someone who trained it themselves reported 81.77, against the paper's 84.93.

Think back to the main results. Propping up a 0.27-point lead with your own reproduction numbers is fair enough, of course; it's just that when it's someone else's turn to reproduce this paper's 87.24, there isn't even code to rerun.

Conclusion

BN-WVAD's idea is economical. Most segments in a batch are normal, BatchNorm's mean is already recording "what normal looks like," and the farther a segment is from that mean, the more suspicious it is. This distance is used to pick pseudo-labels and as part of the anomaly score, and the classifier learns only from normal videos, steering clear of wrongly picked segments.

The most convincing ablations are that the criterion still works when moved over to RTFM, and that the classifier does better without anomaly labels. Batch-level selection lives or dies by the dataset's anomaly ratio, helping more the higher the ratio, and its best setting happens to sit right next to the test set's statistics.

If you want to compare against this paper on UCF-Crime, be ready to write your own UCF-Crime training code first.