The invention discloses a PLC
anomaly detection method and
system based on a self-attention mechanism and an OCNN, and relates to the technical field of industrial
automation control, and the method comprises the steps: collecting PLC operation data through a
Modbus communication protocol, carrying out the
standardization processing, constructing a
time sequence sample, constructing a
feature extraction network based on the self-attention mechanism, and carrying out the detection of the PLC anomaly. Generating a query matrix, a key matrix and a value matrix through three linear transformation
layers to perform global
feature extraction, further performing local
feature extraction, designing an improved OCNN
detector, splicing global and local features through a special fusion layer, introducing residual connection, and calculating an abnormal
score through an abnormal boundary learning layer; joint optimization of a feature extraction network and a
detector is realized, a multi-task
loss function is designed, and a two-stage training strategy is adopted for optimization; and finally, online
anomaly detection is executed, real-
time data preprocessing and feature extraction are carried out, multi-level early warning judgment is carried out, and an early warning information report containing
processing suggestions is generated in combination with space-
time correlation analysis.