\section{Introduction}
\section{Introduction}
Rising concerns for public security and safety have increased the number of surveillance cameras installed in our streets and public places~\cite{abati2019latent, liu2018ano_pred, Ionescu_2019_CVPR, Chandola:2009:ADS:1541880.1541882, morais2019learning}.
Human operators in a control room continuously inspect these video streams on a multi-screen video wall, looking for abnormal events that may mandate further inspection. As human operators can only process a few video streams at the same time, part of the surveillance workflow must be automated when the number of cameras grows. By automating the detection of anomalous events, human operators can focus on the appropriate response to these events, e.g.~by requesting a police intervention.

Since anomalies are context-specific~\cite{song2007conditional}, each video stream requires a tailored anomaly detection algorithm. A running person for example is considered an anomaly in a busy shopping street but it might be normal in a train station as people are often in a hurry to catch the train. In this work we introduce a new neural network architecture that is able to recognize anomalous events in a surveillance camera stream using only unsupervised training. We propose to decouple the learning of appearance and motion information which are the key factors for determining anomalies in a surveillance video. We first train an autoencoder by reconstructing individual frames to capture high level appearance features such as the location, shape and size of an object. Such features however can not guarantee the detection of  anomalies that are caused by motion related features such as speed or trajectory. We therefore add a second component that further exploits the spatiotemporal information of the frequently seen events by predicting the latent code for a future frame using the stacked latent codes of the previous $k$ frames as the input. The underlying assumption is that the anomalous events are rare occasions and will not be modeled accurately by the networks. The predicted latent code of anomalous frames will hence deviate significantly from the observed latent codes.

Our approach is easy to implement and achieves state-of-the-art performance on benchmark datasets. We however do not only focus on detection accuracy but also address several other obstacles for real-world deployment. Our model is much more efficient than related approaches, which could make it possible to evaluate our model at the network edge, on or nearby the surveillance camera itself, as opposed to streaming all data to a central point for analysis. Inference at the edge is also a more privacy friendly paradigm since a human operator will not see the camera data unless his intervention is needed. Lastly, our experimental results indicate that detection performance based on prediction of latent codes is more robust against changing weather and lighting conditions.

The remainder of this paper is organized as follows: In section~\ref{section:related} we give an overview of related anomaly detection methods. In section~\ref{sec:method} we introduce our approach and we experimentally validate it on different benchmark datasets in section~\ref{sec:experiments}. In section~\ref{sec:robustness_of_the_model} we show that our approach is more robust against different distortions. We conduct an ablation study in section~\ref{sec:ablation_study} to analyze the role of different components of the model. We conclude in section~\ref{sec:conclusion} and give a few pointers for future research directions.
\section{Related work}
\label{section:related}

Deep learning is currently the state-of-the-art method for many computer vision related tasks~\cite{SCHMIDHUBER201585} and is also the technique behind the state-of-the-art anomaly detection methods for video surveillance type data. We can differentiate three different approaches to do anomaly detection with deep learning: reconstruction based methods, prediction based methods and methods that use characteristics of the latent code to detect anomalies.

\subsection{Reconstruction based methods}
The most common approach is to build models that reconstruct their input. These models are based on an autoencoder architecture that contains a bottleneck for encoding high level features, creating a compressed representation of the input data. These compressed representations are then used to reconstruct the input data. The assumption here is that the reconstruction works fine for inputs that are similar to the data that was seen during training but that anomalous inputs can not be modelled accurately by the learned features, resulting in a poor reconstruction. The reconstruction error is then used as a metric to detect anomalies.

For our use case of anomaly detection in video surveillance, it is not enough to only model spatial information by processing individual frames, we also need to consider the temporal information to detect anomalies that are caused by motion, such as high speed or irregular movement. Different approaches have been explored to incorporate this information into the model.~\cite{Hasan2016LearningTR} exploit the spatiotemporal information by reconstructing multiple stacked frames using an autoencoder.~\cite{XU2017117} apply a denoising autoencoder~\cite{Vincent:2008:ECR:1390156.1390294} to reconstruct frames. They use optical flow maps to describe the motion information. Another option is to use Recurrent Neural Networks (RNN) or Long Short-Term Memory networks (LSTM)~\cite{SCHMIDHUBER201585} to model the time dimension~\cite{10.1007/978-3-319-59081-3_23, 8019325}. Finally, there is also work that explores the use of a 3D convolutional networks (C3D) to model spatiotemporal representations.~\cite{Tran:2015:LSF:2919332.2919929} show that C3D can encapsulate information related to shapes and motions in video sequence better than a 2D based model, thus boosting the anomaly detection accuracy.

\subsection{Prediction based methods}
Instead of reconstructing the input, it is also possible to predict future frames. This requires a better understanding of temporal information.~\cite{liu2018ano_pred} use a generative adversarial network (GAN)~\cite{NIPS2014_5423} that takes stacked frames and optical flow features as input. Anomalies are detected at test time by measuring the difference between the predicted and observed future frame. Any deviation from the expected frame is considered as an anomaly. For more specialized applications we can also use domain specific features.~\cite{morais2019learning} for example deal with human-related anomaly detection by reconstructing and predicting the decomposed global body movement and local body posture from the human skeleton movement.

\subsection{Latent code based methods}
Both lines of previous work generate expected frames and detect anomalies by measuring the difference in pixel space with the actual input frame. However, it is well known that pixel-wise similarity measurements do not necessarily correspond with human understanding of images~\cite{Larsen:2016:ABP:3045390.3045555, Mathieu2015DeepMV} and are often very sensitive to minor changes in brightness or color. On the other hand, the high level features extracted by a neural network are shown to be less sensitive to these distortions~\cite{Zhang2018TheUE}. There are some very recent approaches that extract high level features with an autoencoder and then use a classifier such as a one-class SVM on the extracted features~\cite{app9040757, Ionescu_2019_CVPR} to detect anomalies. The assumption is that the classifier will distribute the anomalies outside of the learned manifold. The work that is most similar to our approach is the Latent Space Autoregression model from~\cite{abati2019latent}. They use features from a deep 3D convolutional autoencoder combined with an autoregressive network to model the probability distribution underlying the latent representation. They combine the reconstruction error and the likelihood of the latent code to identify the anomalies. Our approach is similar in that we also extract features and work in a high level latent code. However, our approach uses a 2D autoencoder to extract features which highly reduces the number of parameters and computational cost. We use a less complicated feed forward model to do the prediction which does not make any assumptions on the distribution family of the latent code. It allows us to directly use the Mean Squared Error (MSE) between the predicted latent code and the latent code that is extracted from the encoder as the anomaly score. Finally, we explicitly predict the latent code of a future frame instead of relying on the reconstruction of the current frame to capture the motion information.

\begin{figure*}
\centering
\resizebox{.9\textwidth}{!}
{
\begin{minipage}{\textwidth}
\includegraphics[width = 1.0\textwidth]{Figures/end2end.pdf}
\end{minipage}
}
\caption{Overview of our approach. We use the same encoder to extract latent code for each input frame, where $k$ is the number of frames in per input sequence and $t$ is the frame that is 6 timesteps into future ($k+6$). In the training phase, these latent code are used to (a) predict latent codes for future frames with the motion model and (b) reconstruct current frames with the decoder. In the inference phase, we only use the encoder and the motion model. (c) \textit{Conv3D} layers are used in the motion model to learn spatiotemporal information. The figure is best viewed in color.}
\label{fig:main_architecture}
\end{figure*}
\section{Architecture}
\label{sec:method}

In this paper we propose a decoupled architecture to learn the spatiotemporal information which is important for determining anomalies in surveillance videos. We first train an autoencoder to reconstruct individual input frames and aim to represent the appearance information such as shape, location and outlook of an object in the latent codes. Then to further stress the appearance information for frequently seen events and the dynamical aspects in a video, we stack these extracted latent codes from the encoder for a sequence of $k$ frames and use that as the input for a second network to predict the latent code for a future frame. The model is assumed to be only able to predict the latent codes for frequently seen events with high accuracy. The difference between the predicted and the observed latent codes is then used as the anomaly metric. The following sections explain these in detail.

\subsection{Learning appearance features}
To learn high level features, we use a U-Net~\cite{RFB15a} type autoencoder that is trained to reconstruct individual input frames. To force the model to focus on the foreground, we subtract a background frame from each input frame. This background frame is calculated as a frame with per-pixel mean RGB values over all training data. The encoder learns to extract latent codes from a single frame and the decoder learns to reconstruct the input based on the extracted features. The original U-Net architecture has shortcut connections between encoder and decoder. To avoid the trivial solution of copying feature maps from the encoder to the decoder and to improve the regularization power, we add a shortcut connection between the previous frame $T_{k-1}$ and current frame $T_{k}$. In other words, the feature maps that are calculated using frame $T_{k-1}$ are concatenated with the feature maps from frame $T_{k}$ in the upsampling path for reconstructing frame $T_{k}$. The detailed architecture is shown in Figure \ref{fig:main_architecture} (a) and (b).

\subsection{Learning motion features}
Spatiotemporal information is important for detecting anomalies in videos. However, the features that are extracted by encoding a single frame as described above can only focus on the spatial information such as shape, location and size of an object and cannot guarantee the detection of the motion-related anomalies. We thus include a second component that can attend to both spatial and temporal dimension to further learn the dynamical aspects of video sequence. Previous work considered learning the temporal information either by predicting optical flows using a pretrained FlowNet~\cite{Hasan2016LearningTR,liu2018ano_pred} or by predicting future frames in pixel space~\cite{abati2019latent, liu2018ano_pred}. This however has three drawbacks. First, the optical flow estimation is computationaly expensive as it requires around $0.1$ seconds to evaluate a single frame on a GPU machine~\cite{IMKDB17}. Secondly, we need to consider the interaction between appearance and motion information. For example, a vehicle driving with very high speed is usually an anomaly except when it is an ambulance. Independently encoding the appearance and motion information using a pretrained optical flow model cannot take this into account. Finally, the pixel-wise Mean Square Error (MSE) objective function for predicting future often generates blurry frames~\cite{Mathieu2015DeepMV, Zhang2018TheUE}. Instead, we decide to predict the latent code of a future frame through a small motion learning model as shown in Fig.~\ref{fig:main_architecture} (c).

To predict the latent code of frame $T_t$, we extract latent codes for $k$ previous input frames $T_1$...$T_{k}$. The extracted latent codes $z_{1}...z_{k}$ from the encoder for each of past frames $T_1...T_{k}$ are then concatenated along the temporal dimension and used as the input for the motion model to predict the latent code $\hat{z}_t$ for a future frame $T_t$. We use 3D convolutional layers in the motion model since these can attend to both motion and appearance whereas a 2D convolution layer is only able to work in the spatial direction~\cite{Tran:2015:LSF:2919332.2919929}. Each convolutional block includes a 3D convolutional layer with kernel size 3x3x3, stride 2 on the temporal dimension and stride 1 on the feature dimension. This is followed by a BatchNormalization~\cite{Ioffe:2015:BNA:3045118.3045167} and a leaky-relu activation layer. We use three convolutional blocks in the motion model.

\subsection{Training}
Our proposed framework consists of two parts: video frame reconstruction and latent code prediction, so the objective function to train both components end-to-end can be formulated as:
\begin{equation}
\begin{split}
    \mathcal{L} =  \lambda_{r}\sum_{q=2}^{k}\sum_{j=1}^N||\hat{T}_{q,j}-T_{q,j}||_2^2 + \\ \lambda_{p}\sum_{m=1}^{M}||\hat{z}_{t,m}-z_{t,m}||_2^2 + \gamma||W||_2^2
\end{split}
\end{equation}

The first term measures the pixel-wise reconstruction loss where $N$ is the total number of pixels per frame and $k$ is the number of frames in a input sequence. We can only reconstruct the last $k-1$ frames if we input $k$ frames since the reconstruction of one frame requires the features from its previous frame. The second term is the MSE between the predicted and the observed latent code where $M$ is the number of elements in the latent code. The last term is an L2 regularization term where $\gamma$ is kept to be 0.001. The model can be trained end-to-end but to bootstrap the encoder with useful features, we first focus on training the autoencoder for reconstruction ($\lambda_{r}=1$ and $\lambda_{p}=0.001$) until the training loss for reconstruction converges. Then we focus on finetuning the weights of the motion model ($\lambda_{r}=0.001$, $\lambda_{p}=1.0$) to use the motion information better.

\subsection{Inference}
At inference time, we discard the decoder and use the difference between predicted and actual latent code as the metric to determine whether a frame is an anomaly or not. The underlying assumption is that the model can predict the latent code for the normal frames with high accuracy but is not able to do so for anomalous frames. To measure the distance between latent codes, we apply two different metrics: Mean Squared Error (MSE) Eq.~\ref{eq:mse} and cosine-distance Eq.~\ref{eq:cosine_dist}.
\begin{subequations}
\begin{equation}
    s_{t} = \frac{\sum_{m=1}^M ||\hat{z}_{t,m}-z_{t,m}||^2}{M}
\label{eq:mse}
\end{equation}
\begin{equation}
    s_{t} = 1 - \frac{\sum_{m=1}^M \hat{z}_{t,m}z_{t,m}}{\sqrt{\sum_{m=1}^M\hat{z}_{t,m}}\sqrt{\sum_{m=1}^Mz_{t,m}}}
\label{eq:cosine_dist}
\end{equation}
\end{subequations}

After calculating the anomaly score for each frame, following~\cite{Mathieu2015DeepMV}, we normalize the score for each frameset $\mathcal{G}$ to the range of [0,1] using Eq.~\ref{eq:normalize}. A frame that has the anomalous score higher than a threshold is considered as anomaly. Depending on the dataset, $\mathcal{G}$ contains all frames of a video or just the frames in a sliding window for long videos.

\begin{equation}
    s_t = \frac{s_t - min_{j\in\mathcal{G}}(s_j)}{max_{j\in\mathcal{G}}(s_j) - min_{j\in\mathcal{G}}(s_j)}
    \label{eq:normalize}
\end{equation}

\section{Experiments}
\label{sec:experiments}
In this section, we compare our methods to state-of-the-art approaches on public benchmarks. We do not only focus on detection accuracy but also compare the computational cost of the models since this is often the bottleneck that limits the performance in the real world. In addition, we also evaluate the proposed anomaly detector on multiple distorted environments and show that our method is more robust against changes in lighting and weather that are common in the real world.

\subsection{Experimental Setup}
To evaluate the effectiveness of our proposed methods, we use the same datasets as~\cite{liu2018ano_pred}, including the UCSD Pedestrian dataset~\cite{Mahadevan.anomaly.2010}, the CUHK Avenue dataset~\cite{Lu2013AbnormalED} and the ShanghaiTech dataset~\cite{liu2018ano_pred}. The details of these datasets are described by~\cite{liu2018ano_pred}. As is common, we report the Area Under Curve (AUC) score as the accuracy metric.

The experimental settings are shown in Table \ref{tab:implementation_detail}. We use 8 input frames for UCSDPed1 and UCSDPed2 datasets and 6 input frames for the Avenue and ShanghaiTech datasets. More frames are needed to encode the motion and appearance of the much smaller objects in the UCSD Pedestrian datasets than in the Avenue and ShanghaiTech datasets. The resolution of the frames is reduced using bilinear interpolation, keeping the original aspect ratio. As for the architecture, we use five encoder blocks for the UCSDPed1 dataset and four encoder blocks for the other datasets. This is done because the scenes in the UCSDPed1 dataset include more objects and we need to increase the model's capacity in order to encode the appearance- and motion-related features.
\begin{table}[ht!]
\caption{Design choices for each evaluation dataset. }
\resizebox{0.76\textwidth}{!}
{\begin{minipage}{\textwidth}
\begin{tabular}{ccccc}
\toprule
 & UCSDPed1 & UCSDPed2 & Avenue & ShanghaiTech \\ \toprule
Input Size & 128x192 & 128x192 & 128x224 & 128x224 \\
Num Input ($k$) & 8 & 8 & 6 & 6 \\
Encoder Block & 5 & 4 & 4 & 4 \\ \bottomrule
\end{tabular}
\end{minipage}}
\label{tab:implementation_detail}
\end{table}

We train the model for 50 epochs in an end-to-end fashion with initial learning rate $1e-4$ which decays by 0.1 every 20 epochs.
The ShanghaiTech dataset contains data from multiple cameras. We trained individual models per camera and observed no significant performance difference with a model that is trained on data from all cameras. We train the model with the Adam optimizer~\cite{DBLP:journals/corr/KingmaB14} for all our experiments. The code will be released on \textbf{website}.

For the evaluation, we use feature-wise MSE (Eq.~\ref{eq:mse}) to calculate the anomaly score for Avenue dataset and feature-wise cosine-distance (Eq.~\ref{eq:cosine_dist}) for all other datasets.
We normalize the anomaly score in UCSDPed1 and UCSDPed2 dataset with Eq.~\ref{eq:normalize} using all the frames in a test video. For the ShanghaiTech datasets, we use the same sliding-window approach as~\cite{abati2019latent}.

\subsection{Results}
\label{sec:exp_result_auc_fps}
Table \ref{tab:experiment_result_auc} compares our results with those of other unsupervised deep learning based methods for anomaly detection. Our approach outperforms the existing methods in terms of frame-level AUC score on all four datasets. The decoupled mechanism and the combined learning of appearance and motion information improves the training process and allows the extracted and predicted latent codes to be more representative for the frequently seen events and thus improve the anomaly detection accuracy. We further investigate the role of decoupling, the use of Conv3D layers in the motion model as well as different anomaly metrics in section~\ref{sec:ablation_study}.
\begin{table}[ht!]
\caption{Frame-level AUC score with 95\% confidence interval (4 runs) on UCSDPed1, UCSDPed2, Avenue and ShanghaiTech datasets. We outperform most of the existing approaches on all the datasets.} \smallskip
\resizebox{0.89\textwidth}{!}
{\begin{minipage}{\textwidth}
\begin{tabular}{@{}lcccc@{}}
\toprule
 & \begin{tabular}[c]{@{}l@{}}UCSD\\ Ped1\end{tabular} & \begin{tabular}[c]{@{}l@{}}UCSD\\ Ped2\end{tabular} & Avenue & \begin{tabular}[c]{@{}l@{}}Shanghai\\ -Tech\end{tabular}\\ \midrule
\begin{tabular}[c]{@{}l@{}}MDT \cite{5539872}\end{tabular} & 81.8 & 82.9 & - & -  \\ \noalign{\smallskip}
\begin{tabular}[c]{@{}l@{}}ConvAE \cite{Hasan2016LearningTR}\end{tabular} & 81.0 & 90.0 & 70.2 & - \\ \noalign{\smallskip}
\begin{tabular}[c]{@{}l@{}}ConvLSTM \cite{8019325}\end{tabular} & 75.5 & 88.1 & 77.0 & -  \\ \noalign{\smallskip}

\begin{tabular}[c]{@{}l@{}}Unmasking \cite{Ionescu2017UnmaskingTA}\end{tabular} & 68.4 & 82.2 & 80.6 & -\\ \noalign{\smallskip}

\begin{tabular}[c]{@{}l@{}}Hinami \cite{hinami2017joint}\end{tabular} & - & 92.2 & - & - \\ \noalign{\smallskip}

\begin{tabular}[c]{@{}l@{}}StackRNN \cite{8237307}\end{tabular} & - & 92.2 & 81.7 & -  \\ \noalign{\smallskip}

\begin{tabular}[c]{@{}l@{}}FFP-MC \cite{liu2018ano_pred}\end{tabular} & 83.1 & \textbf{95.4} & 84.9 & 72.8 \\ \noalign{\smallskip}

\begin{tabular}[c]{@{}l@{}}LatentAuto
\cite{abati2019latent}\end{tabular} & - & \textbf{95.4} & - & 72.5  \\ \hline \hline
ours & \textbf{84.7$\pm$0.3} & \textbf{95.1$\pm$0.3} & \textbf{88.8$\pm$0.3} & \textbf{74.2$\pm$0.1}\\ \bottomrule
\end{tabular}
\end{minipage}}
\label{tab:experiment_result_auc}
\end{table}

The initial goal of our approach was to develop an architecture that is more efficient than previous approaches.
We benchmark our method with the approaches that have publicly available code on an Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz with an GeForce GTX 1080 Ti. We reimplemented the methods described by~\cite{Hasan2016LearningTR} in Tensorflow to allow for a fair comparison\footnote{The benchmark code is also available at \textbf{website}}. The results are displayed in Table~\ref{tab:experiment_result_fps}.
Our method outperforms the other approaches by a large margin in terms of the number of frames that can be processed per second. Compared to the \textit{Latent-Auto} approach~\cite{abati2019latent} that also detects anomalies using latent code, we can process 16$\sim$45 times more frames per second. The main reason our method is more efficient is because the model independently encodes appearance and motion information. We extract the appearance information using a  relatively efficient 2D convolutional network and process the combined features using a small 3D convolutional network, whereas other approaches build the entire network around 3D convolutions making it much more expensive. Because we extract latent codes from individual frames, each frame only needs to be processed once. We can save each of the last $k$ latent codes that are needed in the motion model and re-use them for the next $k$ predictions.
In contrast, models that use 3D convolutions process each frame $k$ times, each time at a different position in the stack, predicting a different frame, making it much more computationally expensive. Since we predict future latent codes and use the prediction error in latent space as our anomaly metric, we do not need the decoder part at inference, again reducing the computational cost. Also, compared to other models that use anomaly scoring metrics based on latent codes, we do not impose any distribution constraint on the latent code, giving the model the freedom to fit the data as best as possible.
\begin{table}[ht!]
\caption{FPS for different methods. Our method is more efficient than the existing approaches}
\resizebox{0.8\textwidth}{!}
{\begin{minipage}{\textwidth}
\begin{tabular}{@{}lllll@{}}
\toprule
 & \begin{tabular}[c]{@{}l@{}}ConvAE  \cite{Hasan2016LearningTR}\end{tabular} & \begin{tabular}[c]{@{}l@{}}FFP+MC \cite{liu2018ano_pred}\end{tabular} &
 \begin{tabular}[c]{@{}l@{}}LatentAuto \cite{abati2019latent}\end{tabular}
 & Ours \\ \midrule
UCSDPed1 & 75 & 63 & 2 & \textbf{81} \\
UCSDPed2 & 75 & 63 & 2 & \textbf{90} \\
Avenue & 71 & 48 & 5 & \textbf{77} \\
ShanghaiTech & 71 & 48 & 5 &\textbf{77} \\
\bottomrule
\end{tabular}
\end{minipage}}
\label{tab:experiment_result_fps}
\end{table}

A disadvantage of working with latent codes is that it is harder to interpret the model. It is however possible to also use the decoder at inference time to generate predicted frames and to measure the pixel wise reconstruction metrics. This allows us to localize the part of the frame that contains the anomaly. We show these results in Figure \ref{fig:qualitative_result}. The red boxes in each frame are the regions that have the prediction error larger than a threshold.  The green boxes show the ground-truth annotations for the Avenue and ShanghaiTech dataset (the UCSD pedestrian dataset only has frame-level labels). These results empirically confirm that our model can detect motion- and appearance-related anomalies, such as the \textit{skater, cyclist, car, running and gymnastics} events (first four columns). The last two columns of Figure \ref{fig:qualitative_result} show false positives, frames that were labeled as normal but that were flagged as anomalies by our model. Two of these show noise or camera movements that were not seen during training. It also shows that the model is more likely to incorrectly flag objects as anomalies if they are closer to the camera.

\begin{figure*}[ht!]
\centering
\resizebox{1.0\textwidth}{!}
{
\begin{minipage}{\textwidth}
\includegraphics[width = 1.0\textwidth]{Figures/qualitative_result.pdf}
\end{minipage}
}
\smallskip
\caption{True positive (first four columns) and false positive (last two columns) detections of our framework. Examples are selected from the UCSD pedestrian dataset (first row), Avenue dataset (second row) and ShanghaiTech dataset (last row). \# indicates the testing video index. The red boxes are the regions that have highest pixel-wise prediction error and the green box are the ground truth bounding boxes for the anomalous event. We can successfully detect the motion- and appearance- related anomalies and tend to incorrectly flag objects as anomalies if they are closer to camera. The figure is best viewed in color.}
\label{fig:qualitative_result}
\end{figure*}

\section{Robustness of the model}
\label{sec:robustness_of_the_model}
The datasets we used in the previous section are commonly used datasets that allow us to compare anomaly detection techniques quantitatively. They however all contain relatively clean data, recorded at similar times during the day and under clear weather conditions. These datasets are therefore not necessarily representative of real world surveillance footage where external factors such as weather and time of day will severely influence the performance of the model. We argue that in addition to their anomaly detection performance and computational cost, we should also compare the robustness and generalization of the models to these external factors. In this section we investigate two types of robustness and show that by working with latent code anomaly metrics we are more robust than other approaches that use pixel-wise metrics.

\subsection{Modelling long term temporal information}
In section~\ref{sec:exp_result_auc_fps}, we showed that our approach is by design much more efficient than existing techniques. To reduce the computational cost even further we could reduce the number of times we activate the model. In surveillance video, anomalies are typically in view of the camera during multiple seconds. It should be enough to process only a few frames of this window to detect the anomaly. If instead of running our model every 40 ms, we run it every 200 ms, then this obviously results in a lower total computational cost but this also makes the task much harder for the network since we now need to predict five times further into the future. In this way, the model is forced to encode longer term temporal information and the prediction task is more challenging since the future frame will differ substantially from the previous frames.

To explore this trade-off, we subsample the video sequence and only keep every $d_{th}$ frame in our training and test data. Figure~\ref{fig:low_fps_input} shows how sensitive the latent code metric (red line) is compared to the pixel-wise metric (green line). Both techniques follow the same trend but the latent code metric consistently performs better than the pixel-wise metric, especially when the gap between input frames becomes large. This illustrates the power of latent codes and their capability of modelling longer term temporal information.

\begin{figure}[ht!]
    \centering
    \includegraphics[width = .45\textwidth]{Figures/fps_plot_ucsd2_trainend2end.pdf}
    \caption{The anomaly detection accuracy (frame-level AUC score with 95\% confidence interval) when we have low fps input. \textbf{z-mse} is calculated using Eq.~\ref{eq:mse} on the latent code and \textbf{p-mse} is the MSE between the predicted frames and actual frames. The figure is best viewed in color.}
    \label{fig:low_fps_input}
\end{figure}
\subsection{Generalization to other lightning conditions}
The performance of anomaly detection in surveillance video is impacted severely by factors such as varying illumination, multiple weather conditions, on- and off-peak traffic profiles, degradation of the camera and so on. Therefore, in this section, we investigate the robustness of our proposed method to these distortions. We train a model using original frames from the Avenue dataset and then analyze the performance on distorted test set frames. We adjust brightness, blur the image and add rain to the test frames using the Automold toolkit\footnote{\url{https://github.com/UjjwalSaxena/Automold--Road-Augmentation-Library}}. Figure \ref{fig:avenue_augmented_frame} shows some examples of the distorted frames using different levels of rain and brightness.

\begin{figure}[t]
    \centering
    \includegraphics[width=.47\textwidth]{Figures/avenue_rain_frame.pdf}
    \caption{The distorted frames using Avenue dataset. (a) original frame,  (b) and (c) have heavy rain with brightness degree 0.5 and 0.7 respectively and (d),(e) and (f) show torrential rain with the brightness 0.6, 0.8 and 1.0 respectively. The figure is best viewed in color.}
    \label{fig:avenue_augmented_frame}
\end{figure}

Figure \ref{fig:avenue_exp_on_augmented_frame} shows the frame-level anomaly detection accuracy for different distortion levels. The X-axis shows the relative brightness compared to the original frame. The different curves show the performance of using Mean Squared Error (MSE) in pixel space (p) and in latent space (z) as our anomaly metrics for different levels of rain added to the image. As expected the model performance drops when the brightness decreases, but our model is consistently more robust than the baseline model that uses pixel wise metrics. Adding rain to the test frames also reduces the detection performance  but again, our feature-wise latent code MSE performs significantly better as anomaly scoring metric than the pixel-wise MSE. These results verify that our proposed methods using feature-wise MSE in the latent code to identify anomalies is more robust to different outdoor situations than pixel-wise MSE measurements.
\begin{figure}[ht!]
    \centering
    \includegraphics[width=.42\textwidth]{Figures/avenue_rain_exp_comp_one_figure.pdf}
    \caption{The averaged anomaly detection accuracy (frame-level AUC score) on the augmented frames where \textbf{z} means the latent code feature-wise MSE and \textbf{p} means the prediction pixel-wise MSE. The latent code anomalous score measurement is more robust on unseen weather conditions compared to other approaches. The figure is best viewed in color.}
    \label{fig:avenue_exp_on_augmented_frame}
\end{figure}

\section{Ablation study}
\label{sec:ablation_study}
In section \ref{sec:method} we introduced our model together with some design choices. In this section we look closer to three of these and investigate how these contribute to our results.

\subsection{Reconstruction vs prediction}
To understand the impact of the anomaly detection metrics on the detection accuracy, we report the frame level AUC score using pixel-wise reconstruction error, pixel-wise prediction error and feature-wise latent code error in Table~\ref{tab:ucsd_avenue_shanghai_quan_motion}. Adding the motion model highly improves the anomaly detection accuracy for all the datasets since it encodes spatiotemporal information better. Compared to the performance using pixel-wise prediction error, the use of latent code prediction error tends to be better and more stable since it is more robust to the noise in the image as indicated by section~\ref{sec:robustness_of_the_model}. To qualitatively understand how the model differentiates between normal and abnormal frames, we conduct an experiment on the moving-mnist dataset.

We train the same model as shown in Fig.~\ref{fig:main_architecture} using the video sequences that are created by letting randomly selected digits 4 and 7 from the training set of MNIST~\cite{726791} move horizontally or vertically with a speed of 2 following~\cite{8237307} (see Fig.~\ref{fig:ucsd_avenue_to_explain_latent_space} (a)). This model is then tested on video sequences that include all types of digits from the test set of MNIST dataset and two new shapes (circle and square) that are moving also horizontally or vertically with a speed of 2 or speed of 4. The input, reconstruction, prediction and prediction error are shown in Fig.~\ref{fig:ucsd_avenue_to_explain_latent_space} (b) and (c).

Fig.~\ref{fig:ucsd_avenue_to_explain_latent_space} (b) shows the model output for input objects that move with a speed of 2. The model can make good reconstructions and predictions for already seen digits 4 and 7 but tend to predict the unseen digits to be one of the already seen digits. For example, it predicts the circle and square to be similar to 4 and digit 8 to be similar to 7. The difference between the reconstruction and prediction indicates that the model cannot make a good prediction of the latent code for the unseen digits and this allows us to detect the appearance related anomalies. For the objects that are moving with a higher speed as shown in Fig.~\ref{fig:ucsd_avenue_to_explain_latent_space} (c), the model produces a prediction that falls behind the actual input. This is because the designed motion model can further exploit the speed mismatch of the objects during training and testing and is thus able to detect the motion related anomalies.

\begin{figure}[ht!]
    \centering
    \includegraphics[width=.47\textwidth]{Figures/moving_mnist.pdf}
    \caption{Experimental results on moving-mnist dataset. (a) training digits 4 and 7 are moving horizontally or vertically randomly with speed 2. (b) and (c) show the testing digits and shapes that are moving in a similar fashion but with speed 2 (b) and speed 4 (c). From left to right, the columns in (b) and (c) are input, reconstruction, prediction and prediction error. The model cannot accurately reconstruct and predict for both appearance-related (unseen digits) and motion-related (unseen moving speed) anomalies.}
    \label{fig:ucsd_avenue_to_explain_latent_space}
\end{figure}

\begin{table*}[ht!]
\caption{Abnormal event detection results (in \%) with 95\% confidence interval. The \textit{Reconstruction error} and \textit{Prediction error} are pixel-wise MSE and the \textit{Latent code error} is calculated feature-wise. We achieved better performance using latent-code prediction error as anomalous score and using Conv3D layers in the motion model.}
\label{tab:ucsd_avenue_shanghai_quan_motion}
\centering
\resizebox{0.95\textwidth}{!}
{\begin{minipage}{\textwidth}
\begin{tabular}{@{}lcccccccc@{}}
\toprule
                     & \multicolumn{4}{c}{Conv3D}          & \multicolumn{4}{c}{ConvLSTM}        \\  \midrule
                     & Ped1 & Ped2 & Avenue & ShanghaiTech & Ped1 & Ped2 & Avenue & ShanghaiTech \\ \cmidrule(l{1.5mm}r{3mm}){2-5} \cmidrule(l{1.5mm}r{3mm}){6-9}
Reconstruction error & 80.6$\pm$0.2 & 91.3$\pm$0.5 & 83.7$\pm$0.3 &  55.8$\pm$0.2 & 74.8$\pm$0.4 & 87.5$\pm$0.1 &83.1$\pm$0.2 &  52.6$\pm$0.4\\
Prediction error     & 82.2$\pm$0.4 & 90.9$\pm$0.5 & \textbf{89.2$\pm$0.2} &  72.7$\pm$0.2 & 81.2$\pm$0.4& 90.3$\pm$0.8 & \textbf{89.0$\pm$0.3}&     70.2$\pm$0.2          \\
Latent code error    & \textbf{84.7$\pm$0.3} &\textbf{95.1$\pm$0.3}& \textbf{88.8$\pm$0.3} & \textbf{74.2$\pm$0.1} & 82.8$\pm$0.6 & 94.1$\pm$0.1 &   \textbf{88.9$\pm$0.3}     &    71.3$\pm$0.4\\ \bottomrule
\end{tabular}
\end{minipage}}
\end{table*}

\subsection{Design of the motion model}
\label{sec:design_motion_model}
The motion model is an important factor in the design of our architecture since it is required to encode the typical appearance and motion information of the frequently seen events. Therefore, we also replaced the Conv3D layers in the motion model with ConvLSTM to study the impact of the design of the motion model on anomaly detection performance. The anomaly detection accuracy using pixel-wise reconstruction, prediction error and feature-wise latent code error for different datasets are shown in Table~\ref{tab:ucsd_avenue_shanghai_quan_motion}. We achieved better or similar performance on all the datasets using Conv3D layers in the motion model. One of the possible reasons is that the Conv3D layers can fit the data better and thus extract more representative features. In addition, we observed that the model that uses ConvLSTM layers have delayed detection results such that it fails to detect the beginning of anomalous events and it also reports more false alarms after the anomalous events due to the slowly response.

\section{Conclusion and future work}
\label{sec:conclusion}
In this paper we introduced a novel architecture that is able to detect anomalies in real world surveillance footage using only unsupervised training. The model consists of two parts where the first part extracts appearance features from individual frames and the second part uses these features to predict the latent code for a future frame. In contrast to previous works,  our model uses a prediction in latent space as a metric to detect anomalies. We showed that is able to outperform other techniques that use reconstruction or pixel based prediction metrics. Because of the decoupled appearance and motion feature learning, our model is also much more efficient than related approaches. Where other techniques use expensive 3D convolutions to analyze a stack of frames, we process each frame individually and then combine the information with a much smaller 3D convolutional model. This allows us to process 16 to 45 times more frames using the same computational budget. Finally, we show that using latent space features makes the model more robust against distortions such as changing lighting or weather conditions.

Anomaly detection in real world surveillance data is a very challenging topic with many useful applications. For future work, we argue that more research is needed to deal with changing environments, weather and lighting conditions as well as with camera degradation.
\section*{Acknowledgments}
This research received funding from the Flemish Government under the “Onderzoeksprogramma Artificiële Intelligentie (AI) Vlaanderen” programme, and from imec under the CityFlows AAA programme.

{\small
\bibliographystyle{ieee_fullname}


\section{Introduction} \label{introduction}

In the United States (US), substance use disorder (SUD) is one of the main causes of premature death \cite{johnston2003monitoring, schulte2013substance}. Social media is often used by people with SUD to seek support \cite{maclean2015forum77}. Online substance use recovery forums such as the Reddit forum, \textit{/r/Leaves} - which focuses on discussions around quitting marijuana,
 provide a ``safe space" where members - some of whom may be struggling with substance use, can freely
communicate and seek help from other members.

Prior work showed that 10\% of support-seeking messages on a forum focused on discussions around cancer received no comments \cite{wang2015eliciting,yang2019seekers}.
We find that support-seeking posts (across a 3 months time period) from  \textit{/r/Leaves} follow a similar trend with 11\% of posts receiving no comments, thereby leaving some users seeking support without adequate support.

The following social supports: emotional and informational are crucial in online forums focused on discussions around health and well-being \cite{wang2012stay,yang2017commitment}, where similar to prior work \cite{wang2012stay}, emotional support sought in posts seek affirmation, encouragement, and compassion, while informational support sought in posts seek information or advice.

Reddit posts are made up of two sections: the \textit{title} - which briefly describes the post, and the \textit{selftext} - which describes the post in more detail.
\newcite{glenski2017predicting} demonstrated that on Reddit, user interactions such as voting and commenting on posts is guided by the title of the post (post-titles); thereby implying that readers utilize linguistic cues in the post-titles on Reddit to decide whether to respond to posts.
Hence, in this work, we focus on analyzing the post-titles in two Reddit substance use recovery forums \textit{/r/Leaves} and \textit{/r/OpiatesRecovery}. We measure the extent to which these  post-titles seek emotional support and informational support and analyze their relationship with the number of comments they receive.
We hypothesize that since the interests of users who
belong to different forums focused on similar discussions differs \newcite{tran2016characterizing}, the type of social support (expressed in post-titles) that elicits comments may differ from one online substance use recovery forum to the other.

Understanding the relationship between the social supports (emotional and informational) sought in post-titles published in substance use recovery forums and the number of comments these posts receive is important partly because users join online health forums when going through a health care event such as cancer \cite{wen2012understanding,yang2019seekers} or recovering from substance use \cite{maclean2015forum77}; therefore, posts not receiving comments in these forums means that some users are not getting the necessary support they need.

\section{Related Work}
Some prior work focused on non-health related forums while others focused on health related forums.

In non-health related forums, \newcite{althoff2014ask}
studied a Reddit forum to determine the social and linguistic factors associated with posts in the forum that elicit responses.
\newcite{tran2016characterizing} explored several Reddit forums and determined that different forums use different language styles and there was a correlation between a forums language style and the responses to comments.
\newcite{jaech2015talking} examined the effect of language use in online forums on the reaction of members of the forums to comments.
\newcite{hessel2017cats} studied if incorporating multimodal features attracted user attention \cite{horne2017identifying}.

In health related forums, \newcite{wang2012stay} examined the effect of different social supports users are exposed to in an online cancer forum and its effect on the duration of user membership in the forum.
\newcite{wang2015eliciting} demonstrated that in an online
cancer forum, members tend to respond with emotional support when users self-disclose negative information about themselves.
\newcite{yang2019channel} studied communication in an online cancer forum and determined that members of the forum tend to disclose more negative information about themselves in public domains provided by the forums compared to the forums private domains.
\newcite{yang2017commitment} examined the relationship between the kind of communication received by members of an online cancer forum and their commitment to the forum.
\newcite{yang2019seekers} determined that over time, members of an online cancer forum change roles and that certain roles are predictors of prolonged commitment to the group.
\newcite{chancellor2018norms} examined online weight loss forums and determined how support influences user behavior changes. \newcite{maclean2015forum77} analyzed different phases of opioid addiction in an online forum focused on discussions around opioid use recovery.

Our work is different from prior work in that we analyze posts published in  online substance use recovery forums with the aim to determine if and how emotional and informational support sought in published posts in substance use recovery forums elicit comments from members of the forums. This study received exempt status from the University of Pennsylvania Institutional Review Board.

\section{Dataset} \label{dataset}

Our dataset consists of posts and meta-data from two active Reddit substance use recovery forums, \textit{/r/Leaves} and \textit{/r/OpiatesRecovery}, which have 147,000 members and 27,000 members, respectively, as of September 2020. \textit{/r/Leaves} is self-described as \textit{``a support and recovery community for practical discussions about how to quit pot, weed, cannabis, edibles, BHO, shatter, or whatever THC-related product you're using, and support in staying stopped"}. \textit{/r/OpiatesRecovery} is self described as \textit{``We are a group of people dedicated to helping each other kick the habit”}.
We chose \textit{/r/Leaves} and \textit{/r/OpiatesRecovery} because
these forums are the Reddit substance use recovery forums focused on marijuana and opioid use, respectively, with the most number of users.

Typically in these forums, a member writes a post (\textit{title} and \textit{selftext}) and other members respond to the post by either voting the post \textit{up} or \textit{down} or writing a comment. In this paper, we focus only on the comment responses to posts. Using Google’s BigQuery\footnote{\url{https://cloud.google.com/bigquery/}}, which is a data warehouse containing data from Reddit,
we collected and processed all posts published in \textit{/r/Leaves} and \textit{/r/OpiatesRecovery} between December 2015 and August 2019 and collected the following data related to each post: the post-title, the user who published the post, the time the post was created, the comments the post received, and the number of comments the post received.
Table \ref{tab:dev}
highlights the summary of our dataset.

\begin{table}[h]
		\setlength{\abovecaptionskip}{5pt}
		\setlength{\belowcaptionskip}{-12pt}
		\small
		\centering
		\begin{tabular}{|l|l|l|}
			\hline
			\centering
			\textbf{Attribute} & \textbf{\textit{/r/Leaves}}&\textbf{\textit{/r/OpiatesRecovery}}\\
			\hline

			Number of unique users  & 18,100&4,374 \\
			Number of posts  &35,961 &9,900\\
			Number of comments  & 227,850&129,801\\

			\hline

		\end{tabular}

		\caption{Summary of the \textit{/r/Leaves} and \textit{/r/OpiatesRecovery} datasets}

		\label{tab:dev}
	\end{table}

\section{Social Support}
Several studies have shown the importance of the expression of emotional and informational social supports in forums focused on discussions around health \cite{wang2012stay,yang2017commitment,yang2019seekers}.
Using a similar method from previous work by \newcite{wang2012stay}, we built two  models to determine
how much emotional and informational support, respectively, is sought in post-titles in our dataset.
We had 3 annotators - who were health care professionals with graduate degrees and familiar with substance use recovery, to rate a sample of 1,000 post-titles from our dataset, on (i) how much informational support each post-title sought and (ii) how much emotional support each post-title sought; where informational support post-titles provide/seek advice or information and emotional support post-titles seek encouragement, understanding, or affirmation \cite{wang2012stay}. Similar to prior work, \cite{wang2012stay}, the annotators rated these post-titles using a 7-point Likert scale (1 meant ``social support was not expressed in a post-title" and 7 meant ``social support was expressed a lot in a post-title"). To measure the reliability of the annotators, we used intra-class correlation (ICC) \cite{bartko1966intraclass}, which measures annotator reliability when each post-title is rated by different groups of annotators;
the ICC for informational support sought and emotional support sought were 0.95 and 0.93, respectively. For each post-title, the annotator ratings were averaged, hence each post-title had a score that ranged between 1 and 7 which indicated how much informational and emotional support was sought.

\subsection{Features}

We extracted several language features from the annotated post-titles.

Using Linguistic Inquiry and Word Count (LIWC) \cite{pennebaker2015development} - a dictionary comprising different psycho-linguistic categories, we selected the following LIWC categories relevant to informational and emotional support \cite{wang2012stay}: "positive emotion", "negative emotion", "she/he", "you", "we",  "i",impersonal pronoun", auxiliary" "verb", "past", "present", "future","religion", "death" "they", "cognitive mechanism", "biological processes", "time".

Similar to \newcite{wang2012stay}, from each post-title, we extract the number of sentences, the number of words in each sentence, the number of sentences that contain negation words/phrases such as "not", and the number of sentences phrased as questions.

We also extracted the number of specific parts-of-speech and the number of strong subjectivity words such as "affirmation" and weak subjectivity words such as "abandoned" \cite{wilson2005recognizing, wang2012stay}.

Post-titles seeking advice or involving requests were identified and counted \cite{wang2012stay} by (i) selecting sentences that began with the word "you" and followed by a Modal verb such as "may" and (ii) selecting sentences that began with the word "please" and followed by a verb.

We collected names of medicines from the Food and Drug Administration website website \footnote{\url{https://www.fda.gov/Drugs/}}; also a comprehensive list of nicknames for drugs was compiled \cite{wang2012stay}; we counted the number of drug names in each post-title.

 We trained a model of 20 Latent Dirichlet Allocation (LDA) \cite{blei2003latent} topics

 from 45,000 randomly selected post-titles from our dataset. Two physicians, who are familiar with substance use recovery, manually assigned a label to each of the topics, as shown in Table \ref{tab:features_topics}.

\begin{table*}[!t]
\small
	\caption{Summary of LDA topic themes and top 5  highly correlated words associated with each topic}
		\centering
		\begin{tabular}{|l|l|}
			\hline
			\centering

			\textbf{LDA topic themes}& \textbf{Highly correlated words}\\

            \hline

           Time sober& months, weeks, sober, clean, year\\
            Wanting reasons to stop & stop, can't, high, anymore, friends\\
            Feelings: anxious and depressed&feeling, depressed, tired, high, anxious\\
          Time sober before relapse& days, sober, clean, hours, free\\
           Withdrawal symptoms and addiction& withdrawal, drug, test,addiction,job, \\

          Cravings and relapse  & night, strong, cravings, weekend, relapsed\\
          Advice for quitting  &quitting, advice, tips,support, benefits\\
          Ready to quit  & time, quit, finally, hard, stop\\
          Making the decision to quit  & made, make, life, things, friends \\
           Feelings of quitting &anxiety, quitting, depression, deal,pains\\
          mood and feelings  & good, today, bad, high,start\\
            Years of using&years, daily, heavy, user, habit\\
           Reason for quitting& quitting, brain, back, motivation, fog\\
        Impact of addiction    &life, addiction, love, hate, relationship \\
       Quitting     &quit, ago, months,stop, haven't\\
         Side effects  &dreams, sleep, night, nightmares, insomnia\\
          Struggling with relapse  &day, end, relapse, struggling, thoughts\\
         Time to start sobriety   & day, today, start,journey, sobriety\\
          Thinking of quitting  &cold, turkey, thinking, cut, habit\\
            Sharing stories  & story, thought, wanted, share, addiction\\
			\hline

		\end{tabular}

		\label{tab:features_topics}
	\end{table*}

\begin{table}[h]
		\setlength{\abovecaptionskip}{5pt}
		\setlength{\belowcaptionskip}{-12pt}
		\small
		\centering
		\begin{tabular}{|l|l|}
			\hline
			\centering
			\textbf{Emotional Support} & \textbf{Informational Support}\\
			\hline

			Thinking of quitting- (0.76) & Share stories -  (0.69)\\
			Word length - (0.033) & Thinking of quitting-(0.046) \\
			Sharing stories - (0.032)  &  Word length - (0.044)\\%0.27***\\
			Noun - (0.021) & Noun (0.035) \\
			Strong subjectivity - (0.016) & Strong subjectivity -  (0.028) \\

			\hline

		\end{tabular}

		\caption{Top 5 most important features as ranked by the Random forest model}

		\label{tab:feature_ablation}
	\end{table}

\subsection{Social Support Prediction Model}

We built two Random Forest models that each output a numerical value that indicates how much emotional support and informational support is expressed in a post-title based on the annotations. We experimented with SVM, logistic regression, and Random Forest; Random Forest performed better.
We randomly partitioned the annotated posts into a training set (80\%), a validation set (10\%), and a test set (10\%).
We used the validation set to evaluate the performance of the models;
when the performance on the validation set was satisfactory, the models were then evaluated on the test set. Similar to \newcite{wang2012stay}, Pearson's correlation was used to measure the correlation of the models with the annotated data.

These models correlated with the average annotator ratings with
Pearson's correlation r = 0.46 and r = 0.51 for seeking emotional support and informational support, respectively. We then applied these models to the posts in our dataset. Table \ref{tab:feature_ablation} shows the 5 most important features, as ranked by the Random forest model.

\section{Does social support expressed in post-titles elicit comments?}

A challenge in substance use recovery forums is that several support-seeking posts do not receive any comments, thereby leaving some posters potentially without adequate support. In this section, we aim to determine if emotional and informational support expressed in post-titles elicit comments in \textit{/r/Leaves} and \textit{/r/OpiatesRecovery}. For our analysis, we select posts by users with 5 or more published posts in our dataset i.e. 12,960 posts published by 1,285 users from \textit{/r/Leaves} and
4,055 posts published by 335 users from \textit{/r/OpiatesRecovery}. For each user, we calculate the average number of comments they received for all their posts. We also calculated the average extent of emotional and informational support scores for posts published by each user.
We correlate the mean extent of emotional and informational support, respectively with the mean number of comments received per user.

\begin{table}[h]
		\setlength{\abovecaptionskip}{5pt}
		\setlength{\belowcaptionskip}{-12pt}
		\small
		\centering
		\begin{tabular}{|l|l|}
			\hline
			\centering
			\textbf{Feature} & \textbf{Pearson $r$}\\
			\hline

			Emotional Support Sought &  0.17\\
			Informational Support Sought & 0.22\\

			\hline

		\end{tabular}

		\caption{Correlation between social support sought and number of comments: \textit{/r/Leaves}. $p<0.001$. Number of users = 1,285}

		\label{tab:emo_info_corr}
	\end{table}

\begin{table}[h]
		\setlength{\abovecaptionskip}{5pt}
		\setlength{\belowcaptionskip}{-12pt}
		\small
		\centering
		\begin{tabular}{|l|l|}
			\hline
			\centering
			\textbf{Feature} & \textbf{Pearson $r$}\\
			\hline

			Emotional Support Sought&  0.15\\
			Informational Support Sought & - 0.13\\

			\hline

		\end{tabular}

		\caption{Correlation between social support sought and number of comments:  \textit{/r/OpiatesRecovery}. $p<0.001$. Number of users = 335}

		\label{tab:emo_info_corr_opiate_recovery}
	\end{table}

\noindent
\textbf{Results and Discussion:}
 Tables \ref{tab:emo_info_corr} and \ref{tab:emo_info_corr_opiate_recovery} show the correlation between social support sought in post-titles and number of comments in \textit{/r/Leaves} and \textit{/r/OpiatesRecovery}, respectively. We observed that in \textit{/r/Leaves}, the average informational support sought by users in post-titles correlates more with the average number of comments received by these users compared to the average emotional support sought. Also, we observed that in \textit{/r/OpiatesRecovery}, the average emotional support sought had a positive correlation with the average number of comments received compared  the average informational support sought which had a negative correlation with the average number of comments received.

  These findings can benefit members of substance use recovery forums; for example, users seeking to elicit comments to their posts published on \textit{/r/Leaves} may
  use linguistic cues associated with higher informational support in their post-titles. Also, the findings from this work can benefit substance use recovery forum moderators; given that there is a negative correlation between the informational support sought in post-titles in \textit{/r/OpiatesRecovery}, this potentially means that some users seeking informational support in this forum are not receiving support. Hence moderators of the forum can come up with ways in which these informational support seeking posts receive comments; for example informational support seeking posts not receiving comments may be sent to moderators or users familiar with the support sought.\\

\noindent
 \textbf{Limitations and Future Work:}

In our analysis, we focused on two subreddits -  \textit{/r/Leaves} and \textit{/r/OpiatesRecovery}, which are the forums focused on recovery from marijuana use and opiod use with the most number of members on Reddit. In the future, we would explore the relationship between social support expressed in posts and the responses (comments and votes) they receive, in other substance use recovery forums. While the results in this work indicate statistically significant
correlations, in the future, we would look at the affect of author tenure and Reddit karma (reputation) - all of which could potentially contribute to the response rates of posts.

\section{Conclusion}
We built two models to measure the extent of informational and emotional social support expressed in post-titles in two substance use recovery. We used these models to show the social supports that elicit comments in these forums.

\bibliographystyle{acl_natbib}


\section{Introduction}

\begin{figure}[t]
	\centering
	\includegraphics[width=\columnwidth]{Graphics/Fig1_BinaryClass.jpg}
	\caption{Simulation study demonstrating the strong brightness bias in Rectified Gradients. a) Synthetic examples were made from 4000 images from the Imagenette dataset. Black boxes were introduced to 2000 random images. b) Saliency maps were generated from Rectified Gradients and our proposed ``No Bias Rectified Gradients``.  The color-coding in the two saliency maps are different due to their intrinsic values. c) Importance scores are plotted in histograms comparing within and outside of a box. Note how for Rectified Gradient, all scores inside of the box are equal to zero.}
	\label{binary}
\end{figure}

While deep learning using artificial neural networks has shown great performance in computer vision and other areas, we are still seeking and developing ways to better explain why and how they work. Mechanisms underlying neural networks are often explored by saliency methods \cite{erhan2009visualizing, baehrens2010explain, Simonyan2014, Kim2019}. Generally, saliency methods calculate relevance or importance scores for input features (e.g., pixels in images) aimed at interpreting deep neural networks. Two-dimensional visualizations of importance scores are often referred to as saliency maps, which help to highlight input features relevant for classification or other tasks.

\begin{figure*}[!t]
	\centering
	\includegraphics[width=\textwidth]{Graphics/Figure2_Concept_Brightness}
	\caption{\small a) Saliency maps for ``eyeglasses'' using variational autoencoders (VAE). In saliency maps using ``RectGrad'' \cite{Kim2019}, the element-wise product of the input features and the gradient leads to being biased against the dark sunglasses that are not highlighted even though they are crucial. ``Proposed'' refers to our modification of Rectified Gradient, which removes the final multiplication step. b) Scatter plot of the pixel values (average over three color channels) in the original images and the saliency maps. RectGrad suppresses the gradients corresponding to dark pixels (e.g., 0), regardless of their importance for the sunglasses.}
	\label{bias_concept}
\end{figure*}

Saliency methods start from the gradient $M_{i}$ of a class score $S_\textnormal{class}$ with respect to the input features $p_{i}$, such as pixels for images $M_{i}=\partial S_\textnormal{class} / \partial p_{i}$. The class scores are usually taken to be activation of neurons in prediction vectors encoding the class of interest. The gradient tells us which input features have to be changed minimally to have a large influence on the class score. Therefore, larger magnitudes of gradients suggest greater relevance.

Similarly, saliency methods can be applied to deep generative models such as Variational Autoencoder (VAE) \cite{Kingma2014}. To achieve applicability to VAE and other generative models, which naturally lack known classes, concept vectors are used to compute concept scores $S_\textnormal{concept}$, which can be understood as a replacement for $S_\textnormal{class}$  \cite{Brocki_2019}. A concept vector is a latent representation of a high-level concept, which could be known attributes \cite{Larsen2016, White2016}, cluster memberships \cite{Huang2016}, or others. The concept score $S_\textnormal{concept}$ is then obtained by measuring the similarity of the latent representation of an input image $\mathbf z_i$ and the concept vector corresponding to that attribute $\mathbf z_c$.

Calculation of gradients is central to saliency methods, and thus have been modified to produce visually sharper or de-noised visualization. Based on calculating gradients in successive layers of neural network, Guided Backpropagation thresholds any negative values of gradients in each layer during backpropagation \cite{Springenberg2015}. Rectified Gradients generalize this thresholding and is shown to result in sharper saliency maps in some cases \cite{Kim2019}. However, we notice an input bias in Rectified Gradients \cite{Kim2019}. Dark spots in an image were not highlighted by Rectified Gradients, irrespective of the relevance for a chosen class or concept.

This bias is simply due to the element-wise product of the input features and the gradient. Similarly, variants of such multiplication steps, such as Layer-wise Relevance Propagation (LRP) \cite{bach2015pixel}, suffer from this bias. \cite{Adebayo2018} has shown how modified saliency maps showing unusual behaviors under randomization test. Our study provides a very simple reasoning behind why some modified saliency maps do not seem to deteriorate even when model parameters or data labels are randomized. For our concrete analysis, we focus on Rectified Gradient \cite{Kim2019} although our observation and modification are generally applicable. Comparisons are given using several neural networks, including both synthetic examples and real images. This straightforward study showcases how our visual inspection may lead underlying explainability of deep learning models astray.

A Python/Tensorflow package removing a bias step is available at \url{https://github.com/lenbrocki/nobias-rectified-gradient}.

\section{Bias in Rectified Gradient}\label{bias}

Gradients are generally noisy, when applied on image classification or other computer vision tasks involving deep neural networks \cite{erhan2009visualizing, baehrens2010explain, Simonyan2014, Kim2019}. Unlike how humans can easily identify an object in an image, it is not necessary for or constrained in neural networks to mimic this behavior. Rectified Gradient \cite{Kim2019} is a modified approach to the conventional calculation of gradients in order to reduce noise in saliency maps. Essentially, Rectified Gradients introduces layer-wise thresholding, such that artificially selected small values $< \tau$ are removed during backpropagation \cite{Kim2019}.

\begin{figure*}[t]
	\centering
	\includegraphics[width=\textwidth]{Graphics/Figure3_Imagenet_Scaled.jpg}
	\caption{\small a) Saliency maps for the class ``grey great owls'' in ImageNet. In ImageNet, pixel values are centered around 0. Then, the element-wise product of the input features and the gradient in Rectified Gradient \cite{Kim2019} creates a bias against this artificial point in color spectrum. In this ImageNet example, a middle grey (and surrounding values) would be suppressed. We find this example with grey birds. b) Scatter plot of the pixel values (average over three color channels) in the original images and the saliency maps. Horizontal lines indicate the pixel value of 0 which are artificially suppressed in Rectified Gradients.}
	\label{bias_imagenet}
\end{figure*}

We have observed that Rectified Gradient introduces an input bias in the saliency maps. Due to this bias, dark areas of an image are not highlighted even if they are highly relevant for the classification. We have identified the source of this bias to be a final multiplication of the saliency map $M_i$ with the input features $x_i$ which is critical part of the definition of Rectified Gradient. The saliency methods are obtained by Rectified Gradient as follows
\begin{align}
	R_l^k &= \sum_{j}\mathbf{1}(a^k_l\cdot R^j_{l+1}>\tau)\cdot R^j_{l+1},\label{backprop}\\
	M_i &= x_i R_0^i,
\end{align}
where $\mathbf 1$ is the step function, $a^j_l$ is the activation $j$ in layer $l$, $R_l^j$ is the gradient backpropagated up to $a^j_l$ and $l=0$ is the input layer. The equation for the backpropagation of the gradients through the ReLU \eqref{backprop} is a modification of the rule obtained directly from the chain rule
\begin{equation}
R_l^k = \sum_{j}\mathbf{1}(a^k_l > 0)\cdot R^j_{l+1},
\end{equation}
which is the definition used for the original saliency map \cite{erhan2009visualizing}. These modifications by \cite{Kim2019} were presented as to make the saliency maps less noisy. However, this has the undesirable effect of systematically neglecting dark features even when they are relevant. We therefore propose to simply remove the final multiplication with input features from Rectified Gradient, which will maintain its desirable feature of denoising the saliency maps while making it more generally applicable. This simplifies their method to $M_i = R_0^i$.

\section{Results}\label{result}

The consequence of multiplying the final gradients with input features is evident, since RGB (red, green, blue) values in images do not intrinsically contain meaningful information about classes or concepts. We demonstrate the resulting bias in three examples.

First, a simple synthetic example is generated by placing black squares on images from the Imagenette dataset (\url{https://github.com/fastai/imagenette}), a subset of ImageNet \cite{Russakovsky2015}. Out of 4000, 2000 images (50\%) were randomly chosen and black boxes were placed (Figure \ref{binary}(a)). As a result, the background images from the Imagenette dataset are not correlated to existence of black boxes. A binary classifier using three convolutional layers is built and trained on them. Training for 10 iterations achieved 99.8\% accuracy in the testing set, almost perfectly classifying the black box. Knowing that black boxes are artificially inserted into a random half of all images, only the black square in an image is relevant to this classifier. Thus, we expect the black square to be highlighted by having high values in accurate saliency maps. However, we noticed that Rectified Gradients of those black squares are zero, (Figure \ref{binary}(c)). Our proposed method successfully removes this bias.

Second, we investigate this bias when applying on variational autoencoders (VAE) on a large-scale face database with attributes called the CelebA dataset \cite{liu2015faceattributes}. All details about the architecture of the VAE and the training can be found in \cite{Brocki_2019}. Particularly, we focused on the concept ``eyeglasses'' which includes dark glasses and sunglasses. Figure \ref{bias_concept}(a) shows that our proposed method leads to a better highlighting (e.g., larger importance scores) of the dark glasses. Rectified Gradients (``RectGrad`` in Figure \ref{bias_concept}(a)) are suppressing any dark pixels and ended up with $M_i = 0$ if an input pixel is black $x_1 = 0$. Instead of highlighting the sunglasses, the saliency maps obtained using Rectified Gradient highlight the areas surrounding them. To show how gradients are modified, the scatterplot of the input features (averages of three color channels) and saliency maps (RectGrad or Proposed) are shown for each image (Figure \ref{bias_concept}(b)). Clearly, compared to our ``No Bias'' version, Rectified Gradients are showing artificially suppressed values when input pixel values are near 0.

Third, we use a deep residual net with 50 layers of convolutional neural networks called ResNet50 \cite{he2016deep} to classify examples from ImageNet \cite{Russakovsky2015}. This example is used to demonstrate that preprocessing and normalization do not remove the observed bias. In some applications of deep neural networks, pixel values are scaled from $\lbrack 0, 255 \rbrack$ to $\lbrack -0.5, 0.5 \rbrack$ (or other ranges). This preprocessing only shifts this bias to an artificial point in the color spectrum. In particular, a range of $\lbrack -0.5, 0.5 \rbrack$ which is typically used in ImageNet classifiers would introduce this bias at a middle grey. Those pixels around R=127.5, G=127.5, B=127.5 (which correspond to R=0, G=0, B=0 in the scaled range) would be strongly suppressed and will not appear to have highly relevant values in Rectified Gradients. This bias is particularly observed in ImageNet classes whose objects are naturally grey (Figure \ref{bias_imagenet}(a)). We see that grey great owls are better represented by the proposed method. The scatterplot of the scaled input features and saliency maps demonstrate this artificial bias around 0 in the y-axis (Figure \ref{bias_imagenet}(b)).

\section{Discussion and Conclusion}

Interpretability of deep learning methods is highly sought after. While the saliency methods based on gradients are showing great potential to identify and visualize relevant input features, it is critical to carefully consider how our qualitative evaluation (e.g., visual inspection) may differ from the underlying mechanisms of classification or conceptualization.

We have compared the saliency maps obtained with Rectified Gradients and with our proposed ``No Bias'' modification, which removes the final multiplication with input pixels, for three different case studies. In the first synthetic example, the difference between the two methods is particularly apparent because the black box is completely removed from the saliency map by Rectified Gradient, whereas our proposed method correctly highlights it. The second example used the concept score method to obtain saliency maps for a VAE with respect to the concept ``eyeglasses''. The dark eyeglasses are substantially better highlighted when using our proposed method. In the third example, it is demonstrated that a preprocessing step of scaling or normalizing the pixel values does not remove this input bias. These artificial biases are consistently apparent when plotting the input pixel values against the importance scores in saliency maps.

Generally, we are interested in better understanding and explaining the predictions or underlying mechanisms of deep neural networks, that are independent of the human biases. One may argue that when the target object is bright, a multiplication with input pixels would lead to less noisy saliency maps. However, if we know the characteristics of the target object, such information should be incorporated into the model.

It can not be excluded that the saliency maps should be noisy, because this might accurately reflect the behavior of the model. In an extreme situation, the model may use a few pixels to reach its accurate prediction. Then, for many irrelevant pixels, the importance scores are highly noisy that will result in noisy saliency maps. If an artificially de-noised saliency map is desired, it is more transparent and interpretable to  post-processing of the maps.

\section*{Acknowledgment}

This work was supported by the Narodowe Centrum Nauki [2016/23/D/ST6/03613] and the NVIDIA Corporation’s GPU grant.

\bibliographystyle{IEEEtran}