Efficient Neural Network based Classification and Outlier Detection for
  Image Moderation using Compressed Sensing and Group Testing
Popular social media platforms employ neural network based image moderation
engines to classify images uploaded on them as having potentially objectionable
content. Such moderation engines must answer a large number of queries with
heavy computational cost, even though the actual number of images with
objectionable content is usually a tiny fraction. Inspired by recent work on
Neural Group Testing, we propose an approach which exploits this fact to reduce
the overall computational cost of such engines using the technique of
Compressed Sensing (CS). We present the quantitative matrix-pooled neural
network (QMPNN), which takes as input $n$ images, and a $m \times n$ binary
pooling matrix with $m < n$, whose rows indicate $m$ pools of images i.e.
selections of $r$ images out of $n$. The QMPNN efficiently outputs the product
of this matrix with the unknown sparse binary vector indicating whether each
image is objectionable or not, i.e. it outputs the number of objectionable
images in each pool. For suitable matrices, this is decoded using CS decoding
algorithms to predict which images were objectionable. The computational cost
of running the QMPNN and the CS algorithms is significantly lower than the cost
of using a neural network with the same number of parameters separately on each
image to classify the images, which we demonstrate via extensive experiments.
Our technique is inherently resilient to moderate levels of errors in the
prediction from the QMPNN. Furthermore, we present pooled deep outlier
detection, which brings CS and group testing techniques to deep outlier
detection, to provide for the case when the objectionable images do not belong
to a set of pre-defined classes. This technique enables efficient automated
moderation of off-topic images shared on topical forums dedicated to sharing
images of a certain single class, many of which are currently human-moderated.
Sabyasachi Ghosh, Sanyam Saxena, Ajit Rajwade
Efficient Neural Network based Classification and Outlier Detection for Image Moderation using Compressed Sensing and Group Testing

###### Abstract

Popular social media platforms which allow users to upload image content employ neural network based image moderation engines to classify images as having potentially objectionable or dangerous content (such as images depicting weapons, drugs, nudity, etc). As millions of images are shared everyday, such image moderation engines must answer a large number of queries with heavy computational cost, even though the actual number of images with objectionable content is usually a tiny fraction of the total number. Inspired by recent work on Neural Group Testing, we propose an approach which exploits this fact to reduce the overall computational cost of such neural network based image moderation engines using the technique of Compressed Sensing (CS). We present the _quantitative matrix-pooled neural network_ (Qmpnn), which takes as input \(n\) images, and a \(m\times n\) binary pooling matrix with \(m<n\), whose rows indicate \(m\) pools of images i.e. selections of \(r\) images out of \(n\). The Qmpnn efficiently outputs the product of this matrix with the unknown sparse binary vector representing the classification of each image as objectionable or non-objectionable, i.e., it outputs the number of objectionable images in each pool. If the matrix obeys certain properties as required by CS theory, this compressed representation can then be decoded using CS algorithms to predict which input images were objectionable. The computational cost of running the Qmpnn and the CS decoding algorithms is significantly lower than the cost of using a neural network with the same number of parameters separately on each image to classify the images, which we demonstrate via extensive experiments. Our technique is inherently resilient to moderate levels of errors in the prediction from the Qmpnn. Furthermore, we present pooled deep outlier detection, which brings CS and group testing techniques to deep outlier detection, to provide for the important case when the objectionable images do not belong to a set of pre-defined classes. This technique is designed to enable efficient automated moderation of off-topic images shared on topical forums dedicated to sharing images of a certain single class, many of which are currently human-moderated.

## 1 Introduction

Compressed sensing (CS) has been a very extensively studied branch of signal/image processing, which involves acquiring signals/images directly in compressed form as opposed to performing compression post acquisition. Consider a possibly noisy vector \(\mathbf{y}\in\mathbb{R}^{m}\) of measurements of the signal \(\mathbf{x}\in\mathbb{R}^{n}\) with \(m\ll n\), where the measurements are acquired via a sensing matrix \(\mathbf{\Phi}\in\mathbb{R}^{m\times n}\) (implemented in hardware). Then we have the relationship:

\[\mathbf{y}=\mathbf{\Phi}\mathbf{x}+\mathbf{\eta}, \tag{1}\]

where \(\mathbf{\eta}\in\mathbb{R}^{m}\) is a vector of i.i.d. noise values. CS theory [15, 30] states that under two conditions, \(\mathbf{x}\) can be stably and robustly recovered from \(\mathbf{y},\mathbf{\Phi}\), with rigorous theoretical guarantees, by solving convex optimization problems such as the Lasso[30], given as follows:

\[\mathbf{\hat{x}}\triangleq\operatorname*{argmin}_{\mathbf{x}}\|\mathbf{y}-\mathbf{\Phi}\mathbf{x} \|^{2}+\lambda\|\mathbf{x}\|_{1}, \tag{2}\]

where \(\lambda\) is a carefully chosen regularization parameter. The two conditions are: (\(\mathcal{C}1\)) \(\mathbf{x}\) should be a sufficiently sparse vector, and (\(\mathcal{C}2\)) no sparse vector, except for a vector of all zeroes, should lie in the null-space of \(\mathbf{\Phi}\). \(\mathcal{C}1\) and \(\mathcal{C}2\) ensure
that \(\mathbf{y}\) and \(\mathbf{x}\) are uniquely mapped to each other via \(\mathbf{\Phi}\) even though \(m\ll n\). \(\mathcal{C}2\) is typically satisfied when the entries of \(\mathbf{\Phi}\) belong to sub-Gaussian distributions and when \(m\geq O(k\log n/k)\). If these conditions are met, then successful recovery of a vector \(x\) with at the most \(k\) non-zero elements is ensured [15, 30].

Group testing (GT), also called pooled testing, is an area of information theory which is closely related to CS [25]. Given a set of \(n\) samples (for example, blood/urine samples) that need to be tested for a _rare_ disease, GT replaces tests on the individual samples by tests on _pools_ (also called _groups_), where each pool is created using a subset of the \(n\) samples. Given the test results on each pool (as to whether or not the pool contains one or more diseased samples), the aim is to infer the status of the individual \(n\) samples. This approach dates back to the classical work of Dorfman [20, 8] and has been recently very successful in saving resources in COVID-19 RT-PCR testing [24, 45]. In some cases, side information in the form of contact tracing matrices has also been used to further enhance the results [29, 27, 26]. If the test results report the _number_ of defective/diseased samples in a pool instead of just a binary result, it is referred to as quantitative group testing (QGT) [43].

**Image moderation** is the process of examining image content to determine whether it depicts any objectionable content or violates copyright issues. In this paper, we are concerned with semantic image moderation to determine whether the image _content_ is objectionable, for example depiction of violence (such as images of weapons), or whether it is off-topic for the chosen forum (such as images of a tennis game being shared on an online forum for baseball).

Manually screening the millions of images shared on online forums like Facebook, Instagram, etc. is very tedious. There exist many commercial solutions for automated image moderation (Amazon, Azure, Picpurify, Webpurify). However, there exists only a small-sized body of academic research work in this area, mostly focused on specific categories of objectionable content, such as firearms/guns [12], knives [28, 17] or detection of violent scenes in images/videos [22]. Most of these papers employ neural networks for classification, given their success in image classification tasks since [33]. However large-scale neural networks require several Giga-flops of operations for a single forward pass [13] and consume considerable amounts of power as shown in [11, 40]. Thus, methods to reduce the heavy load on moderation servers are the need of the hour. Besides reduction in power consumption, it is also helpful if the computational cost for image moderation engines is reduced significantly.

In this work, we present a CS approach to speed up image moderation. Consider a set of \(n\) images, each of which may independently have objectionable content with a small probability \(p\), called the _prevalence rate_ of objectionable images (henceforth referred to as OIs). Small \(p\) is justified by independent reports from forums such as Facebook [1] (\(0.03-0.14\%\)) or Reddit [5] (\(6\%\)), where millions of images are regularly uploaded and where image or content moderation is an important requirement. Instead of invoking a neural network separately on each image to classify it as objectionable or non-objectionable, we introduce the _quantitative matrix-pooled neural network_ (Qmpnn), which takes in a specification of \(m<n\) pools of images - each pool being a selection of \(r\) out of \(n\) images - and efficiently predicts the count of OIs in these pools. Similar to [38], the Qmpnn runs the first few layers of the neural network on each image of a pool and computes their Intermediate Feature Maps (IFMs), computes the superposed feature map (SFM) of the pool from its constituent IFMs, and processes only the SFM using the remaining layers of the network. However, unlike [38], the IFM for each image is computed only once, and all \(n\) images are processed in a single forward pass to produce the \(m\) pool outputs. Such a design ensures that the computational cost of running the

Figure 1: Left: Main Components of our Image Moderation Engine; Right top: A pool of \(8\) images containing \(2\) images of firearms which are considered objectionable images (OIs); Right, bottom: The first \(9\) channels of the Superposed Feature Map (SFM) for this pool. The SFM has size \(512\times 28\times 28\).
network on the \(m\) pools is lower than that of running the network on the \(n\) images individually. The pool specification is given by an \(m\times n\) binary pooling matrix. The output of the Qmpnn is thus the product of the pooling matrix and the _sparse_ unknown binary vector specifying whether each image was objectionable or not. We employ CS algorithms, which run at very little additional cost, to determine the status of each of the \(n\) images from the Qmpnn's results on the \(m\) pools.

The above method and the one used in [38] are applicable only to classification problems, where the objectionable images belong to a single or a limited number of classes. However, in many commonly occurring cases, the the objectionable images may belong to a large number, in fact even an unknown number of classes. For example, on a topical forum dedicated to sharing information about tennis, any image whose content is not related to tennis can be considered objectionable. This no longer belongs to the realm of classification, but is instead an outlier detection problem. We extend our earlier approach of combining neural networks and CS algorithms to deal with this application via a novel technique. Our work in this paper is inspired by that in [38] which was the first work to apply GT principles to the problem of binary classification in the presence of class imbalance. However, we significantly build up on their setup and technique, and make the following contributions (see also Sec. 3.4 for more details):

1. We show that the problem of classifying the original \(n\) images (as OI or not) from these \(m\) counts (each count belonging to a pool) can be framed as a CS problem with some additional constraints (Sec. 3). We employ various algorithms from the CS and GT literature for this purpose (Sec. 3.2). Via an efficient implementation of our network called Qmpnn, we enable usage of pooling matrices in which one image can be a part of _many_ pools. As opposed to this, in the approach in [38], each new pool that an image contributes to, incurs an additional cost, which makes it impractical to have an image contribute to more than two pools. Since each image contributes to many pools, an improved resilience to any errors in the network outputs can be obtained.
2. We test our method for a wide range of prevalence rates \(p\) and show that it achieves significant reduction in computation cost and end-to-end wall-clock time compared to individual moderation of images, while remaining competitive in terms of classification accuracy despite noisy outputs by the pooled neural network (Sec. 4).
3. We also show that our method outperforms binary group testing methods, as used in [38], for high \(p\), where quantitative information is more important (Sec. 4).
4. Our decoding algorithms are designed to be noise-tolerant, as opposed to existing GT algorithms used for this problem which do not handle the case of a pool falsely testing negative for the presence of an objectionable image as done in [38] (also see Sec. 4).
5. Finally, we present a novel _pooled deep outlier detection_ method for computationally efficient automatic identification of off-topic images on internet forums such as Reddit (Sec. 3.3). Moderation of such off-topic content is currently either done manually or via text-based tools [31]. Note that off-topic images do not belong to a set of pre-defined classes, making this problem different from the one where OIs belonged to a single class. To

\begin{table}
\begin{tabular}{|l l|} \hline \multicolumn{2}{|l|}{**List of Abbreviations**} \\ \hline Bmpnn & Binary Matrix-Pooled Neural Network \\ Bpmn & Binary Pooled Neural Network \\ CLasso & Constrained Least Absolute Shrinkage and Selection Operator \\ Comp & Combinatorial Orthogonal Matching Pursuit \\ CS & Compressed Sensing \\ GMM & Gaussian Mixture Model \\ GT & Group Testing \\ IFM & Intermediate Feature Map \\ Inn & Individual Neural Network \\ Mip & Mixed Integer Programming Method \\ NComp & Noisy Combinatorial Orthogonal Matching Pursuit \\ NLPD & Negative Log Probability Density \\ OD & Outlier Detection \\ OI & Objectionable Image \\ QGT & Quantitative Group Testing \\ Qmpnn & Quantitative Matrix-Pooled Neural Network \\ Qnn & Quantitative Pooled Neural Network \\ SFM & Superposed Feature Map \\ \hline \end{tabular}
\end{table}
Table 1: List of Abbreviations
the best of our knowledge, the approach proposed in this paper is the first one in the literature to present this problem in the context of compressed sensing or group testing.

In this paper, we combine the capabilities of neural networks and CS algorithms in a specific manner. Neural networks have been used in recent times for CS recovery [48, 51, 35] with excellent results. However, in this paper, we are using neural networks for either a noisy classification or a noisy outlier detection task, retaining the usage of classical CS or GT algorithms.

## 2 Group Testing Background

We first define some important terminology from the existing literature, which will be used in this paper. In **binary group testing**, there are \(n\) items, of which \(k\ll n\) unknown items are defective. Instead of individually testing each item, a pooled test (or group test) is performed on a pool/group of items to determine whether there exists at least one defective item in the pool, in which case the test is said to be 'positive' (otherwise 'negative'). The goal of group testing is to determine which \(k\) items are defective with as few tests as possible. In **quantitative group testing**, pooled tests give the _count_ of the number of defective items in the pool being tested. In **non-adaptive group testing**, the number of tests and the pool memberships do not depend on the result of any test, and hence all tests can be performed in parallel. In **adaptive group testing**, the tests are divided into two or more rounds, such that the pool memberships for tests belonging to round \(t_{r}+1\) depend on the test outcomes from rounds \([t_{r}]\triangleq\{1,\cdots,t_{r}\}\). **Dorfman Testing** is a popular \(2\)-round binary, adaptive algorithm [20], widely used in COVID-19 testing [49]. In round 1 of Dorfman testing, the \(n\) items are randomly assigned to one out of \(n/g\) groups, each of size \(g\). All items which are part of a negative pool are declared non-defective. All items which are part of a positive pool are then tested individually in round 2. The optimal pool size \(g\) which minimizes the number of tests in the worst case is \(\sqrt{n/k}\) and the number of tests is at most \(2\sqrt{nk}\)[20].

A **pooling matrix**\(\mathbf{\Phi}\) is a \(m\times n\) binary matrix, where \(\mathbf{\Phi}_{ij}=1\) indicates that item \(j\) was tested as part of pool \(i\) and \(\mathbf{\Phi}_{ij}=0\) otherwise. Let \(\mathbf{x}\) be the unknown binary vector with \(x_{j}=1\) if item \(j\) is defective, \(0\) otherwise. Then the outcome of the pooled tests in binary group testing may be represented by the binary vector \(\mathbf{y}\), such that \(y_{i}=\bigvee_{i=1}^{n}\mathbf{\Phi}_{ij}\wedge x_{j}\) where \(\vee\) and \(\wedge\) denote the Boolean OR and AND operations respectively. The outcome of pooled tests in quantitative group testing may be represented by the integer-valued vector \(\mathbf{y}=\mathbf{\Phi}\mathbf{x}\) obtained by multiplication of the matrix \(\mathbf{\Phi}\) with the vector \(\mathbf{x}\). In both binary and quantitative group testing, a **decoding algorithm** recovers \(\mathbf{x}\) from known \(\mathbf{y}\) and \(\mathbf{\Phi}\). Group testing is termed **noisy** or **noiseless** depending on whether or not the test results \(\mathbf{y}\) contain noise.

## 3 Main Approach

Fig. 1 shows the main components of our approach for image moderation (see also Alg. 1). Consider a set of \(n\) images, \(\mathcal{I}=\{I_{1},\ldots,I_{n}\}\), represented by a \(n\)-dimensional binary vector \(\mathbf{x}\), with \(x_{i}=1\) if the \(i^{\text{th}}\) image has objectionable content and \(x_{i}=0\) otherwise. The binary _pooling matrix_\(\mathbf{\Phi}\) of dimensions \(m\times n\) specifies the \(m\) image pools \(\{P_{1},\ldots,P_{m}\}\), to be created from the images in \(\mathcal{I}\). Each row of \(\mathbf{\Phi}\) has sum equal to \(r\), which means that each pool has \(r\) images. The pooling matrix \(\mathbf{\Phi}\) and the \(n\) images in \(\mathcal{I}\) are passed as input to a so-called _quantitative matrix-pooled neural network_ (Qmpnn, see Sec. 3.1) which is specifically trained to output the number of OIs in each pool in the form of a \(m\)-element vector \(\mathbf{y}\). If the output of the Qmpnn is perfect, then clearly, for all \(q\in\{1,\ldots,m\}\), \(y_{q}=\sum_{I_{i}\in P_{q}}\mathbbm{1}(x_{i}=1)=\sum_{i=1}^{n}\mathbf{\Phi}_{qi}x_{i}\), which gives us \(\mathbf{y}=\mathbf{\Phi}\mathbf{x}\) just as in Sec. 2. Hence, recovery of the unknown
vector of classifications \(\mathbf{x}\) given the output \(\mathbf{y}\) of Qmpnn (the vector of \(m\) different quantitative group tests) and the pooling matrix \(\mathbf{\Phi}\) can be framed as a CS problem. Such an approach is non-adaptive because the pool memberships for each image are decided beforehand, independent of the Qmpnn outputs. Furthermore, comparing with Eqn. 1, we see that this CS problem has boolean constraints on each \(x_{i}\), and with \(y_{q}\in\{0,\ldots,r\}\) for each \(q\). In general the Qmpnn will not be perfect in reporting the number of OIs, hence the \(\mathbf{y}\) vector predicted will be noisy. This is represented as:

\[\mathbf{y}=\mathfrak{N}(\mathbf{\Phi}\mathbf{x}), \tag{3}\]

where \(\mathfrak{N}(.)\) is a noise operator, which may not necessarily be additive or signal-independent unlike the case in Eqn. 1. However, we experimentally find that CS algorithms, which are specifically designed for signal-independent additive noise, are effective even in the case of noise in the outputs of the Qmpnn.

### Pooled Neural Network for Classification

The idea of a pooled neural network was first proposed in [38]. We make two key changes to their design - (1) incorporate the pooling scheme within the neural network which enables efficient non-adaptive (one-round) testing, and (2) have quantitative outputs instead of binary, which enables CS decoding. We discuss the significance of our architectural changes in detail in Sec. 3.4. Below, we describe the pooled neural network architecture from [38] and then our network models. The rest of this section uses many abbreviations. For the reader's convenience, a complete list is presented in Table 1.

Consider a feed-forward deep neural network which takes as input a single image for classifying it as objectionable or not. We term such a network an _individual neural network_, or Inn. Furthermore, let this neural network have the property that it may be decomposed into \(L\) blocks parameterized by the (mutually disjoint) sets of parameters \(\theta_{j},j\in\{1,\ldots,L\}\), with \(\mathbf{\Theta}\triangleq\bigcup_{j=1}^{L}\theta_{j}\), so that for any input image \(I\),

\[\mathtt{INn}_{\mathbf{\Theta}}(I)\triangleq f_{\theta_{L}}^{(L)}\circ f _{\theta_{L-1}}^{(L-1)}\circ\cdots\circ f_{\theta_{1}}^{(1)}(I), \tag{4}\]

where \(\circ\) represents function composition, and where each block computes a function \(f_{\theta_{j}}^{(j)},j\in\{1,\ldots,L\}\). Furthermore, the \(L^{\text{th}}\) block is a linear layer with bias, and has two outputs which are interpreted as the unnormalized log probability of the image being objectionable or not. Below, we derive _pooled neural networks_ based on an Inn parameterized by \(\mathbf{\Theta}\), and which take as input more than one image.

Consider the output of only the first \(l<L\) blocks of the INN on an input image \(I\). We call this the _intermediate feature-map_ (IFM) of image \(I\), with \(\mathtt{IFM}_{\mathbf{\Theta}}(I)\triangleq f_{\theta_{1}}^{(l)}\circ\cdots\circ f _{\theta_{1}}^{(1)}(I)\). Consider a _pool_ created from \(r\) images, given as \(P\triangleq\{I_{1},I_{2},\ldots,I_{r}\}\). A _superposed feature map_ (SFM) of the pool of images \(P\) is obtained by taking an entry-wise max over the feature-maps of individual images, i.e. \(\mathtt{SFM}_{\mathbf{\Theta}}(P)(.)\triangleq\max_{I\in P}\mathtt{IFM}_{\mathbf{ \Theta}}(I)(.)\) (known as 'aggregated features' in [38]). In a _binary pooled neural network_ (Bpmn), the SFM of a pool of images \(P\) is processed by the remaining \(L-l\) blocks of the Inn:

\[\mathtt{BPNN}_{\mathbf{\Theta}}(P)\triangleq f_{\theta_{L}}^{(L)}\circ f _{\theta_{L-1}}^{(L-1)}\circ\cdots\circ f_{\theta_{1+1}}^{(l+1)}\circ\mathtt{ SFM}_{\mathbf{\Theta}}(P). \tag{5}\]

The two outputs of a Bpmn are interpreted as the unnormalized log probability of the pool \(P\) containing an image belonging to the OI class or not. A Bpmn has the same number of parameters as the corresponding Inn. This was introduced in [38], where it is referred to as 'Design 2'.

In this work, we introduce a _quantitative pooled neural network_ (Qpmn), which is the same as a Bpmn except that it has \(r+1\) outputs instead of \(2\). Due to this there are more parameters in the last linear layer (the \(L^{\text{th}}\) block). Let these parameters be denoted by \(\tilde{\theta}_{L}\), with the \(L^{\text{th}}\) block computing a function \(f_{\tilde{\theta}_{L}}^{(L)}\), and \(\mathtt{QPNN}_{\tilde{\mathbf{\Theta}}}(P)\triangleq f_{\tilde{\theta}_{L}}^{(L)} \circ\ldots f_{\theta_{1+1}}^{(l+1)}\circ\mathtt{SFM}_{\mathbf{\Theta}}(P)\), with \(\tilde{\mathbf{\Theta}}\triangleq\bigcup_{j=1}^{L-1}g_{j}\cup\tilde{\theta}_{L}\). The \(r+1\) outputs of a Qpmn are interpreted as the unnormalized log probabilities of the pool \(P\) containing \(0\) through \(r\) instances of images which belong to the OI class.

Finally, we introduce the _quantitative matrix-pooled neural network_ (Qmpnn), which takes as input a set of \(n\) images \(\mathcal{I}\triangleq\{I_{1},\ldots,I_{n}\}\), a specification of \(m\) pools containing \(r\) out of \(n\) images in each pool via binary matrix \(\mathbf{\Phi}\), and outputs \(r+1\) real numbers for each of the \(m\) pools, in a single forward pass. That is,

\[\mathtt{QMPNN}_{\tilde{\mathbf{\Theta}}}(\mathcal{I},\mathbf{\Phi}) \triangleq(\mathtt{QPNN}_{\tilde{\mathbf{\Theta}}}(P_{1}),\ldots, \mathtt{QPNN}_{\tilde{\mathbf{\Theta}}}(P_{m})) \tag{6}\] \[\text{where }P_{q} \triangleq\{I_{i}|\Phi_{qi}=1,I_{i}\in\mathcal{I}\}\ \forall q\in\{1,\ldots,m\}.\]

For a pool \(q\), the \(s^{\text{th}}\) output (\(s\in\{0,\ldots,r\}\)) is interpreted as the unnormalized log probability of the pool \(q\) containing \(s\) images belonging to the OI class. Notably, the IFM for each of the \(n\) images is computed only once by the Qmpnn, and is re-used for each pool that it takes part in. A _binary matrix-pooled neural network_ (Bmpnn) is exactly the same
as a Qmpnn except that each pool has only two outputs. We note that while the first \(l\) blocks of the neural network are run for each of the \(n\) images, the remaining \(L-l\) blocks are only run for each of \(m\) SFMs. However, if an individual neural network (Inn) is run on the \(n\) images, then both the first \(l\) blocks and the last \(L-l\) blocks will be run \(n\) times. Hence, since \(m<n\), the Qmpnn (and the Bmpnn) requires significantly less computation than running the Inn on the \(n\) images, which we verify empirically in Sec. 4.

**Training:** Let \(\mathcal{D}\) be a dataset of images labelled as OI or non-OI. A _pooled dataset_\(\mathcal{D}_{\text{pooled}}\) is obtained from \(\mathcal{D}\). Each entry of \(\mathcal{D}_{\text{pooled}}\) is a pool of \(r\) images, and has a label in \(\{0,\dots,r\}\), equal to the number of images in that pool which belong to the OI class. Details of creation of the pooled dataset are given in Sec. 4. The parameters \(\mathbf{\tilde{\Theta}}\) of a Qpmn are trained via supervised learning on \(\mathcal{D}_{\text{pooled}}\) using the cross-entropy loss function, \(L(\mathbf{\tilde{\Theta}})=\underset{(P,c)\sim\mathcal{D}_{\text{pool}}}{E}[- \log\sigma(\texttt{QPNN}_{\mathbf{\tilde{\Theta}}}(P))_{c}]\), where \(\sigma(.)\) is the softmax function, given by \(\sigma(\mathbf{z})_{s}\triangleq\frac{e^{s}}{\sum_{i=0}^{s}e^{rt}}\). The parameters \(\Theta\) of a Bpmn are trained similarly, except that each training pool has a label in \(\{0,1\}\), with \(1\) indicating pools which contain at least one OI.

**Inference:** The trained parameters \(\mathbf{\tilde{\Theta}}\), and a pooling matrix \(\mathbf{\Phi}\) are then used to instantiate a Qmpnn. The entries of the vector \(\mathbf{y}\), containing pool-level predictions of the count of OIs in each pool, are obtained from a Qmpnn as:

\[y_{q}=\operatorname*{arg\,max}_{s\in\{0,1\dots,r\}}\texttt{ QMPNN}_{\mathbf{\tilde{\Theta}}}(\mathcal{I},\mathbf{\Phi})(q,s)\;\forall q\in \{1,\dots,m\}. \tag{7}\]

In Sec. 3.2, we present CS algorithms to decode this vector \(\mathbf{y}\) to recover the vector \(\mathbf{x}\) for classification of each image in \(\mathcal{I}\).

Similarly, the trained parameters \(\mathbf{\Theta}\) of a Bpmn and a pooling matrix \(\mathbf{\Phi}\) can be used to instantiate a Bmpnn. The entries of the binary vector \(\bar{\mathbf{y}}\) containing pool-level predictions of whether each pool contains an OI or not can be obtained from the Bmpnn as:

\[\bar{y}_{q}=\operatorname*{arg\,max}_{s\in\{0,1\}}\texttt{ BMPNN}_{\mathbf{ \tilde{\Theta}}}(\mathcal{I},\mathbf{\Phi})(q,s)\;\forall q\in\{1,\dots,m\}. \tag{8}\]

This can be decoded by the non-adaptive binary group testing decoding algorithms presented in Sec. 3.2.

### CS/GT Decoding Algorithms

Given Eqn. 3, the main aim is to recover \(\mathbf{x}\) from \(\mathbf{y}\) (the prediction of the Qmpnn, Eqn. 7) and \(\mathbf{\Phi}\). For this, we propose to employ the following two algorithms:

1. Mixed Integer Programming Method (Mip): We minimize the objective in Eqn. 2 with boolean constraints on entries of \(\mathbf{x}\), i.e. \(\forall i\in[n],x_{i}\in\{0,1\}\). We use the CVXPY [19][7] package with the Gurobi [6] solver, which uses a branch and bound method for optimization [3].
2. Constrained LASSO (CLasso): This is a variant of the Lasso from Eqn. 2, with the values in \(\mathbf{x}\) constrained to lie in \([0,1]\). The relaxation from \(\{0,1\}\) to \([0,1]\) is done for computational efficiency. The final estimate regarding whether each of the images is an OI is obtained by thresholding \(\mathbf{\hat{x}}\), i.e. \(\forall i\in[n]\), \(I_{i}\) is considered to be an OI if \(\hat{x}_{i}>\tau\), where \(\tau\) is the threshold determined on a validation set.

The hyperparameters in our algorithms (\(\lambda\) for CLasso and Mip, and \(\tau\) for CLasso) are chosen via grid search so as to maximize the product of specificity and sensitivity (both defined in Sec. 4) on a representative validation set of images of known classes.

We also compare with some popular algorithms the from binary group testing literature, which act as a baseline. For the non-adaptive methods, the binary vector \(\bar{\mathbf{y}}\) containing predictions of a Bmpnn (from Eqn. 8) is provided to the decoding algorithms. The algorithms are:

1. Dorfman Testing: See Sec. 2. This is referred to as Two-Round testing in [38, Algorithm 1]. In the first stage, a binary pooled neural network (Bpmn) is used to classify a pool of images as containing an objectionable image or not. If the Bpmn predicts that the pool contains an objectionable image, then each image is tested individually in a second round using an individual neural network (Inn). Otherwise, all images in the pool are declared as not being objectionable, without testing them individually. Because of a second round of testing, Dorfman Testing is inherently resistant to a pool being falsely declared as positive, but not to a pool being falsely declared as negative.
2. Combinatorial Orthogonal Matching Pursuit (Comp) [16]: This is a simple decoding algorithm for noiseless non-adaptive binary group testing, wherein any image which takes part in at least one pool which tests negative (i.e., no OIs in the pool) is declared as a non-OI, and the remaining image are declared as OIs. The One-Round Testing method in [38] uses Comp decoding, albeit with a different pooling matrix than ours.
3. Noisy Comp (NComp) [16]: a noise-resistant version of Comp. An image is declared to be OI if it takes part in strictly greater than \(t\) positive pools (or equivalently in strictly less than \(c-t\) negative pools, where \(c\) is the number pools that each image takes part in).

A good pooling matrix \(\mathbf{\Phi}\) is crucial for the performance of these algorithms. We choose binary matrices with equal number of ones in each column, equal number of ones in each row, with the dot product of each pair of columns and each pair of rows at most \(1\). More details about this are provided in Appendix A.2.

### Pooled Deep Outlier Detection

Here, we consider the case where the set of allowed images belong to one underlying class, and any image not belonging to that class is considered 'off-topic'. Such a situation arises in the moderation of topical communities on online forums such as Reddit (e.g. see [31]). For example, an image of a baseball game is off-topic on a forum meant for sharing of tennis-related images. As the off-topic images could belong to an unbounded variety of classes, instances of all or some of which may not be available for 'training', _classification_ based approaches (such as the Qmpnn from Sec. 3.1, and [38]) may not be directly applicable, and instead, _deep outlier detection_ based methods are more suitable.

Recent deep outlier detection methods [36, 44] approximate a class of interest, represented by suitable feature vectors \(\mathbf{\mathbb{R}}^{d}\), using a high dimensional Gaussian distribution characterized by a mean vector \(\mathbf{\mu}\in\mathbb{R}^{d}\) and a covariance matrix \(\mathbf{\Sigma}\in\mathbb{R}^{d\times d}\). Then the Mahalanobis distance between the feature vectors of a test image and the mean vector \(\mathbf{\mu}\) is computed. This Mahalanobis distance acts as the anomaly score to perform outlier detection, i.e. test feature vectors with a Mahalanobis distance greater than some threshold (say \(\bar{\tau}_{md}\)) are considered outliers. The feature vectors can be represented by the outputs of a suitably trained neural network. One may think of using such an approach with a pooled neural network to detect pools containing outlier images. However a single Gaussian distribution is often inadequate to represent a sufficiently diverse class, and hence we resort to using a Gaussian Mixture Model (GMM). We put forward a novel approach which uses a pooled neural network combined with a GMM, to detect anomalous pools, i.e., pools which contain at least one off-topic image, which we term _pooled deep outlier detection_. This enables us to use binary group testing methods from Sec. 3.2 - such as Comp, NComp and Dorfman Testing - for pooled outlier detection. Furthermore, we also detect the number of outlier images in a pool, thus enabling CS methods to be used for pooled outlier detection. To the best of our knowledge, this is the first such work in the literature, which enables group testing and compressed sensing methods to be used for outlier detection.

We consider the setting where for training we have available a set of images which are either on-topic or are off-topic images from known classes, but at test time the off-topic images may be from unknown classes. We train a Qpm using the method in Sec. 3.1, with the label \(L(P)\) for any training pool \(P\) set to the number of off-topic images in it. The output of the last-but-one layer of the Qpmn (i.e. the \((L-1)^{\text{th}}\) layer - see Sec. 3.1) is considered to be the feature vector \(\phi(P)\) for the pool of images \(P\) which is input to it. First, we create \(M\) pools from the on-topic training data images (i.e. these pools have \(0\) off-topic images), and fit a GMM \(G\) with some \(K\) clusters to the feature vector \(\phi(.)\) of all these pools, using the well-known expectation-maximization (EM) algorithm. The optimal value of \(K\) is chosen via cross-validation, by selecting the \(K\) with the maximum likelihood given a held-out set of pools containing only on-topic images.

For any pool \(P\), we use the negative log probability density of its feature vector \(\texttt{NLP}_{G}(\phi(P))\) (negative log
probability density) under the GMM \(G\) as an anomaly score, given by:

\[\texttt{NLPD}_{G}(\phi(P)):=-\log\left(\sum_{j=1}^{K}p_{j}\mathcal{N}(\phi(P)| \boldsymbol{\mu_{j}},\boldsymbol{\Sigma_{j}})\right), \tag{9}\]

where \(\{\boldsymbol{\mu_{1}},\boldsymbol{\mu_{2}},\cdots,\boldsymbol{\mu_{K}}\}\) are the \(K\) mean vectors, \(\{\boldsymbol{\Sigma_{1}},\boldsymbol{\Sigma_{2}},\cdots,\boldsymbol{\Sigma_{K }}\}\) are the \(K\) covariance matrices and \(\{p_{1},p_{2},\cdots,p_{K}\}\) are the \(K\) membership probabilities of the GMM \(G\), and for any vector \(\mathbf{z}_{i}\), \(\mathcal{N}(\mathbf{z}|\boldsymbol{\mu_{j}},\boldsymbol{\Sigma_{j}})\) is its probability density given the multivariate normal distribution with mean \(\boldsymbol{\mu_{j}}\) and covariance matrix \(\boldsymbol{\Sigma_{j}}\).

It is intuitive to imagine that \(\texttt{NLPD}_{G}(\phi(P))\) values would generally be larger for pools containing a larger number of outlier images (\(L(P)\)), and we should be able to predict \(L(P)\) given \(\texttt{NLPD}_{G}(\phi(P))\). The main idea is to create a histogram of anomaly scores of pools with different number of off-topic images in them, and assign to a new pool the label which is most common in its bin. This is accomplished as follows. From the _validation_ set of images, some \(N\) pools \(\{P_{i}\}_{i=1}^{N}\) are created, each containing \(r\) images. Since off-topic images are expected to be rare at test time, we only consider pools which contain upto some \(t<r\) off-topic images. Thus \(L(P)\in\{0,1,\ldots,t\}\). For each pool \(P_{i}\), the value \(\texttt{NLPD}_{G}(\phi(P_{i}))\) is computed. These NLPD values are divided into some \(Q\) bins/intervals and an anomaly score histogram \(H_{G}\) is created in the following manner:

\[\forall j\in\{1,2,\cdots,Q\},\forall l\in\{0,1,\cdots,t\},H_{G}(j,l)=\frac{ \#\text{pools in bin $j$ containing $l$ outlier images}}{N}. \tag{10}\]

That is, \(H_{G}(j,l)\) represents the fraction of pools from \(\{P_{i}\}_{i=1}^{N}\) which contain \(l\) outlier images and whose NLPD value falls into the \(j^{\text{th}}\) bin. This histogram \(H_{G}\) is created at the time of training.

Each non-empty bin \(j\) is assigned a label \(\mathcal{L}(j)\) equal to \(\text{argmax}_{l\in\{0,1,\ldots,t\}}H_{G}(j,l)\), i.e., the label with the most number of pools in that bin. An empty bin is assigned the label of its nearest non-empty bin. If there is more than one nearest non-empty bin, then the bin is assigned the label of the bin with the larger index. At test time, given the feature vectors \(\phi(P_{\text{test}})\) of a pool \(P_{\text{test}}\) created from some \(r\) test images, first its anomaly score \(\texttt{NLPD}_{G}(\phi(P_{\text{test}}))\) is computed using the GMM. If the anomaly score lies in bin \(j_{\text{test}}\), then \(P_{\text{test}}\) is assigned the label \(\mathcal{L}(j_{\text{test}})\). If the anomaly score is to the right of all bins (i.e. greater than the right index of the rightmost bin), then it is assigned the label \(t\). If it is to the left of all bins (i.e. less than the left index of the leftmost bin), then it is assigned the label \(0\). That is,

\[L(P_{\text{test}})=\begin{cases}\mathcal{L}(j_{\text{test}})&\text{if $\texttt{NLPD}_{G}(\phi(P_{\text{test}}))$}\in\text{ bin $j_{\text{test}}$}\\ 0&\text{if $\texttt{NLPD}_{G}(\phi(P_{\text{test}}))$}<s_{\text{min}}\\ t&\text{if $\texttt{NLPD}_{G}(\phi(P_{\text{test}}))$}>s_{\text{max}}\end{cases}, \tag{11}\]

where \(s_{\text{min}}\) and \(s_{\text{max}}\) are respectively the smallest and the largest of the \(N\) NLPD values used to create the histogram \(H\).

At the time of deployment, \(m\) pools are created from \(n\) images to be tested for off-topic content using a Qmpnn and a pooling matrix \(\Phi\), and feature vectors of the \(m\) pools are obtained. For each pool, we determine the number of off-topic images it contains using the GMM and histogram-based method just described. Given these \(m\) numbers and
the pooling matrix \(\Phi\), we predict whether or not each of the \(n\) images is off-topic using the CS and non-adaptive GT decoding algorithms described in Sec. 3.2. Our method is summarized in Algorithm 2.

We also perform Dorfman Testing for outlier detection. Feature vectors of a pool of \(r\) images are obtained by running a Qpnn, and the GMM and histogram-based method is used to predict the number of off-topic images in the pool. If the pool is predicted to contain at least one off-topic image, then each image is individually tested for being off-topic using the same method, but using an individual neural network (Inn). That is, the features of each image are obtained using the Inn, and a previously trained GMM and histogram (of validation _image_ anomaly scores) are used to label the images as off-topic or not. This is summarized in Algorithm. 3.

### Comparison with Related Work

There exists very little literature on the combination of GT algorithms with neural networks. The sole published work on this topic (to our knowledge) can be found in [38]. The neural networks in [38] use only binary outputs, while the neural networks proposed in our methods have quantitative outputs, and are trained to predict the _number of OIs_ in a given SFM. This enables usage of CS decoding algorithms. CS methods have better recovery guarantees than non-adaptive binary GT (see Appendix A.3). Non-adaptive pooling using a \(m\times n\) pooling matrix is implemented in [38] by separately running a Bpnn for each pool. In their method, the intermediate feature map (IFM) for an image needs to be re-computed for each pool that it takes part in, making it computationally inefficient. Due to this, the scheme in [38] is limited to using pooling matrices in which each image takes part in at most two pools. Such matrices can be at most \(1\)-disjunct (see Appendix A.1 for the definition), and hence guarantee of exact recovery via Comp is for only \(1\) OI per matrix (see [21, Prop. 2.1] and Appendix A.4 for an explanation). Thus their scheme is applicable for only very low prevalence rates (\(p\)) of OIs. In our implementation, an IFM for each image is computed only once, and is re-used for each pool that it takes part in. This enables usage of pooling matrices with \(3\) or more entries per column. This means that we can use matrices with high 'disjunctness' for group testing decoding [39] or those obeying restricted isometry property (RIP) of high order [10] for compressed sensing recovery (see Appendix A.1 for definitions of disjunctness and RIP). Due to this, our method is applicable for both low or high \(p\) values. Furthermore, there are no guarantees for binary group testing for recovery from noisy pool observations using matrices which have only two \(1\) entries per column. This is because if one test involving an item is incorrect but the other one is correct, there is no way to determine which of them is the incorrect one. Noise-tolerant recovery algorithms for binary GT exists for suitable matrices with \(3\) or more \(1\) entries per column. For example, NComp with a pooling matrix which has \(3\) tests per item and has the properties described in Appendix A.2, when testing in the presence of upto one defective item, can recover from an error in one test of that item by declaring it defective if two of the tests are positive, or non-defective if two of its tests are negative. Moreover, higher number of \(1\) entries per column implies better noise tolerance for CS algorithms for the matrices described in Appendix A.2. See Appendix A.5 for details.

Over and above these differences, we also extend binary group testing and compressed sensing to deep outlier detection as earlier described in Sec. 3.3, whereas the approach of [38] is limited to the classification setting. In the case of OIs with a single class, our test datasets also contain a much larger number of objectionable images (see details in Sec. 4), and these are mixed with non-OIs to form datasets of size \(1\)M or \(100\)K for a wide range of prevalence rates \(p\), so that each OI gets tested many times in combination with other OIs and different non-OIs. However in [38], prediction measures are presented only for a single dataset for the case when \(p=0.001\), with the number of unique OIs being only \(50\) and each OI being tested only once. When a single OI participates in multiple pools, there is an inherent noise resilience brought in. This is important as the neural network may not produce perfect classification.

## 4 Experiments

We present an extensive set of experimental results, first focusing on the classification case, and then on the outlier detection case.

### Image Moderation using Pooled Classification: Single Class for Objectionable Images

Here the objectionable images belong to a single underlying class, and the goal is to classify images as objectionable or not objectionable.

Tasks:We use the following two tasks for evaluation: (_i_) firearms classification using the Internet Movie Firearms Database (IMFDB) [2], a popular dataset used for firearms classification [12, 17]; and (_ii_) Knife classification using the Knives dataset [28], a dataset of CCTV images, labelled with the presence or absence of a handheld knife. In (_i_), the firearm images from IMFDB are mixed with non-firearm images from ImageNet-1K [42] as IMFDB contains only firearm images. The firearms and the knife images are respectively considered as objectionable images (OIs) in
the two tasks. Here below, we provide details of the number of images in the training/validation/test splits in each dataset.

Individual Dataset Splits:For the firearm classification task, we use firearm images from IMFDB [2] and Imagenet-1K [42] as the OI class, with \(9\),\(458\) and \(3\),\(617\) (total \(13\),\(075\)) images in the training set from the two datasets respectively. Additionally, 667 firearm images from IMFDB were used in the validation set, and 931 images were used in the test set. The validation and test images were manually cleaned to remove images which did not contain a firearm, or images in which the firearm was not the primary object of interest. For the non-OI images, we used images from 976 classes in ImageNet-1K [42], which did not belong to a firearm class - \(1\),\(200\),\(764\) in the training set, \(50\),\(000\) in the validation set, and \(48\),\(800\) in the test set (leaving out weapon images from ImageNet-1K such as 'tank', 'holster', 'camon', etc., following [38]). During training of the Inn, the classes were balanced by selecting all \(13\),\(075\) OIs and the same number of random non-OIs for training at each epoch. Classes were balanced in the validation split as well, by using all \(50\),\(000\) non-OIs and randomly sampling with replacement \(50\),\(000\) OIs.

The Knives dataset [28] used for the knife classification task consists of 12,899 images of which 3559 are knife images and 9340 are non-knife images. Some images were taken indoors, while some were taken through a car window in the street. We randomly selected 2159 knife and 6140 non-knife images for training, 700 knife and 1600 non-knife images for validation, and 700 knife and 1600 non-knife images for testing. During training of the individual neural network, classes were balanced by sampling (without replacement) 2159 random non-knife images at each epoch. The validation set was also balanced by sampling (with replacement) 1600 random knife images. See Fig. 1 for examples of images in IMFDB, and Fig. 2 for examples of images from the Knives dataset.

Pooled Dataset Splits:For firearms classification, during training of the Qpnn, at each epoch, \(6\),\(248\) pools of size \(r=8\) were created, each pool containing \(k\) randomly selected OIs and \(8-k\) randomly selected non-OIs, for each \(k\) in \(\{0\dots 8\}\). Of these, \(40\%\) pools contained no OIs, \(24\%\) contained 1 OI, \(12\%\) contained 2 OIs, \(6\%\) each containing 3 and 4 OIs, and \(3\%\) each contained 5 through 8 OIs. Such a distribution was chosen because OIs are assumed to have low prevalence rate in the test dataset. Hence greater accuracy is desired on pools with low number of OIs - however, enough instances of pools with high number of OIs must be seen during training for good accuracy. The pooled validation set used for selection of neural network weights contained \(63\),\(325\) pools of size \(8\), created with the same method as the pooled training set. For testing, we created \(9\) mixtures of the test data split of the individual dataset, each containing \(N=1\) Million images, with each mixture containing \(pN\) OIs, with the prevalence rate \(p\in\{0.001,0.002,0.005,0.01,0.02,0.03,0.04,0.05,0.1\}\).

For knife classification, 12496 pools of size 8 were created for training following the same distribution of OIs as for the firearms classification case. The pooled validation set used for selection of neural network weights contained 2873 pools of size 8, created with the same method as the pooled training set. The pooled test dataset consisted of 9 mixtures of 100K images, created with the same method as for the firearms classification task.

Data Transformations:Images were padded with zeros to equalize their height and width, and resized to \(224\times 224\), during both training and testing. We also added a random horizontal flip during training. For the pooled datasets, a random rotation rotation between \([-30^{\circ},30^{\circ}]\) was applied to each training image. This rotation was also applied to test data for the knife classification task.

Training:We train all our networks for 90 epochs using stochastic gradient descent with learning rate \(0.001\) and momentum \(0.9\), using cross-entropy loss and weight decay of \(0.0001\). Model weights are checkpointed after every epoch. The best model weights are selected from these \(90\) checkpoints using classification accuracy on the validation set. For the firearms classification task, a weighted accuracy is used for selection of the best checkpoint of the pooled neural networks, viz \(\texttt{Acc}_{\text{weighted}}=\sum_{k=0}^{8}\texttt{Binom}(8,p,k)\texttt{Acc}_ {k}\), where \(\texttt{Acc}_{k}\) is the classification accuracy on pools with

Figure 2: Data Samples from Knives dataset [28]. Top Row: Images containing a knife, Bottom Row: Images not containing a knife.
\(k\) OIs in them, and \(\mathtt{Binom}(8,p,k)\) is the probability of having \(k\) OIs in a pool of size \(8\) if the prevalence rate of OIs is \(p\). This accounts for the fact that accuracy on pools with higher number of OIs is more important for high values of \(p\), while pools with \(0\) or \(1\) OI are more important for low values of \(p\).

Confusion Matrix:As can be seen in Fig. 3, if \(g\) is the ground truth number of OIs, the predictions of the Qmpnn lie in the interval \([\text{max}(0,g-1),\text{min}(g+1,r)]\) with high probability. This is presented as a confusion matrix of size \((r+1)\times(r+1)\) of the ground truth number of OIs in a pool versus the predicted number. In Fig. 3, we have \(r=8\).

Neural Network Implementation:We use the official PyTorch implementation of ResNeXt-101 (\(32\times 8d\)) [50][4], a highly competitive architecture which has produced compelling results in many image classification tasks, with weights pre-trained on ImageNet-1K. The last linear layer of this network has \(1000\) outputs by default. Recall the discussion in Sec. 3.1 regarding the architectures of the Inn, Qmpnn, Bmpnn, Qpmnn, and Bpmn. For Qpmn/Qmpnn with pool size \(r=8\), we replace the last linear layer to have only 9 outputs. For the Inn of Bpmn/Bmpnn, we replace the last linear layer to have only two outputs. Each image is passed through first three stages of the ResNeXt-101 to create IFMs, which are then combined to create SFMs for the pools in the Qmpnn/Qpmn/Bpmn. The remaining two stages of the ResNeXt-101 process only the SFMs in Qmpnn/Qpmn/Bmpnn/Bpmn. This configuration is exactly the same as Design 2 in [38, Sec. II.A]. In initial experiments, we also tried using Design 3 of [38], but the accuracy of this configuration was not good on the IMFDB dataset. The networks are trained using the method specified in Sec. 3.1. Details of training the individual and pooled neural networks have been given earlier.

Pooling Matrix:We use a \(50\times 100\) balanced pooling matrix \(\mathbf{\Phi}\) with the construction as described in Appendix A.2, with \(r=8\) ones per row and \(c=4\) ones per column. That is, \(50\) SFMs are created from \(100\) IFMs, with each SFM being created from \(8\) different IFMs, and each IFM contributing to \(4\) different SFMs.

Prediction:We randomly sampled \(pN\) OIs and \((1-p)N\) non-OIs from the test split and shuffled these \(N\) images to create our test datasets. Here, \(p\in\{0.001,0.002,0.005,0.01,0.02,0.03,0.04,0.05,0.1\}\) is the prevalence rate of OIs, and \(N\) is 1M for IMFDB and 100K for Knives. Each test set is divided into chunks of size \(100\) each and passed to the Qmpnn to retrieve the prediction vector \(\mathbf{y}\) of each chunk. As can be seen in Fig 3, if \(g\) is the ground truth number of OIs, the predictions lie in the interval \([\text{max}(0,g-1),\text{min}(g+1,r)]\) with high probability. These pool-level predictions are decoded using the algorithms Classo and Mip. We compare them with the baselines of Comp, Dorfman Testing with pool-size 8 (Dorfman-8, same as Design 2 + Algorithm 1 of [38]), NComp with \(t=2\) (NComp-2) and Individual Testing (Individual) on images of the same size. The numerical comparison was based on the following two performance measures:

1. _Sensitivity_ (also called _Recall_ or True Positive rate) \(\triangleq\#\text{correctly detected OIs / }\#\text{actual OIs}\)
2. _Specificity_ (also called True Negative Rate) \(\triangleq\#\text{correctly detected non-OIs / }\#\text{actual non-OIs}\).

For both the measures, larger values indicate better performance.

Figure 3: Qmpnn Confusion Matrix on IMFDB Pooled Validation Data: true #OIs (rows) versus predicted #OIs (columns)
Hyperparameter Selection:We created mixtures of images from the validation split of the same sizes and the same prevalence rates as for the test split. For a given prevalence rate \(p\), grid search was performed on the corresponding validation split mixture with the same value of \(p\) to determine the optimum value of \(\lambda\) and \(\tau\) for CLasso and \(\lambda\) for Mip (see Sec. 3.2). The hyperparameter values which maximized the product of sensitivity and specificity on the validation mixture were chosen.

Discussion on Results:Fig. 4 shows the sensitivity and specificity of each of these algorithms for different values of \(p\), for the two classifications tasks (\(i\)) and (\(ii\)) defined earlier. We see that for IMFDB and Knives, the CS/GT methods remain competitive with Individual. In general, CLasso and Mip have _much higher sensitivity_ than Comp and Dorfman-8. This is because if a pool gets falsely classified as negative (i.e. containing no OIs), then all OIs in that pool get classified as negative by Comp and Dorfman. However, CLasso and Mip can recover from such errors as they inherently consider the results of other pools that the OI takes part in. Such false negative pools are more common at lower \(p\) values, where most positive pools have only a single OI, which may remain undetected by the pooled neural network (see also the confusion matrix of the pooled neural network in Fig 3). NComp-2 improves upon the sensitivity of Comp and Dorfman-8 by allowing for one false negative pool for each OI. However, it incurs a corresponding drop in specificity because non-OIs which take part in three positive pools incorrectly get classified as OI. When \(p\) is high, it is likely that such non-OIs are common, and hence the steep drop in specificity makes NComp-2 unviable. At high prevalence rates of OIs, it is common for a non-OI to test positive in all of its pools. Since Comp uses only such binary information, it incorrectly declares all such images as OIs, and we observe a sharp decline in specificity. However, CLasso and Mip use the quantitative information of the number of OIs in the pools, and can eliminate such false positives. For example, if it is known that a positive pool has only two OIs, then in general only two images from that pool will be declared as being an OI, whereas Comp may declare anywhere from \(1\) through \(8\) positives for such a pool. Among the CS algorithms, CLasso has better sensitivity, while Mip has better specificity.

Comparison with Downsampling:In Fig. 4, we also compare our method to individual testing of images downsampled by a factor of \(4\) (size \(112\times 112\)) (referred to in Fig. 4 as Downsample) for the firearms task. We find that downsampling lowers the specificity of prediction of individual testing, and both Mip and CLasso have better

Figure 4: Performance of Objectionable Image Moderation via Pooled Classification methods for various prevalence rates (\(p\)), averaged over 1M images for IMFDB and 100K images for Knives. Top Row: Sensitivity on IMFDB (left), Knives (middle), and IMFDB-Downsampled (right). Bottom Row: Specificity on IMFDB (left), Knives (middle), and IMFDB-Downsampled (right). Note: Y-axis for Specificity charts is broken up into two ranges in order to show all the values more clearly.
specificity for both IMFDB and Knives.

Computational Cost:Fig. 5 compares the average number of floating point operations used per image processed by the Qmpnn against those used for Dorfman-8 and Individual for different prevalence rates on IMFDB. We used the Python package _pftflops_[46] for estimation of FLOPs used by the neural networks. We see that the Qmpnn with \(50\times 100\) pooling matrix uses only around \(61\%\) of the computation of Individual. While Dorfman-8 uses less computation for small \(p\), the Qmpnn is significantly more efficient for \(p>0.05\).

Wall-clock Times:The end-to-end wall-clock times for Qmpnn with Mip decoding on IMFDB are presented for a range of prevalence rates in Table 2. We see that this is significantly faster than individual testing of the images for all \(p\), and for \(p\geq 0.04\) than Dorfman-8.

Combining Pooling with Downsampling:We verify whether downsampling may be combined with GT and CS methods for further reduction in computation cost without negatively affecting the performance. Fig. 4 (sub-figures labelled IMFDB-Downsampled, rightmost column, top and bottom rows) shows the performance of non-adaptive GT and CS methods on IMFDB images downsampled by a factor of \(4\) to \(112\times 112\). We note that while all the algorithms observe a drop in sensitivity, it may be within an acceptable range depending on the particular use-case, especially for CLasso. Specificity also drops, but less severely. CLasso and Mip present the best balance of specificity and sensitivity across the entire range of \(p\).

Multiple Objectionable Elements in the _Same Image:_We created \(100\) random pools containing one OI (firearm image) each, but where _each OI depicted two firearms_. Out of \(100\), the Qrnn correctly reported \(97\) times that the pool contained only one OI, and incorrectly reported two OIs \(3\) times. We conjecture that the Qrnn detects unnatural edges between firearms in the SFM, due to which it does not get confused by a single image containing multiple firearms.

\begin{table}
\begin{tabular}{|c|c|c|c|} \hline \(p\) & **Individual** & **Dorfman-8 [38]** & **Qmpnn + Mip** \\ \hline
0.001 & & 2080.6 & 3003.5 \\ \hline
0.01 & & 2352.7 & 2992.4 \\ \hline
0.02 & & 2668.6 & 3007.9 \\ \hline
0.03 & & 2924.7 & 2991.0 \\ \hline
0.04 & & 3152.2 & 2988.1 \\ \hline
0.05 & & 3403.6 & 2983.3 \\ \hline
0.1 & & 4315.0 & 2984.4 \\ \hline \end{tabular}
\end{table}
Table 2: End-to-end wall-clock times (secs), for processing 1M images of IMFDB+ImageNet with one NVIDIA GeForce RTX 2080 Ti GPU (11GB RAM) + one AMD 12-Core CPU, 64GB RAM. Batch-size chosen to fill GPU RAM.

Figure 5: Image Moderation cost per image in giga floating point operations (GFLOPs). Cost for running non-adaptive or individual methods is the same for classification and outlier detection. Cost for Dorfman-8 averaged over 1M images for IMFDB and 100K images for Knives. Cost for Dorfman-8-OD (see Sec. 4.2, paragraph titled ’Prediction’) averaged over 100K images for IMFDB and Cars.
### Off-topic Image Moderation using Pooled Outlier Detection

Here, the on-topic images are from a single underlying class and off-topic images may be from classes not seen during training. The goal is to detect such off-topic images, which do not belong to the underlying class. We do this by treating this as an outlier detection task, where the on-topic images are considered 'normal' and off-topic images are considered to be outliers.

Tasks:We consider two off-topic image moderation tasks, wherein the on-topic images are (_i_) firearm images from IMFDB used in Sec. 4.1, and (_ii_) car images from the Stanford Cars Dataset [37]. During training, we use non-firearm or non-car images from ImageNet-1K as off-topic images from known classes for the two tasks, respectively. During training, we use images from some 182 non-firearm or 179 non-car random classes which are in ImageNet-21K [18, 41] but not in ImageNet-1K. The off-topic image classes chosen for testing are not present in the training datasets.

Individual Dataset Splits:The firearm images in training, validation and test splits of IMFDB as described in Sec. 4.1 are taken to be on-topic images for the respective splits for the off-topic image moderation task. From the 976 non-firearm classes of ImageNet-1K in Sec. 4.1, we randomly sample \(10{,}000\) and \(1{,}000\) images and add them to the training and validation split, respectively, as off-topic images. For testing, we choose \(1{,}000\) images from \(182\) random non-firearm classes of ImageNet-21K as off-topic images.

For the Cars dataset, we take 8041 cars images for testing, 2144 cars images for validation, and 6000 cars images for training from the Stanford cars dataset as on-topic images. The \(1{,}000\) off-topic images for testing come from 179 non-car classes of ImageNet-21K, whereas for training and validation, we sample 10000 and 1000 images from 955 non-car classes of Imagenet-1K. We created 9 test sample sets (one per prevalence rate) of the test data split, each containing 100K images, using the same procedure and the same prevalence rates \(p\) as in Sec. 4.1. At each epoch of Inn training, classes in the training split were balanced by using all \(10{,}000\) off-topic images from known classes and randomly sampling (with replacement) an equal number of on-topic images. The validation split classes were not balanced since the imbalance in class proportions was not too much.

Pooled Dataset Splits:The pooled dataset training split was created using the same procedure as in Sec. 4.1, with the same pool size (i.e. 8), number of pools, and distribution of pools with different number of off-topic images in them. The pooled dataset validation split had \(625\) pools and was also created using the same procedure.

Neural Network, Data Transformation, Training:We use the same neural network (ResNeXt-101 [4, 50]) and train an Inn and a Qpnn using the same procedure as for the classification case (Sec. 4.1 and Sec. 3.1) on the IMFDB and Cars datasets. The data transformation used was the same as for the classification case, except that random rotation transformations were also applied to the images during testing to create more artificial edges in the SFMs and aid in detection of outliers in a pool.

Figure 6: Histogram method Confusion Matrix on IMFDB Pooled Validation Data: true #OIs (rows) versus predicted #OIs (columns)
GMM and Histogram Creation:Recall the steps for GMM fitting and creation of histograms of anomaly scores in Sec. 3.3. We created \(M_{\text{IMFDB}}=40850\) and \(M_{\text{Cars}}=18750\) pools respectively from the training splits of IMFDB and Cars datasets and obtained their feature vectors by passing them to the trained ResNeXt-101 Qpnn. For each dataset, we fit a GMM on these feature vectors. The optimal number of clusters in the GMM for the pooled case was 30 and 6 respectively for the IMFDB and Cars dataset, and 5 and 1 respectively for the individual case. For computing the anomaly scores histograms for each dataset, a total of \(N=100K\) pools were created from the validation split, each of size \(r=8\) and maximum number of outliers \(t=5\) (roughly 16666 pools for each pool label). We capped the number of outliers at \(5\) because for small prevalence rate \(p\) ranging between 0.001 and 0.1, having more than 5 outlier images in a pool of \(8\) is a very low probability event. For each dataset, we passed these pools to the trained Qpnn to obtain pool feature vectors. We used the earlier GMM to obtain their anomaly scores, and computed the anomaly score histogram, with \(Q=500\) bins. Recall from Sec. 3.3 and Algorithm 3 that the same histogram method can be used for testing individual images as well. For creating the histogram for testing individual images, we used 5000 off-topic and 5000 on-topic images, and used \(Q=500\) bins.
Hyperparameter Selection:The hyperparameters for CLasso-OD were chosen in exactly the same manner as for the classification case (Sec. 4.1).

Discussion on Results:Fig. 7 shows the sensitivity and specificity of each of these algorithms for different values of \(p\), for the two off-topic image detection tasks defined earlier. We see that for both IMFDB and Cars dataset, the CS/GT methods for oulier detection remain competitive with Individual. We observe that CLasso-OD has higher sensitivity than Comp-OD for the entire range of prevalence rates considered and higher than Dorfman-8-OD for \(p\leq 0.01\). The reason for this has been discussed in Sec. 4.1: when a pool gets _falsely_ classified as negative (i.e., containing no outlier image), then all outlier images in that pool get classified as negative by Comp-OD and Dorfman-8-OD. In the higher \(p\) regions, Dorfman-8-OD starts to perform better than CLasso-OD. This is because, as we can see in Fig. 6, the prediction model gets confused for pools having \(\geq 2\) outlier images. At high prevalence rates of off-topic images, it is common for an on-topic image to test positive in all of its pools. As discussed in Sec. 4.1, Comp-OD uses only such binary information and declares incorrectly all such images as off-topic, so we observe a sharp decline in specificity. However, CLasso-OD uses the quantitative information of the number of off-topic images in the pools, and can eliminate such false positives.

Comparison with Downsampling:In Fig. 7, we also compare our method to individual testing of images downsampled by a factor of \(4\) (size \(112\times 112\)) (referred to in Fig. 7 as Downsample-OD) for the firearms task. We find that downsampling lowers the specificity of prediction and hence both CLasso-OD and Dorfman-8-OD show better specificity than individual testing of downsampled images.

Computational Cost:The computational cost in terms of number of floating point operations (FLOPs) are presented in Fig. 5. Since the same neural network as in the classification case has been used, the amount of computation for each image for pooled outlier detection using CS/non-adaptive GT methods is the same. Some additional computation is needed in the GMM related steps, but it is very small (by a factor of 100) compared to computations involving the neural network. For Dorfman-8-OD, the amount of computation needed is slightly higher than for Dorfman-8. This is because in case of pooled outlier detection, \(11\%\) of negative pools falsely test as positive, as compared to only \(2\%\) for pooled classification (see the top-left entries in the confusion matrices presented in Fig. 6 and Fig. 3). However, we see that the computation costs for both adaptive and non-adaptive pooled outlier detection methods are well below those of individual testing.

Wall-clock Times:The end-to-end wall-clock times for pooled outlier detection with CLasso decoding and using Dorfman-8-OD on the Cars Dataset for 100K images are presented for a range of prevalence rates in Table 3. We see that both CLasso-OD and Dorfman-8-OD are significantly faster than individual testing of the images for all \(p\). CLasso-OD is also faster than Dorfman-8-OD for \(p\geq 0.02\).

Combining Pooling with Downsampling:Similar to Sec. 4.1, we performed experiments to see whether downsampling can be combined with GT and CS methods for further reduction in computation cost without negatively affecting the performance. We show the performance of our pooled outlier detection methods on IMFDB images downsampled by a factor of \(4\) to \(112\times 112\) in Fig. 7 (sub-figures labelled IMFDB-Downsampled, rightmost column, top and bottom row). We again note that while all the algorithms observe some drop in sensitivity, it is within an acceptable range. The specificity also drops, but to an even smaller extent.

\begin{table}
\begin{tabular}{|c|c|c|c|} \hline \(p\) & **Individual-OD** & **Dorfman-8-OD** & **Classo-OD** \\ \hline
0.001 & 430.87 & 253.6 & 302.2 \\ \hline
0.01 & 437.5 & 281.6 & 305.6 \\ \hline
0.02 & 436.9 & 309.5 & 303.3 \\ \hline
0.03 & 437.3 & 332.9 & 304.1 \\ \hline
0.04 & 437.5 & 356.9 & 303.4 \\ \hline
0.05 & 436.7 & 376.0 & 303.2 \\ \hline
0.1 & 436.5 & 466.3 & 303.4 \\ \hline \end{tabular}
\end{table}
Table 3: End-to-end wall-clock times (secs), for processing 100k images of Cars+ImageNet with one NVIDIA GeForce RTX 2080 Ti GPU (11GB RAM) + one AMD 12-Core CPU, 64GB RAM. Batch-size chosen to fill GPU RAM.
Conclusion and Future Work

We presented a novel CS based approach for efficient automated image moderation, achieving significant reduction in computational cost for image moderation using deep neural networks. We also presented a method for pooled deep outlier detection for off-topic image moderation, bringing for the first time CS and GT methods to outlier detection. Because we output the number of OIs for each pool, recovering the original OIs is also a quantitative group testing (QGT) [43, 23] problem. Hence QGT algorithms (eg: Algorithms 1 and 2 from [23]) may also be used instead of CS for decoding within our framework. We leave an exploration of using QGT algorithms for image moderation as future work. In this work, we assumed that the errors in the different elements of \(\mathbf{y}\) are independent of each other and the underlying \(\mathbf{x}\). Though this produced good results, using a more sophisticated noise model is an avenue for future work. Our approach reduces the number of tests and is orthogonal to approaches such as network pruning or weights quantization which reduce the complexity of each test. In future, we could combine these two approaches, just as we (already) explored the combination of pooled testing and image downsampling.

## Appendix A Appendix

### Properties of Good Sensing Matrices

In a \(k\)**-disjunct pooling matrix**, the support of any column is not a subset of the union of supports of any \(k\) other columns. In noiseless binary group testing, Comp can identify upto \(k\) defectives exactly if the pooling matrix is \(k\)-disjunct [39, Sec 2.2].

**Mutual Coherence** of a matrix is the maximum value of the dot product of any of its two columns. Sensing matrices with low mutual coherence are preferred for compressed sensing as they allow for reduction of the upper bounds on recovery errors [47, Theorem 1].

The \(1\)**-norm Restricted Isometry Property (RIP-1)** of order \(2k\) is a sufficient condition on the sensing matrix \(\mathbf{\Phi}\) for recovery of \(k\)-sparse \(\mathbf{x}\) from noisy \(\mathbf{y}\) via LASSO [10]. A pooling matrix \(\mathbf{\Phi}\) satisfies RIP-1 of order \(2k\) if it holds for some constants \(2k\) and \(\delta\) that \(\|\mathbf{x}\|_{1}\leq\|\mathbf{\Phi}\mathbf{x}\|_{1}\leq(1+\delta)\|\mathbf{x}\|_{1}\) for all \(2k\)-sparse vectors \(\mathbf{x}\).

### Choice of Pooling Matrix \(\mathbf{\Phi}\)

Randomly generated matrices from zero-mean Gaussian or Rademacher distributions have been popular in CS because they are known to obey the Restricted Isometry Property (RIP) with high probability [9], which is a well-known sufficient condition to guarantee accurate recovery [14]. RIP-obeying matrices also satisfy condition \(\mathbb{C}2\) mentioned in Sec. 1 of the main paper. Despite this, such matrices are not suitable for our image moderation application, as they will lead to all \(n\) images contributing to every SFM - that too in unequal or both positive and negative amounts - and complicate the job of the Qmpnn that predicts \(\mathbf{y}\). Random Bernoulli (\(\{0,1\}\)) matrices have been known to allow for very good recovery [34] due to their favorable null-space properties. But randomly generated matrices will contain different number of ones in each row, due to which each pool would contain contributions from a different number of images. Instead, we use binary matrices which are constrained to have an equal number of ones in each of the \(n\) columns, denoted by \(c\) (i.e. 'column weight' \(c\)), and an equal number of ones in each of the \(m\) rows, denoted by \(r\) (i.e. 'row weight' \(r\)). This implies that \(nc=mr\). Such a construction ensures that the Qmpnn must produce outputs constrained to lie in \(\{0,1,...,r\}\), and also ensures that each of the \(n\) images contributes to at least one pool (actually to exactly \(c\) different pools, to be precise). These matrices can be made very sparse (\(r\ll n\)), which ensures that noise in the output of the Qmpnn can be controlled. We put an additional constraint, that the dot product of any two rows must be at most \(1\), and similarly the dot product of any two columns must be at most \(1\). It can be shown that such matrices are \((c-1)\)-disjunct, obey the 'RIP-1' property of order \(2c\)[24, Sec. III.F], and have low mutual coherence [27], which makes them beneficial for GT as well as CS based recovery. These properties are defined in Sec. A.1.

### Recovery Guarantees for CS and binary GT

Quantitative group testing (see Sec. 2), which is closely related to CS, has some conceptual advantages over binary group testing, as it uses more information inherently. We summarize arguments from [39, Sec. 2.1], [23, Sec. 1.1] regarding this: Consider binary group testing with \(m\) pools from \(n\) items with \(k\) defectives. The total number of outputs is \(2^{m}\). The total number of ways in which up to \(k\) defective items can be chosen from \(n\) is \(\sum_{i=0}^{k}C(n,i)\). We must have \(2^{m}\geq\sum_{i=0}^{k}C(n,i)\), which produces \(m\geq k\log(n/k)\). If we instead consider quantitative group testing, then the output of each test is an integer in \(\{0,1,...,k\}\). The total number of outputs would thus be \((k+1)^{m}\). Thus \((k+1)^{m}\geq\sum_{i=0}^{k}C(n,i)\), which produces \(m\geq\frac{k\log(n/k)}{\log(k+1)}\). Thus, the lower bound on the required number of tests is smaller in the case of quantitative group testing by a factor of \(\log(k+1)\). Moreover, work in [8] argues
that in the linear regime where \(k=O(n)\) (even if \(k\ll n\)), individual testing is the optimal scheme for binary non-adaptive group testing. This is stated in Theorem 1 of [8] which argues that if the number of tests is less than \(n\), then the error probability is bounded away from 0. On the other hand CS recovery with binary matrices is possible with \(m=O(k\log(n/k))\) measurements [10, Theorem 9].

### Upper bound on disjunctness of column-regular matrices

We explain in this section that matrices with column weight \(k\) (i.e., with \(k\) ones per column, equivalent with each image participating in \(k\) pools) which have strictly fewer rows than columns cannot be \(k\)-disjunct. The work in [21, Prop. 2.1] gives an upper bound on the cardinality of a uniform \(r\)-cover-free family of sets. They consider the power set of a set \(X\) of \(n\) elements. A \(k\)-uniform family of sets is any set of subsets of \(X\) containing exactly \(k\) elements. Let \(\mathcal{F}=\{S_{1},\ldots,S_{K}\}\) be a \(k\)-uniform family of sets of cardinality \(K\). If \(\mathcal{F}\) is \(r\)-cover-free, it means that no element of \(\mathcal{F}\) is a subset of the union of any \(r\) other sets in \(\mathcal{F}\). The work in [21, Prop. 2.1] gives the following bound on the cardinality of \(F\):

\[K\leq\frac{\binom{n}{t}}{\binom{k-1}{t-1}}, \tag{12}\]

where \(t=\lceil\frac{k}{r}\rceil\).

We can construct a \(n\times K\) pooling matrix \(\mathbf{\Phi}\) from \(\mathcal{F}\), where each column is a \(0/1\)-binary vector with column weight \(k\), and \(\mathbf{\Phi}_{ij}=1\) indicating that the element \(i\) is in the set \(S_{j}\). Recall from Appendix A.1 that in an \(r\)-disjunct matrix, the support of any column is not a subset of the union of supports of any \(r\) other columns. From the definition of disjunctness and \(r\)-cover-free families, if the matrix \(\mathbf{\Phi}\) is to be \(r\)-disjunct, then the family of sets \(\mathcal{F}\) must be \(r\)-cover free. Moreover, if \(r=k\), then \(t=1\), and \(K\leq\frac{n}{k-1}\). Hence, matrices with column weight \(k\) and fewer rows than columns i.e. \(n<K\) cannot be \(k\)-disjunct.

For the case from Sec. 3.4 where column weight can be _upto_\(k=2\), we note that for any column with column weight \(1\), the corresponding row in which it has a \(1\) entry also has a row weight equal to \(1\), otherwise the matrix cannot be \(2\)-disjunct. Thus, we can remove such rows and columns from the matrix, and the reduced matrix will also be \(2\)-disjunct and will have column weight equal to \(2\) for all columns. From the above result, the number of columns in this reduced matrix must be less than or equal to the number of rows. Since we removed an equal number of rows and columns from the original matrix, the original matrix also has number of columns less than or equal to the number of rows, and hence cannot be used for achieving a reduction in number of tests using group testing.

### Noise-tolerance of balanced binary matrices with row and column dot product at most 1

The work in [24, Sec. III.F.4] shows that such matrices with column weight \(c\) are adjacency matrices of \((k,\epsilon)\)-unbalanced expander graphs, and consequently [10, Theorem 1] have RIP-1 for any \(k<2c+1\), with \(\epsilon=\frac{k-1}{2c}\), and \(0\leq\epsilon<1\). Robust recovery guarantees using the RIP-1 for such adjacency matrices exist - for example, [32, Theorem 6.1] states that the \(\ell_{1}\)-norm of the recovery error of [32, Algorithm 1] is upper-bounded by \(\frac{7-4\epsilon}{1-2\epsilon}\eta\), where \(\eta\) is the \(\ell_{1}\)-norm of the noise in measurements. For a fixed magnitude of noise in the measurements, the amount of error in the recovered vector depends on the value of \(\epsilon\), with smaller values being better. For a fixed \(k\), \(\epsilon\) can be made smaller by having a larger value of \(c\), the column weight of the matrix. Hence matrices with higher values of the column weight i.e. ones in which each item takes part in a larger number of pools are more robust to noise for CS recovery.
