Instrumentation & Measurement Magazine 26-2 - 22

block, we introduce HWA and DTN, as described in the next
sections.
Table 1 lists the detailed architecture setting, where: Ni
is the number of blocks in each stage; C is the Channel dimension;
heads is the number of heads in hybrid window
attention; and window size is the region size in hybrid window
attention.
Hybrid Window Attention
Hybrid window attention is proposed to add cross-window
connection based on the introduction of pooling attention
and window attention. It calculates all the local attention
within a window, and by this way, the input features contain
global information [25]. Specifically, in order to process
the 2D image, we reshape X∊RHxWxD
tened 2D patches XR
NP2 D



into a sequence of flat,
where (H,W) is the resolution
of the original input image.
For an input sequence X∊RLxD
,WK,WV∊RLxD
, (where L=P2
C, denotes the
original image resolution; (P,P) is the resolution of each image
patch; and D denotes the number of image channels) a linear
projection WQ
is applied, followed by a pooling
operation (P) for the query, key and value tensor:
Q P XW K P XW V P XWV
Q
Q
,
 K
K
,
 V
where the length  L of QR 


lengths of K and V can be reduced by PK


andPV
self-attention can be expressed as:
, , max(
and PV
Z Attention Q K V Soft QK D V
T
/
)
to compute a length-flexible output sequence Z∊RLxD
downsampling factors PK
different from those applied to the query sequence PQ
    
LD can be reduced by PQ
(1)
and the
. Then, pooled
(2)
. The
for key and value may be
. The resolution
between different stages of DHT can be reduced by
pooling query Q and will significantly reduce the computational
complexity by pooling key K and value V. The relevant
analysis is as follows, in which we present the complexity of
the model.
We assume that the input and output features have the
same size H×W×C. Hybrid window attention will be calculated
in the local window for self-attention. There is
segmentation of images by non-overlapping windows. Each
window contains P×P patches. To ensure that the image (H×W)
is divisible by the window (P×P), when calculating attention,
we use the padding method.
 R H
h

T
C

x 


x Concate  



Concate  
hH

hH  
h


 
2
h
where γ,β are two learning rate parameters of affine transformation
in the model. H represents the number of model
heads, and
, 
2
h

T
 R
C
H is the normalization constant
of DTN. The 'Concate' in the equation means to
concatenate together the normalization constant of DTN.
This design is accomplished in two steps. Firstly, patches
with different attention distances are attended to by the attention
heads, and different self-attention heads are encouraged
to conduct different background modelling. Secondly, with
two different statistics (inter -token and intra -token), we design
the DTN by calculating the normalization constant for
each head of the hybrid window attention.
Dataset Description and Experiment
Configuration
In our experiments, the NEU surface defect dataset [26] and
the DAGM dataset [27] are utilized to verify the validity of our
proposed approach. First, we describe the two datasets used in
this paper and then show the experimental setup.
Dataset
Stage
1
2
3
4
22
Table 1 - Detailed architecture specifications
Output Size
DHT
H/4×W/4×C
H/8×W/8×C
H/16×W/16×C
H/32×W/32×C
N1:4; C=96; heads:3; Window size:7
N2:4; C=192; heads:6; Window size:7
N3:12; C=384; heads:12; Window size:7
N4:4; C=768; heads:24; Window size:7
IEEE Instrumentation & Measurement Magazine
The NEU surface defect dataset contains six types of defects
(Fig. 2): rolled-in scale (RS), patches (Pa), crazing (Cr), pitted
surface (PS), inclusion (In) and scratches (Sc), with 300 images
of each defect and an image size of 200×200 pixels. In the classification
task, we randomly
select 70% of the data as
the training set and the remaining
30% as the testing
set [28].
The DAGM dataset was
generated manually and
contains six classes of image
samples of 512×512 pixels
April 2023

(4)
In this model, the computational complexity of our hybrid
window attention is:
 
 2 22

=HGWG=HW/r2
HWA HWN C HWC N CSS (3)
22
where C denotes the Channel dimension, h and w represent
the height and width of the image, respectively, and
NS
is the number of sampling points. It can be
concluded that the computational cost has a linear complexity.
Channel size is insignificant compared to the cost of attention
calculation.
Dynamic Token Normalization (DTN)
This article defines DTN with a unified description. The normalization
constant of DTN is obtained by computing the
token's statistics. We reshape the image into a sequence of tokens
x∊RLxD
, and DTN normalizes the token by the following:

Instrumentation & Measurement Magazine 26-2

Table of Contents for the Digital Edition of Instrumentation & Measurement Magazine 26-2

Instrumentation & Measurement Magazine 26-2 - Cover1
Instrumentation & Measurement Magazine 26-2 - Cover2
Instrumentation & Measurement Magazine 26-2 - 1
Instrumentation & Measurement Magazine 26-2 - 2
Instrumentation & Measurement Magazine 26-2 - 3
Instrumentation & Measurement Magazine 26-2 - 4
Instrumentation & Measurement Magazine 26-2 - 5
Instrumentation & Measurement Magazine 26-2 - 6
Instrumentation & Measurement Magazine 26-2 - 7
Instrumentation & Measurement Magazine 26-2 - 8
Instrumentation & Measurement Magazine 26-2 - 9
Instrumentation & Measurement Magazine 26-2 - 10
Instrumentation & Measurement Magazine 26-2 - 11
Instrumentation & Measurement Magazine 26-2 - 12
Instrumentation & Measurement Magazine 26-2 - 13
Instrumentation & Measurement Magazine 26-2 - 14
Instrumentation & Measurement Magazine 26-2 - 15
Instrumentation & Measurement Magazine 26-2 - 16
Instrumentation & Measurement Magazine 26-2 - 17
Instrumentation & Measurement Magazine 26-2 - 18
Instrumentation & Measurement Magazine 26-2 - 19
Instrumentation & Measurement Magazine 26-2 - 20
Instrumentation & Measurement Magazine 26-2 - 21
Instrumentation & Measurement Magazine 26-2 - 22
Instrumentation & Measurement Magazine 26-2 - 23
Instrumentation & Measurement Magazine 26-2 - 24
Instrumentation & Measurement Magazine 26-2 - 25
Instrumentation & Measurement Magazine 26-2 - 26
Instrumentation & Measurement Magazine 26-2 - 27
Instrumentation & Measurement Magazine 26-2 - 28
Instrumentation & Measurement Magazine 26-2 - 29
Instrumentation & Measurement Magazine 26-2 - 30
Instrumentation & Measurement Magazine 26-2 - 31
Instrumentation & Measurement Magazine 26-2 - 32
Instrumentation & Measurement Magazine 26-2 - 33
Instrumentation & Measurement Magazine 26-2 - 34
Instrumentation & Measurement Magazine 26-2 - 35
Instrumentation & Measurement Magazine 26-2 - 36
Instrumentation & Measurement Magazine 26-2 - 37
Instrumentation & Measurement Magazine 26-2 - 38
Instrumentation & Measurement Magazine 26-2 - 39
Instrumentation & Measurement Magazine 26-2 - 40
Instrumentation & Measurement Magazine 26-2 - 41
Instrumentation & Measurement Magazine 26-2 - 42
Instrumentation & Measurement Magazine 26-2 - 43
Instrumentation & Measurement Magazine 26-2 - 44
Instrumentation & Measurement Magazine 26-2 - 45
Instrumentation & Measurement Magazine 26-2 - 46
Instrumentation & Measurement Magazine 26-2 - 47
Instrumentation & Measurement Magazine 26-2 - 48
Instrumentation & Measurement Magazine 26-2 - 49
Instrumentation & Measurement Magazine 26-2 - 50
Instrumentation & Measurement Magazine 26-2 - 51
Instrumentation & Measurement Magazine 26-2 - 52
Instrumentation & Measurement Magazine 26-2 - 53
Instrumentation & Measurement Magazine 26-2 - 54
Instrumentation & Measurement Magazine 26-2 - 55
Instrumentation & Measurement Magazine 26-2 - 56
Instrumentation & Measurement Magazine 26-2 - 57
Instrumentation & Measurement Magazine 26-2 - 58
Instrumentation & Measurement Magazine 26-2 - 59
Instrumentation & Measurement Magazine 26-2 - 60
Instrumentation & Measurement Magazine 26-2 - 61
Instrumentation & Measurement Magazine 26-2 - 62
Instrumentation & Measurement Magazine 26-2 - 63
Instrumentation & Measurement Magazine 26-2 - Cover3
Instrumentation & Measurement Magazine 26-2 - Cover4
https://www.nxtbook.com/allen/iamm/26-6
https://www.nxtbook.com/allen/iamm/26-5
https://www.nxtbook.com/allen/iamm/26-4
https://www.nxtbook.com/allen/iamm/26-3
https://www.nxtbook.com/allen/iamm/26-2
https://www.nxtbook.com/allen/iamm/26-1
https://www.nxtbook.com/allen/iamm/25-9
https://www.nxtbook.com/allen/iamm/25-8
https://www.nxtbook.com/allen/iamm/25-7
https://www.nxtbook.com/allen/iamm/25-6
https://www.nxtbook.com/allen/iamm/25-5
https://www.nxtbook.com/allen/iamm/25-4
https://www.nxtbook.com/allen/iamm/25-3
https://www.nxtbook.com/allen/iamm/instrumentation-measurement-magazine-25-2
https://www.nxtbook.com/allen/iamm/25-1
https://www.nxtbook.com/allen/iamm/24-9
https://www.nxtbook.com/allen/iamm/24-7
https://www.nxtbook.com/allen/iamm/24-8
https://www.nxtbook.com/allen/iamm/24-6
https://www.nxtbook.com/allen/iamm/24-5
https://www.nxtbook.com/allen/iamm/24-4
https://www.nxtbook.com/allen/iamm/24-3
https://www.nxtbook.com/allen/iamm/24-2
https://www.nxtbook.com/allen/iamm/24-1
https://www.nxtbook.com/allen/iamm/23-9
https://www.nxtbook.com/allen/iamm/23-8
https://www.nxtbook.com/allen/iamm/23-6
https://www.nxtbook.com/allen/iamm/23-5
https://www.nxtbook.com/allen/iamm/23-2
https://www.nxtbook.com/allen/iamm/23-3
https://www.nxtbook.com/allen/iamm/23-4
https://www.nxtbookmedia.com