# An End-to-End Deep Learning Image Compression Framework Based on Semantic Analysis
## 3 Network Structure
### Compressed Image with Semantic Map  
In order to perform discriminative compression for images, image blocked processing adopts 8 \(\times 8\) blocks, referring to JPEG, so that the corresponding compression ratio of each image block can be calculated according to its semantic importance, due to the problem that larger blocks will slow down the computation speed and smaller blocks will affect the information entropy between pixels. The method described in Section 3.2 is used so that the number of iterations in the image compression network controls the compression ratio of images. In this section, we propose a compression bit allocation algorithm according to the semantic importance of image blocks to calculate the number of iterations of each block given the average compression level of images. Given the input image size \(H\times W\), the entire picture is divided into \(N\) blocks with a size of \(8\times 8\), with \(N=H\times W/8\times 8\). Let \(\overline{K}\) be the average compression level of the image, and the compression level of block \(i\) be \(K_{i}\); to ensure the consistency of the compression ratio, the sum of the compression levels of all image blocks should be defined as  
\[\sum_{i=1}^{N}K_{i}=\overline{K}\times N \tag{9}\]  
We convert the semantic importance map to a grayscale graph to better represent the semantic importance of each pixel. The higher the gray value of pixel \((x,y)\), the greater the probability that \(i\) belongs to a specific grammatical category of interest to the human eye; that is, the higher the semantic importance. Let the semantic importance value \(V_{i}\) of the block \(i\) be the sum of the gray values \(g_{(x,y)}\) corresponding to each pixel \((x,y)\) which belongs to the block; then, we can get the semantic level \(L_{i}\). \[L_{i}=\frac{V_{i}}{\sum\limits_{i=1}^{N}V_{i}}=\frac{\sum\limits_{(x,y)\in i}g _{(x,y)}}{\sum\limits_{i=1}^{N}\sum\limits_{(x,y)\in i}g_{(x,y)}} \tag{10}\]  
Considering the sum of the compression level of the blocks to be \(\overline{K}\times N\), the calculated level of block \(i\) can be expressed as \(T_{i}\). \[T_{i}=\left\lfloor L_{i}\times\overline{K}\times N\right\rfloor \tag{11}\]  
where \(\left\lfloor\cdot\right\rfloor\) is the int function used to ensure the average compression level does not exceed \(\overline{K}\). However, in our experiment, we found that the calculation method proposed above will result in an excessive number of iterations of the image block with higher semantic importance when the whole picture has a high average number of iterations. According to the image compression network described above, although the increase in the number of iterations can improve the quality of the restored image, a great deal of calculation time and space are required. Therefore, the allocation method is not reasonable when the average number of iterations is high, which needs further improvement. We performed 0-30 iterative compressions on the 24 images in the Kodak dataset and calculated the corresponding MS-SSIM [22] values to verify the impact of the number of iterations on the quality of the recovered images. From the experimental results, although the recovered quality gradually improved with the increasing iterations, we observed that the degree of the improvement gradually decreased and tended to be approximate after 24 times. Therefore, we choose 24 to be the threshold for the iterations of the compression network to balance the computational overhead with the quality of the compressed image. For image blocks with more than 24 iterations, the excess number is assigned to the remaining image blocks that do not exceed this, based on the degree of semantic importance. In light of all derivations above, the complete description of the proposed algorithm is given in Algorithm 1. First, we calculated the iterations \(T_{i}\) of each image block according to Equation (11), in which more than 24 iterations are processed as 24, and the excess part is added to the summation \(E\).