# High-Quality Video Watermarking Based on Deep Neural Networks for Video with HEVC Compression +
## 3 Proposed Method
### HEVC Compression Learning Process  
In order to increase the accuracy of the embedded watermarked image compared to the original image and to increase the tolerance range of HEVC compression, an additional training element was introduced in the training process of the encoder and decoder that mimics HEVC compression, hereafter referred to as the DNN coder. In this subsection, the training process for the aforementioned element will be presented, while the training of the encoder embedding the watermark, as well as the decoder performing the watermark reconstruction, will be presented in the next subsection. In order to carry out the training process of the DNN coder mimicking HEVC compression, the following objective function relationships were used:  
\[MSE_{\text{{OyCedImg}}}=\text{MSE}\big{(}\text{Image}_{Original},\ \text{Image}_{\text{{Coded}}}\big{)} \tag{1}\]  
\[MSE_{\text{{HeVCedImg}}}=\text{MSE}\big{(}\text{Image}_{\text{{HeVC}}}(CRF),\ \text{ Image}_{\text{{Coded}}}\big{)} \tag{2}\]  
\[\text{EpochChange}(i)=i\cdot 0.001 \tag{3}\]  
\[L_{\text{{CordLoss}}}(i)=\big{(}\big{(}(1.01-\text{EpochChange}(i))\cdot MSE_{ \text{{OyCedImg}}}\big{)}+\big{(}(0.50+\text{EpochChange}(i))\cdot MSE_{ \text{{HeVCedImg}}}\big{)}\big{)}\ i\,\varepsilon(0;300) \tag{4}\]  
\[\
abla L_{\text{{Cord}}}(i)=\frac{\partial L_{\text{{CordLoss}}}(i)}{\partial Var _{\text{{Cord}}}(i)} \tag{5}\]  
where \(\text{MSE}(\text{Image}_{1},\text{Image}_{2})=\frac{1}{\hbar}\sum_{i=0}^{N_{j} }\big{(}\text{Image}_{1}^{p}[i]-\text{Image}_{2}^{q}[i]\big{)}^{2}\) is the mean square error at axis \(j\) (with size \(N_{j}\)) of images described as tensors, Image\({}_{Original}\) is the original image, Image\({}_{Codd}\) is the image produced by the trained ANN mimicking the image after HEVC compression, Image\({}_{Hec}\) is the image obtained after HEVC compression, \(CRF\) (constant-rate-factor) is the coefficient determining the degree of HEVC compression, \(MSE_{\text{{OyCedImg}}}\) is the mean square error of the image produced by the coder relative to the original image, \(MSE_{\text{{HeVCedImg}}}\) is the mean square error of the image produced  
Figure 2: Demonstration of YUV color model for the YUV444 and YUV420p variants. by the DNN coder in relation to the image obtained after HEVC compression, \(i\) is the training epoch number, EpochChange\((i)\) is the modification value of the error function calculated on the basis of the epoch number, \(L_{CodLoss}(i)\) is the encoder error, \(Var_{\text{Cod}}(i)\) is the tensor of the encoder model weights, \(L_{Cod}(i)\) is the gradient of the coder objective function. The training process used the Adam Optimizer algorithm [53]. The optimal number to achieve convergence for DNN was to run 300 epochs of the training algorithm. For the first 200 epochs of training, the learning rate had a fixed value of \(10^{-4}\), and for the next 100 epochs the coefficient was changed to \(10^{-5}\), as it was found during the experiments that a reduction in the rate after the 200 th epoch yielded the best training results. The training set consisted of 4000 images randomly downloaded from the Internet, which were changed to a 128 \(\times\) 128 resolution compatible with the input size of the coder and the other ANNs discussed further. The images, when loaded for training, were converted to the YUV420p color model, which means that from the standard RGB color model, which has dimensions of 128 \(\times\) 128 \(\times\) 3 (where the first two numbers indicate height and width and the last digit indicates the number of channels), the images were converted accordingly with the YUV420p color model to a size of 192 \(\times\) 128 \(\times\) 1, which is the image size at the input and output of the network. The test set consisted of video frames that had been converted to the H.265 codec format with a compression coefficient of \(CRF=7\). The testing process compared the individual frames read from the video and then calculated \(MSE_{HrecCallmg}\).