{'fraction_non_alphanumeric': 0.02702176347436584, 'fraction_numerical': 0.00759530649009202, 'mean_word_length': 4.900603274921, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Feature-based Attention in Convolutional Neural Networks

Convolutional neural networks (CNNs) have proven effective for image processing tasks, such as object recognition and classification. Recently, CNNs have been enhanced with concepts of attention, similar to those found in biology. Much of this work on attention has focused on effective serial spatial processing. In this paper, I introduce a simple procedure for applying feature-based attention (FBA) to CNNs and compare multiple implementation options. FBA is a top-down signal applied globally to an input image which aides in detecting chosen objects in cluttered or noisy settings. The concept of FBA and the implementation details tested here were derived from what is known (and debated) about biological object- and feature-based attention. The implementations of FBA described here increase performance on challenging object detection tasks using a procedure that is simple, fast, and does not require additional iterative training. Furthermore, the comparisons performed here suggest that a proposed model of biological FBA (the"feature similarity gain model") is effective in increasing performance.


SUMMARY OF PREVIOUS WORK
Previous work with CNNs has incorporated ideas from biological vision to enhance processing, especially with regards to biological attention. Taking inspiration from biology is reasonable, as CNNs have many architectural elements in common with the ventral visual stream, and visualization techniques have shown that feature representations are similar at corresponding levels of the CNN and visual stream (Zeiler & Fergus, 2014). Here, a recap of previous attention approaches in CNNs is provided, and background on biological feature attention is given.

ATTENTION IN CNNS
A lot of work on attention in CNNs has focused on spatial attention. That is, performance is enhanced by processing small regions of the image in sequence (see Mnih et al. (2014) for their work and their summary of previous work), or allocating processing resources according to spatial saliency maps (Xu et al., 2015). Biologically speaking, these "hard" and "soft" forms of attention in the machine learning literature correspond to "overt" and "covert" spatial attention respectively. Overt attention occurs when an animal chooses to make a small eye movement, or saccade, to a region. Covert attention refers to the ability to increase visual information processing of a region without an eye movement. The challenge for machine learning when trying to use these forms of spatial attention is to effectively choose which regions of the image on which to focus attention.
Feature-based attention is a kind of covert attention in that it does not require eye movements. However, it serves to enhance certain features of an image, rather than certain locations. Some work in CNNs has approximated this style of attention. Most prominently, the work of Stollenga et al. (2014) finds a policy for dynamically weighting feature maps in a Maxout network. While powerful, this technique requires iterative training and many feedforward-feedback loops at runtime. The implementation of FBA here is applied to a specific object category in order to enhance detection of that category, and only requires one feedforward pass. Attention has been found to increase performance accuracy and decrease reaction time on a variety of cognitive tasks. The neural mechanisms underlying covert attention are a hot topic of research in neuroscience. Much of this work comes from non-human primate studies, wherein neural activity is recorded from various areas in the ventral visual stream as visual stimuli are presented to the animal. These studies have lead to the feature similarity gain model of attention (Treue & Trujillo, 1999). It states that when an animal is cued to attend to a certain visual feature, neurons that are selective to that feature increase their firing rate beyond the rate found without attention (Maunsell & Treue, 2006). In most studies, this increase is found to be a multiplicative effect. Furthermore, effects are stronger in later areas of the ventral stream (McAdams & Maunsell, 1999).
Some studies have shown that neurons that are selective to features other than those attended have their activity suppressed. This represents a bi-directional modulation of neural activity with attention. Some studies suggest changes in the positive direction are more prevalent, however (McAdams & Maunsell, 1999).
Two lines of results show that this attention is spatially global and feature specific: (1) FBA alters the activity of neurons selective to the attended feature at all spatial locations across both hemispheres (Cohen & Maunsell, 2011) and (2) In tasks with attention applied to one of two spatially overlapping stimuli, neural activity is biased toward the activity found when the attended feature is presented alone (Patzwahl & Treue, 2009).

FBA IMPLEMENTATION AND TESTING
Taking inspiration from biology, I've incorporated into a CNN the mechanisms used by neurons for attending to specific features or objects. This allows enhanced object detection. Different implementation details are described below and tested with a pre-trained CNN on two types of object detection tasks .

FBA PROCEDURE
FBA works by enhancing the features of an attended object category. This can be implemented in a pre-trained CNN by altering the network in a category-specific way. In order to determine how different feature maps should be altered for a given category, information about their average activity in response to that category is collected. When processing a new image with FBA, feature maps are altered to be biased in the direction of the average activity of the attended category.

DETERMINATION OF FEATURE PATTERNS
Category-specific feature patterns are created based on the average activity of feature maps when presented with images of a given category. Feature patterns are defined for each category and for each ReLU layer in the network (which in the network used here, shown in Figure 1, corresponds to layers 2,6,10,13,16,19,21. These layers are marked with red numbers that will be used to refer to them in further figures).
Activity of the k th feature map in layer l, in response to image n, is given as X lk (n), with X lk ∈ R h×w . This activity can be averaged over the two spatial dimensions to give a scalar value, r lk (n): where h and w are the height and width of the feature map, respectively, and x ij lk is the ij th element of X lk . (For the fully connected layers, which lack two-dimensional feature maps, r lk (n) = x lk (n), which is just the activity of an individual node). Thus, the k th element of the vector r l (n), is the spatially-averaged activity of the k th feature map in response to image n. Averaging these values over all images in the training set gives the vectorr l :  For the object detection task, the 1000-way softmax classifier normally used in the CNN is replaced by binary classifiers trained to determine if a given object category is present or absent. Category-specific feature-based attention can be applied at any of the ReLU layers, marked with the red numbers on the side. Filter details are given in the box. Special imagesets were made to test the object detection abilities of FBA. Array images (B) are composed of 4 ImageNet images on a 2x2 grid. Merged images (C) are two overlaid ImageNet images.
Next, feature patterns are defined for each layer, l, and object category, c. A feature pattern, given as f c l , is a vector with an entry for each feature map, which determines how that feature map is altered when attention is applied to category c. It is defined as: with N c representing the total number of training images from object category c. That is, an object category's feature pattern at a given layer is merely the average activity of the feature maps at that layer in response to images of that category, with the mean activity under all image categories subtracted and standard deviation divided. These feature patterns determine how the feature maps are modulated when attention is applied to a specific category.
At this point, a choice can be made about whether to set negative elements of these feature patterns to zero. As discussed above, evidence suggests that neurons may be modulated both positively and negatively by attention, but positive modulation may be stronger. Both rectification options are tested here.

OPTIONS FOR APPLICATION OF FBA AT RUNTIME
Once the feature patterns are generated, they are used to alter the network at runtime. Here again there are many implementation options.
First, the alteration can manifest as either an additive effect or a multiplicative one. That is, when attending to category c, a weighted version of the feature pattern for category c can be added before the rectified linear units: with I ij lk representing input to the ReLU coming from layer l − 1. Or, for the multiplicative effect, the slope of the rectified linear units can be multiplied by a weighted function of the feature pattern for category c: x ij lk = (1 + βf c lk )ReLU (I ij lk ) (5) Strength of the attention is varied via the weighting parameter, β. For the additive effect, β was varied from 4 to 24, and for the multiplicative effect β was varied from .2 to 1.2. These values were found to give a range of performances.
Combining the modulation options described in 4 and 5 with the rectification options discussed above, four implementation combinations are possible: Additive-Bidirectional, Additive-Positive, Multiplicative-Bidirectional, and Multiplicative-Positive.
Finally, attention does not need to be applied to all layers. As discussed above, the strongest effects of attention are found in later extrastriate visual areas. Thus, performance is measured here when attention is applied to different layers individually, and to combinations of layers.
In all cases, the modulation is applied in a spatially global way. That is, each ij position in a feature map receives the same modulation.

OBJECT DETECTION TESTS
To show how FBA can enhance object detection, two image sets were created which pose difficult problems for a standard CNN. These image sets are described below. In either case, the task of the network was to output a binary variable reporting whether or not a given object category was present in the image. For this, the softmax classifier is removed and the last layer of the network was fed into a binary classifier trained to detect the given category (results from SVM shown, though results are similar using regularized logistic regression). The test images are described here: 3.2.1 ARRAY IMAGESET Array images are each composed of four ImageNet images selected randomly from the available categories, arranged in a 2x2 grid (example in Figure 1). This type of "cluttered" image is reminiscent of those used in experiments on feature and spatial attention.

MERGED IMAGESET
Merged images are each composed of two ImageNet images superimposed on top of one another as a weighted linear sum of pixel values (example in Figure 1). This type of image is an analogue of the stimuli used in Patzwahl & Treue (2009). It offers a test of FBA's ability to "see" an object category when distracting features are overlapping. More generically, the overlaid image could simply be viewed as a form of structured noise.

NETWORK ARCHITECTURE AND PARAMETERS
The pre-trained network used for this work comes from Vedaldi & Lenc. Its architecture and details are shown in Figure 1. It contains 7 ReLU layers, and thus 7 possible locations of attention.
For each category, a binary classifier was trained on 150 category and 150 non-category normal images from ImageNet (results do not depend strongly on number of training images). Tests of performance shown here were on the same number of test images coming from the above test imagesets. Training images do not overlap with the images used to make the imagesets. Performance is determined by averaging over 20 folds of training on different subsets of training images. This distribution of performances allows for significance testing between different implementation options.

RESULTS
The array and merged imagesets prove challenging for the binary classifiers trained on normal images. As the inset in Figure 2 shows, the binary classification performance (averaged over all categories) is high on normal images (95.17%), but is lower for merged images (70.89%) and even lower for array images(59.29%). More standard methods of assessing CNNs also show this difficulty: top-5 error rate on merged images (calculated by accepting either of the two image categories in the merged image as correct) is 58.18%.
Applying FBA, however, increases the ability of the network to detect the attended object. Different implementation options provide different results. Results are also dependent on the category attended. Figures shown are of results from array images, but merged image results are qualitatively similar and shown in the Appendix. Array images were more challenging, and show larger increases in performance. Figure 2 shows the effect of different strengths (β) of attention when it is applied at different layers (the implementation options used here are multiplicative bi-directional effects, tested on array images). In many instances, increasing the strength of attention is beneficial to a point, and then becomes detrimental to performance. This can be shown by tracing the effect of increasing attention strength through a space of changing true and false negative rates, as seen in the right column of Figure 2B. In order for FBA to be effective, it should decrease false negatives without substantially increasing false positives. As can be seen, for most categories (shown in different colors), false-negative decrease rate outpaces false positive increase rate, up to a certain strength (increasing strength shown as increasing circle size). The left column of Figure 2B show ROC curves that result from varying strength. Again, increases in strength bring performance closer to that found on the normal images (asterisks), but only to a point. Notably, the effects of increasing strength are different for different layers. Earlier layers don't move the performance as much, even at high strengths, compared to later layers.

STRENGTH OF ATTENTION AFFECTS PERFORMANCE
For further analyses, the best performing strength at a given layer and category will be used.

APPLYING FBA TO LATER LAYERS PERFORMS BEST
As Figure 3A shows, the average increase in performance (in units of percentage points) with attention across categories varies based on the layer at which attention is applied. Looking at median performance, applying attention to later layers (specifically 5 and 6) has the best effect on perfor-

B.
A. Applying FBA to multiple layers at once (Figure (3B, half-strength was used when applied to multiple layers at once) appears to have only minor effects on performance compared to single layers.
Averaging over categories can make seeing the impact of applying attention to different layers difficult. In order to see this impact, a direct comparison was made. For each category, performance was directly compared across layers and the layer that led to the best performance was found. This was done for all four combinations of implementation options. As shown in Figure 4C, layer 5 consistently outperforms other layers.

BI-DIRECTIONAL MULTIPLICATIVE EFFECTS PERFORM BEST
In order to concretely determine which of the different implementation options performs best, a direct comparison was made, similar to the one described above for Figure 4C. That is, at each combination of category and layer, the four pairings of implementation options were compared and the best performing pairing was determined. Figure 4B shows histograms displaying the results of these comparisons. The combination of bi-directional and multiplicative effects clearly outperforms the other options.

B.
Figure 3: Increase in binary classification performance for different FBA implementation options at different single layers (A) and combinations of layers (B), as labeled on the X axes. The Y axis represents performance with attention minus performance without, resulting in a measure of the increase in performance in units of percentage points. Horizontal lines represent median performance increase across categories. Boxes are 25th and 75th percentiles and whiskers extend to the most extreme data points not considered outliers. Red crosses are outliers. The best mean performance increase for the single layer application is 12.49% (layer 5, multiplicative-bidirectional). The best mean performance increase for multiple layer application is 13.16% (layers 4-5, multiplicativepositive). Data shown here for array images, merged image data in Appenix Figure 5 4

.4 EFFECTS OF BI-DIRECTIONAL MODULATION ARE UNCLEAR
Breaking down these comparisons even further shows an interesting result ( Figure 4A).
Looking at all instances when multiplicative effects were used, it's clear that bi-directional modulation performs better than positive-only. However when looking at instances where additive effects are used, there is not a clear winner (or, in the case of merged image data (Appendix Figure 6), positive modulation is the winner). Thus, there appears to be a synergistic benefit from combining multiplicative effects and bi-directional modulation.
Under this investigation, the benefit of multiplicative effects remains clear. That is, looking at all instances when bi-directional modulation is used, it's clear that multiplicative effects perform better than additive, and the same is true when looking at positive-only modulation ( Figure 4A, top row).

Bi Pos
Multi Add

Add Multi
Bi Merged image data is in Appendix Figure 6 4.5 COMPLICATIONS While FBA does increase performance on binary object detection tasks, there are some complications. First, not all categories are affected equally. This is perhaps due to the style of training images used to make the feature patterns for each category. Images in categories that perform well, like schoolbus, tend to have the object centered, and from somewhat consistent angles. Thus, learned feature patterns for these categories strongly represent the object. Food images, such as bagel and burrito, tended to be cluttered and display the object in multiple different ways, weakening the ability of the feature patterns to capture the relevant traits.
Another difficulty comes from determining the best strength to use. Here, strength was treated as a free parameter and the best value in each instance was experimentally determined. Generally, the best strength to use will depend on the difficulty of the imagesets being evaluated. Biologically, the brain must have a way of setting the strength of the feedback connections that control attention.

CONCLUSION
The implementation of FBA presented here is a simple feedforward operation that does not require iterative training. It allows for the ability to train on normal, clear images and test on more challenging images. As such, it may serve as a means of generalizing the classification ability of a CNN. A nice feature of the FBA implementations described here is that even when little data (20 images for each category) is used to make the feature patterns, performance still increases substantially (Appendix Figure 7).
Although not tested here, FBA may also aid in fine discrimination tasks, which is another setting where attention is used by humans. The freedom to apply FBA at different layers may be especially useful for fine discrimination problems, as lower layers represent the finer, smaller features.
Aside from performance, this work further demonstrates the applicability of biological ideas to CNNs. And conversely, the ability to test out biological mechansims in CNNs. This work provides evidence that FBA applied as a multiplicative effect to later layers in the visual stream is an effective way to increase performance, more so than additive or lower layer effects. Thus, biology appears to be using the most effective option for increasing visual information processing under attention.

B.
Figure 5: Same as Figure 3, but for merged image data.

Bi Pos
Multi Add

Add Multi
Bi Pos Pos Bi Layer A. B. C.
Instances when given option outperformed alternatives Option Combinations Figure 6: Same as Figure 4, but for merged image data.