# 4 KSecure: A Universal Method for Active Manipulation Detection in Images of Any Resolution
## 3 Method
### Training Process  
At the beginning of the 4 KSecure training process, we assume, similar to other data-hiding solutions [37; 38; 39], that the encoder and decoder networks are trained simultaneously within a single learning loop. This means that during a single training iteration, data pass through the entire pipeline, from the encoder input through subsequent processing blocks and finally to the decoder. A crucial aspect of this process is maintaining a continuous gradient flow, which enables the network to understand better the transformations occurring throughout the processing pipeline. From an implementation perspective, this was achieved using the Kornia library, which supports differentiable image transformation operations. This chapter focuses on a general overview of the 4 KSecure training process. At the same time, specific aspects, such as dataset characteristics and the types of introduced distortions, will be discussed in dedicated subsections. A detailed schematic of the entire training pipeline is illustrated in Figure 3, where the high-resolution and intermediate-resolution paths are highlighted separately. This distinction helps clarify how data are repeatedly scaled and processed within the system. The upper part of the diagram represents the encoder section, which concludes with generating a high-resolution image containing the embedded hidden signature. Then, still within the training phase, this image passes through the attack module, a component present only during training, which simulates various types of malicious modifications that the data may encounter in real-world scenarios. The next stage is the decoder section, which takes the manipulated (noisy) image as input and attempts to determine the likelihood of manipulation based on distortions in the previously embedded pattern, while identifying the regions where alterations occurred. The decoder output consists of a mask visualizing the localized attacks and a binary prediction indicating whether the system detects any manipulation in the image. Figure 2: Network scheme and data shape in the 4 KSecure algorithm. (**a**) Encoder network, (**b**) decoder network. Supervised training is conducted based on four loss functions (also illustrated in Figure 3), which simultaneously regulate both the encoder and decoder parameters. Each pipeline component has a corresponding ground truth, allowing the network to adjust its predictions to match real values gradually. This online training organization ensures that both models, the encoder and the decoder, learn harmoniously within a single process,  
Figure 3: Training scheme for the 4 KSecure algorithm. enabling continuous performance monitoring and optimization. Below is a description of each loss function along with their corresponding metrics:  
* _Loss 1_ is responsible for ensuring that the binary mask generated by the decoder aligns with the reference mask (ground truth). In this case, the classic Binary Cross-Entropy (BCE) function is used, as each pixel is classified into one of two categories: modified or unmodified. The reference mask is created by the attack module, which designates the manipulated regions. The mathematical formulation of BCE is as follows: \[l(x,\,y)=L=\{l_{1},\,\ldots,\,l_{N}\}^{T},\,l_{n}=-w_{n}[y_{n}\times logx_{n} +(1-y_{n})\times\log(1-x_{n})]\] where \(N\) is the batch size;
* _Loss 2_ concerns the classification accuracy of the entire image. Similar to Loss 1, BCE is applied. Still, instead of operating on a pixel-wise matrix, it uses a single logit value that determines whether any manipulation is present in the entire image. The ground truth for this function is derived from the reference mask: if any modification is detected, the image is classified as \"positive\";
* _Loss 3_ ensures high image transparency at the intermediate resolution stage. It evaluates artifacts introduced by the encoding network (combined with the input image), while considering the final predictions from the decoder.