Back to paper library
Paper notesarXiv 2021Biomimetics 2023

DAN

Distracted on Purpose

Original paper

Distract Your Attention: Multi-head Cross Attention Network for Facial Expression Recognition

Paper authors

Zhengyao Wen · Wenzhong Lin · Tao Wang · Ge Xu

Publication
Biomimetics 2023Journal
First submitted to arXiv
arXiv:2109.07270
Cite this paper · BibTeX

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

@misc{faceanalysisdan2021,
  title = {{Distract Your Attention: Multi-head Cross Attention Network for Facial Expression Recognition}},
  author = {Zhengyao Wen and Wenzhong Lin and Tao Wang and Ge Xu},
  year = {2021},
  eprint = {2109.07270},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2109.07270}
}
On this page

Surprise and fear look a lot alike. Both have wide-open eyes and an open mouth, and the difference is in the details. In surprise the whole eyebrow lifts and the mouth falls open with the jaw; in fear the eyebrows lift while also drawing together, and the corners of the mouth stretch sideways. To tell them apart, you have to look at the eyebrows and the mouth at the same time.

A model that looks at only one place easily gets this wrong. The DAN authors drew heat maps for an expression model with a single attention head, and what lights up is usually a large patch around the mouth or nose; with the authors' four heads, each of the four maps lights up a different spot, and the eyes, the bridge of the nose, the mouth and the chin all have a head looking at them.

DAN (Distract your Attention Network) comes from Zhengyao Wen, Wenzhong Lin, Tao Wang and Ge Xu of Minjiang University in Fuzhou. The "distraction" in the name is meant literally. The authors require in the loss that the four attention heads differ from one another, forcing them to spread out to different places on the face, and then combine the four heads' results to classify. One more loss term pushes the features of different expressions farther apart.

The paper reports 89.70% on RAF-DB, 62.09% on AffectNet-8 and 65.69% on AffectNet-7, each the top of its table at the time. The arXiv version went through six revisions from September 2021 to May 2023, the last in sync with the journal version, and a few numbers changed along the way, which comes up later.

Defining the Problem

The exams and the scores

Facial expression recognition takes a cropped face and picks one of seven classes (surprise, fear, disgust, happiness, sadness, anger, neutral) or eight (adding contempt). DAN sits three exams.

  • RAF-DB: faces collected from the web and annotated by multiple voters, aligned to 100×100100\times100. The basic-expression subset has 12,271 training and 3,068 test images, reporting overall accuracy. The test set is very uneven, with 1,185 happiness images (38.6%) and only 74 for fear.
  • AffectNet: about 280,000 hand-annotated training images out of a million web pictures. The seven-class version is called AffectNet-7, and adding contempt gives AffectNet-8. Testing uses the official validation set, with 500 images per class, so overall accuracy equals the mean per-class accuracy.
  • SFEW 2.0: still frames taken from AFEW, a database of movie clips; seven classes, 958 training, 436 validation and 372 test images, a very small set.

Classes too much alike

In general image classification, cats and trucks have wildly different features. Expression classes all share the same face, differing only in a few muscles, so their features naturally crowd together.

Face recognition ran into a similar problem long ago, and the common fix is center loss. It keeps a center for each class and pulls each image's feature toward the center of its own class, packing each class tightly. Expression recognition has plenty of variants too, such as Island loss, DDA loss, and DACL's attention version. The authors point out two drawbacks. These variants mostly need extra parameters or computation; and center loss itself only packs each class tightly, without requiring different class centers to stay apart.

One attention head isn't enough

The second observation is that an expression shows up in several places on the face at once. A single attention module produces only one weight map, which usually lands on one fairly large region.

Original Figure 1: four rows of faces, five heat maps per row, with red marking the strongest attention. The left column is DACL with a single attention head, mostly lighting up a large patch around the mouth or nose. The four columns to the right of the dashed line are DAN's four heads, each lighting up a different place. The first row lights up, in order, the right eye, nose to mouth, the left eye and forehead, and mouth to chin; the second row the mouth, between the eyes, the mouth and chin, and above the bridge of the nose; the third row both eyes, the mouth, the forehead and the chin; the fourth row the right eye, the mouth, the left side of the forehead and the chin.
Original Figure 1, Wen et al., from PDF page 2, arXiv license, scholarly quotation.

These are Grad-CAM++ heat maps on the RAF-DB test set, marking which locations in the image the model relies on most when it decides. On the left is DACL, one head, lighting up a large area around the mouth or nose. The four columns on the right are DAN's four heads; on the same face, each lights up its own spot.

Compare row by row and you'll notice that the same head doesn't look at a fixed place across faces. The first head looks at the eye on the right side of the image in the first row, the mouth in the second, and between the eyes in the third. DAN never specifies which head is in charge of which part; it only requires that the four heads differ from one another on the same face.

So the problem becomes two things. How do you push the class centers apart without adding hyperparameters? And with no part annotations at all, how do you get several attention heads to spread out on their own?

Solving the Problem

The big picture

Original Figure 2: the DAN overview. On the left, two faces enter a blue CNN block labeled FCN, and a dashed box above it shows Affinity Loss, with a cluster of yellow dots gathering toward one center and black dots toward another, and arrows pushing the two centers apart. The MAN section in the middle has three parallel branches, each a blue SA block followed by an elementwise multiplication, then a green CA block followed by another elementwise multiplication, with an ellipsis between the branches. The AFN section on the right first applies Log Softmax; three green bars stand for the heads' attention vectors, which are summed and followed by yellow Linear and BN, ending in CE Loss. A dashed box above it shows Partition Loss, with two rows of heat maps lit in different places. A legend at the top right explains the symbols for elementwise multiplication, Log Softmax, summation, CNN blocks and attention maps.
Original Figure 2, Wen et al., from PDF page 5, arXiv license, scholarly quotation.

DAN has three stages.

  1. FCN (Feature Clustering Network): a ResNet-18 backbone plus an affinity loss that pulls same-class features toward the class center while pushing the class centers apart.
  2. MAN (Multi-head Attention Network): several parallel attention heads, each a spatial attention (SA) followed by a channel attention (CA).
  3. AFN (Attention Fusion Network): scales each head's output with log-softmax, requires the heads to differ through a partition loss, sums them, and classifies with a fully connected layer and BN.

The figure doesn't show tensor sizes. Take one RAF-DB face and follow it through the official code networks/dan.py.

A flowchart drawn for this note, top to bottom. The input image is 3×224×224 and passes through ResNet-18 (MS-Celeb-1M pretrained, last pooling and classifier removed) to give x′ of 512×7×7; purple text on the right notes GAP → 512-d for the affinity loss, which pulls toward the class centers and pushes the centers apart. Next comes a dashed box labeled head j (4 in all: same structure, own weights), containing in order: a 1×1 conv to 256×7×7; 3×3, 1×3 and 3×1 convs to 512×7×7 each, summed, then ReLU; a sum over the 512 channels into one 7×7 spatial map (no sigmoid, values unbounded); x′ ⊙ the spatial map, still 512×7×7, these four boxes marked in blue as spatial attention; and a last box in green, marked as channel attention, GAP to 512, then 512 → 32 → 512 and sigmoid for channel weights, multiplied onto the GAP output to give the 512-d a_j. Gray text on the right gives about 2.14M parameters per head, 8.54M for four heads, and 19.72M with the backbone. Outside the box, the 4 a_j are stacked into 4×512 and each channel gets a log-softmax across the 4 heads, with orange text on the right saying the partition loss wants the variance of each channel across the 4 heads to be as large as possible; finally the 4 heads are summed into 512, followed by an FC layer to 7 and BN, with cross-entropy.
Drawn for this note from the official code networks/dan.py and equations (1)–(6) of the paper.

The input is resized to 224×224224\times224. ResNet-18 with its last pooling and classifier layers removed outputs x′x' of 512×7×7512\times7\times7; each cell of the 7×7 grid corresponds to roughly a 32×32-pixel patch of the original image, so the eyes, nose and mouth take up a cell or two each. The backbone is first pretrained on the MS-Celeb-1M face recognition data, the same weights used in papers such as SCN and DACL.

From here x′x' splits into two paths. One goes through global average pooling (GAP) to 512 dimensions for the affinity loss; the other goes into the four attention heads at once.

FCN: pushing the class centers apart

The affinity loss is equation (2) of the paper:

Laf=∑i=1N∥xi′−cyi∥22σc2\mathcal L_{af}=\frac{\sum_{i=1}^{N}\left\|x'_i-c_{y_i}\right\|_2^2}{\sigma_c^2}

xi′x'_i is the 512-dimensional feature of image ii after GAP, cyic_{y_i} is the center of its class, and NN is the batch size. The numerator is center loss, the squared distance from each image to its own class center. The denominator σc2\sigma_c^2 measures how spread out the class centers are from one another.

In the official code, the denominator is computed by arranging the CC class centers into a C×512C\times512 matrix, taking the variance of those CC numbers in each dimension, and summing over the 512 dimensions. The centers are learnable parameters, updated by the same optimizer along with the network.

A smaller numerator packs each class tighter, and a larger denominator spreads the class centers out; both are written into the same fraction. For example, if the mean squared distance from each image to its own center stays the same and the seven centers spread out twice as far, the variance in each dimension quadruples and the loss drops to a quarter. The authors stress that this denominator is computed directly from the centers during training, with no extra hyperparameter such as a margin to tune.

The authors also projected RAF-DB features trained with the two losses into two dimensions with t-SNE. In the center loss plot several classes' boundaries overlap; in the affinity loss plot the seven clusters are more separated. t-SNE distorts distances, so this serves only as a qualitative reference.

MAN: what happens inside a head

Each attention head first applies spatial attention, equation (3) of the paper:

sj=x′⊙Hj(ws,x′)s_j=x'\odot H_j(w_s,x')

HjH_j produces a spatial weight map, and ⊙\odot is elementwise multiplication. Then channel attention, equation (4):

aj=sj⊙Hj′(wc,sj)a_j=s_j\odot H'_j(w_c,s_j)

j=1,…,Kj=1,\dots,K, with K=4K=4 by default.

Original Figure 4: the structure of one attention head. The dashed box on the left is the spatial attention unit: yellow Input Features first pass through a 1×1 Conv, then split into three branches, a 3×3 Conv, a 1×3 Conv and a 3×1 Conv, which are summed (Σ), pass through an Activation, and are multiplied elementwise with the input to give Spatial Features. The dashed box on the right is the channel attention unit: Spatial Features go through Pooling, then two Linear layers and one Activation to give Channel Features, which are multiplied elementwise with the Pooling result to output orange Output Features.
Original Figure 4, Wen et al., from PDF page 7, arXiv license, scholarly quotation.

Walk through this figure with the official code beside it.

Spatial attention. x′x' first goes through a 1×11\times1 convolution that compresses 512 channels to 256. Then three convolutions side by side, 3×33\times3, 1×31\times3 and 3×13\times1, each expand 256 channels back to 512, and the three are summed and passed through a ReLU. Using horizontal, vertical and square kernels together, according to the paper, captures local features at multiple scales.

In a step the figure leaves out, the code sums these 512 channels directly into a single 1×7×71\times7\times7 map, then multiplies it back onto every channel of x′x'. This map never goes through a sigmoid, and its values have no upper bound, being the sum of 512 ReLU outputs. Estimating from the distribution at initialization (this note's estimate), three BN-ed branches summed and passed through a ReLU average about 0.7 per channel, and summing 512 of them gives three hundred-odd.

Channel attention. sjs_j is pooled by GAP to 512 dimensions, passed through two fully connected layers, 512→32→512 (with BN and ReLU in between), and finally a sigmoid, giving each channel a weight between 0 and 1, which is multiplied back onto the GAP result. The output aja_j is a 512-dimensional vector. This is almost exactly SENet's squeeze-and-excitation with a reduction ratio of 16 and an extra BN in the middle; the difference is that the weights multiply the pooled vector instead of going back onto the feature map.

The paper's title says Multi-head Cross Attention, and the class in the code is called CrossAttentionHead too. In a Transformer, cross-attention takes queries from one side and keys and values from the other, then computes the similarity between every pair; inside each DAN head there are no queries or keys, only a 7×77\times7 spatial weight map and a set of 512-dimensional channel weights. The paper never explains what "cross" refers to; judging from the structure, each head chains spatial and channel attention together, and multi-head means several such modules side by side.

The four heads share the same structure with their own parameters. Counting parameters, each head's 1×11\times1 convolution has about 130,000, the 3×33\times3 about 1.18 million, and the 1×31\times3 and 3×13\times1 about 390,000 each; with channel attention and BN, one head is about 2.14M and four heads 8.54M. ResNet-18 without its classifier is 11.18M, for a total of 19.72M, the same as the paper reports. The heads all compute on the 7×77\times7 feature map, so the four together add only 0.41 GFLOPs, taking the whole model from ResNet-18's 1.82 G to 2.23 G.

AFN: scale, require difference, then merge

Each of the four heads gives a 512-dimensional aja_j, and they're stacked into 4×5124\times512. AFN first applies log-softmax along the "head" direction, equation (5) of the paper:

vjl=log⁡exp⁡(ajl)∑k=1Kexp⁡(akl)v_j^l=\log\frac{\exp\left(a_j^l\right)}{\sum_{k=1}^{K}\exp\left(a_k^l\right)}

l=1,…,512l=1,\dots,512 indexes the channel. Each channel gets its own softmax across the four heads, followed by a log. The authors say this puts the different heads' features on a common scale.

Next comes the partition loss, equation (6) of the paper:

Lpt=1NL∑i=1N∑l=1Llog⁡(1+Kσi,l2)\mathcal L_{pt}=\frac{1}{NL}\sum_{i=1}^{N}\sum_{l=1}^{L}\log\left(1+\frac{K}{\sigma_{i,l}^2}\right)

σi,l2\sigma_{i,l}^2 is the variance among the four heads' vv for image ii and channel ll, and L=512L=512. The more the four heads differ on this channel, the larger the variance and the smaller this term; when the four heads are identical, the variance is 0 and the term blows up.

Work through one channel. Say the four heads output a=(2.0, 0.5, 0.3, 0.2)a=(2.0,\ 0.5,\ 0.3,\ 0.2) on this channel; their exponentials are 7.389, 1.649, 1.350 and 1.221, summing to 11.609:

log⁡∑keak=log⁡11.609=2.452vj=aj−2.452\begin{aligned} \log\sum_k e^{a_k}&=\log 11.609=2.452\\ v_j&=a_j-2.452 \end{aligned}

The four vv are −0.452, −1.952, −2.152 and −2.252, averaging −1.702, with deviations of 1.25, −0.25, −0.45 and −0.55 and a sum of squares of 2.13. The official code uses PyTorch's var, which divides by K−1=3K-1=3, for a variance of 0.71, and this channel's loss is log⁡(1+4/0.71)=1.89\log(1+4/0.71)=1.89. Make the first head stand out a bit more, a=(3.0, 0.5, 0.3, 0.2)a=(3.0,\ 0.5,\ 0.3,\ 0.2), and the variance becomes 1.79, with the loss falling to 1.17. If all four heads output 1, the variance is 0; the code adds a tiny eps to the denominator to avoid dividing by 0, and the term comes to about 37.

For the four heads on the same channel, log-softmax subtracts the same number (2.452 here), so the variance of vv is exactly the variance of aa, 0.71 in both cases. What the partition loss actually measures is how much the four heads' raw outputs differ, and log-softmax has no effect on it.

The partition loss looks at the pooled 512-dimensional vectors and never touches the 7×77\times7 spatial maps. If two heads' spatial maps light up in different places, the vectors you get after multiplying by x′x' and pooling will naturally differ; the authors rely on this indirect effect to spread the four heads out spatially. It also only requires the four heads on the same image to differ, never that a given head always look at a given part, which matches the heat maps earlier, where "the same head looks at different places on different faces."

Finally the four heads' vv are summed along the head direction into 512 dimensions, followed by a fully connected layer outputting seven classes, then a BN layer, and cross-entropy. The total loss is equation (7):

L=λ1Laf+λ2Lpt+Lcls\mathcal L=\lambda_1\mathcal L_{af}+\lambda_2\mathcal L_{pt}+\mathcal L_{cls}

λ1=λ2=1\lambda_1=\lambda_2=1; the authors say the results aren't very sensitive to these two values, but give no data.

A BN after the fully connected layer is unusual. In April 2022 someone asked about it in issue #14; the asker had tried it on their own small 4-class dataset, and without the BN the cross-entropy on the first batch was about 313, against a normal 1.94 with it. The author admitted that "the BN put after FC layer is odd," that the model doesn't learn well without it, and that "it's hard for me to explain." Following the estimate above (this note's guess), the spatial map has no upper bound and can reach several hundred, so the resulting aja_j are large too, and after log-softmax and summation the features fed into the classifier are large as well; large logits make the cross-entropy explode, and that last BN effectively pulls the scale of the whole path back down.

Training setup

  • RAF-DB and AffectNet use the officially aligned images; SFEW 2.0 uses RetinaFace detection followed by manual alignment. The input is 224×224224\times224.
  • ResNet-18 pretrained on MS-Celeb-1M.
  • 40 epochs, batch 256, 4 heads, one 12 GB Tesla P100.
  • RAF-DB uses SGD with learning rate 0.1 (multiplied by 0.1 every 10 epochs in the code); AffectNet uses Adam with learning rate 10−410^{-4}, upsampling minority classes and downsampling majority classes so the classes are roughly balanced during training.
  • Data augmentation is horizontal flips, random rotation and random erasing.

The AffectNet command in the official README trains for 10 epochs, and the released weights stop at epoch 5 (AffectNet-8), epoch 6 (AffectNet-7) and epoch 21 (RAF-DB). The code computes test-set accuracy every epoch and saves only the best one; AffectNet's validation set is its test set, and RAF-DB has no validation set at all. Picking checkpoints this way is common in expression recognition papers, so keep it in mind when you read the numbers.

Discussion

Main results

DatasetBaselinePrior bestDAN
AffectNet-856.8461.4062.09
AffectNet-756.9764.5765.69
RAF-DB86.2588.9889.70
SFEW 2.051.2958.5053.18

Compiled from Tables 1–4 of the paper, accuracy %. The baseline is a ResNet-18 with the same pretraining. "Prior best" is the highest row other than DAN on each table, which is MViT for both AffectNet rows, PSR for RAF-DB and FaceCaps for SFEW 2.0.

On both large datasets, DAN tops the table. On AffectNet-8 it's 0.69 above MViT and 1.86 above SCN's 60.23; on RAF-DB it's 0.72 above PSR and 2.67 above SCN's 87.03. SFEW 2.0 gets only 53.18, below several methods on the table; the authors' explanation is that multi-head attention needs more data to train, and SFEW's training set has fewer than a thousand images.

RAF-DB's 89.70% needs taking apart. Per-class recall is happiness 95.36, sadness 90.17, surprise 89.97, neutral 88.53, anger 83.95, disgust 70.62, fear 60.81. Happiness makes up nearly 40% of the test set, so accuracy is held up mostly by it; the unweighted mean over the seven classes is 82.77%. As for the surprise and fear from the opening, surprise gets ninety percent right and fear only sixty. AffectNet-8's validation set has the same count per class, and per-class recall ranges from neutral at 56.80 to happiness at 74.60, with contempt at 57.52.

Two numbers across six versions

That "seven-class mean" was actually in the paper at first. In v1 through v5, the RAF-DB table had an extra Avg. Accuracy column, with DAN at 85.32%, and the text said both numbers were the best at the time. In March 2022, the asker in issue #11 found a bug in the code in rafdb.py that computes mean accuracy, and recomputing with the official weights gave only 83.76. The author replied that it was their mistake and would be updated; in April, in issue #18, they said the corrected figure was 82.75, and in June said again that they would update the paper. v5 in November 2022 still had 85.32; v6 in May 2023 dropped the whole column (that's one way to update it).

SFEW 2.0 changed too. v1 through v5 gave 57.88%, with the text calling it "comparable"; v6 changed it to 53.18%, with the text now reading "although not the best," and no explanation of any kind between the two versions. The SFEW training code wasn't released; the author's reason in issue #7 was that the faces had to be cropped by hand, and a different detector would give different results.

RAF-DB's 89.70 and AffectNet's 62.09 and 65.69 never changed across all six versions.

Ablations

ModuleSettingRAF-DB
FCNnone88.17
FCNcenter loss88.91
FCNaffinity loss89.70
AFNno partition loss88.20
AFNpartition loss89.70

Compiled from Table 5 of the paper, accuracy %; every setting includes cross-entropy.

Affinity loss is 0.79 above center loss and 1.53 above adding nothing; removing the partition loss costs 1.50.

Original Figure 5: a line chart with the number of attention heads on the horizontal axis, from 1 to 10, and RAF-DB accuracy on the vertical axis, from 88.80% to 90.00%. The values are roughly 88.88, 89.34, 89.07, 89.70, 89.27, 89.37, 89.47, 89.27, 89.24 and 89.07 in order, highest at 4 heads, labeled 89.70.
Original Figure 5, Wen et al., from PDF page 10, arXiv license, scholarly quotation.

The number of heads was tried from 1 to 10. One head gives 88.88, four heads 89.70, and after that it wanders between 89.07 and 89.47. The vertical axis of this chart starts at 88.80, so the whole chart spans less than 1 percentage point. The RAF-DB test set has 3,068 images, so one image is 0.033 percentage points, and one head versus four heads is a difference of 25 images.

A gap of this size has to be set beside reproduction noise. In the official issues, people who reran RAF-DB with the code reported 89.0 (#6), 88.98 (#22), and 89.54 and 88.72 (#31). The author's reply in #6 was that the code doesn't fix the random seed and to try a few more times, adding that "the 89.70 is not the best acc of our model." The reproduction spread is 0.2 to 1 percentage point, about as large as the distances between settings in the ablation table; the paper doesn't say how many times each setting was run, nor does it report standard deviations.

The baseline was questioned too. The asker in issue #13 (April 2022) used the same MS-Celeb-1M weights and DAN's training strategy to run a plain ResNet-18 and got 88.75% on RAF-DB, while the paper's table lists the baseline at 86.25%. The author replied that these pretrained weights weren't trained by them, that SCN and DACL use them too, and that "the best performances of all these model are below your stated 88.75%." Put the numbers side by side and DAN is 3.45 percentage points above its own baseline, but only 0.95 above the asker's.

A different dataset

Like most expression papers, DAN tests on the same dataset it trains on. In January 2026, a study from Warsaw University of Technology retrained POSTER++, DMUE and DAN from their official code, with seven classes on all three datasets, and then tested across datasets. In this study DAN gets only 76% on RAF-DB; its authors say some results are slightly below the original authors' numbers, which is "overall negligible" in the context of their later experiments. The RAF-DB described in the study averages 425×425425\times425, which looks like the unaligned original images rather than the official 100×100100\times100 aligned version DAN uses, so the absolute numbers can't be compared directly with 89.70.

The cross-dataset drops are easier to read. DAN trained on RAF-DB falls to 40% when tested on AffectNet, and only 37% on ExpW, which was collected from the web; trained on AffectNet and tested on RAF-DB, it gets 65%. All three methods drop when the dataset changes; among the three models trained on RAF-DB, DAN has the lowest accuracy on the other two datasets, with POSTER++ at 49% and 52% and DMUE at 45% and 47%. Each dataset has its own annotation habits, and DAN's design doesn't address that problem.

Official code

The official code is at yaoing/DAN, MIT-licensed, with training code for RAF-DB and AffectNet, three sets of weights, and code for single-image inference and Grad-CAM. Besides the class count, the partition loss computation and the final BN mentioned earlier, there are two practical pitfalls.

  • MS-Celeb-1M pretrained weights. In October 2022 someone reported that the download link was dead (issue #28), with no reply; the README switched to a new link the same month. These weights decide how high the baseline goes; change the weights and every number has to be rerun.
  • AffectNet's file format. The code reads the version with one *_exp.npy label file per image. The asker in issue #9 used data in a different format, topping out at 60.94 on AffectNet-8 and getting 60.39 when testing the official weights on their own validation list; the author suggested downloading again through the official channel.

Conclusion

DAN makes an expression classifier look at several places on the face at once. ResNet-18 is followed by four "spatial attention plus channel attention" heads, the partition loss requires the four heads to differ on the same face, and the affinity loss pushes the feature centers of the expression classes apart; the whole model has 19.72M parameters, only 0.41 GFLOPs more than ResNet-18, with 89.70% on RAF-DB and 62.09% on AffectNet-8, both the top of their tables at the time.

The four heads really do spread out, each lighting up its own spot on the heat maps; how much accuracy that buys is less well supported. In the ablations each component brings 0.8 to 1.5 percentage points, community reruns of the official code vary by 0.2 to 1 percentage point, and the paper doesn't report how many times each setting was run; a plain ResNet-18 trained from the same MS-Celeb-1M weights already reaches 88.75%. When you use the official code, change the class count in AffinityLoss to the dataset's real number of classes and keep the BN after the fully connected layer; when you use it as a comparison, run it several times and average, and report the seven-class mean for RAF-DB alongside, which is 82.77% for this same model.

The name says "distract," but what it actually does is make the network pay close attention to several places at once. In the opening puzzle, telling surprise from fear means looking at the eyebrows and the mouth together; DAN spread out where it looks, and on RAF-DB surprise is 89.97% correct while fear is still only 60.81%. Between seeing different places and telling similar expressions apart, there is still a gap.