Disclosure of Invention
The invention mainly aims to provide a page rendering method, equipment, a storage medium and a device based on machine learning, and aims to solve the technical problem of considering both image loading speed and user experience in the prior art.
In order to achieve the above object, the present invention provides a page rendering method based on machine learning, which includes the following steps:
when a page loading request sent by target user equipment is received, detecting the type of the target equipment corresponding to the target user equipment according to the page loading request;
inputting the type of the target equipment into a preset image proportion optimization model so that the preset image proportion optimization model outputs a target optimal proportion corresponding to the type of the target equipment;
acquiring page text information and page image information corresponding to the page loading request;
compressing the page image information according to the target optimal proportion to obtain optimized image information;
rendering the page text information and the optimized image information to a current page.
Preferably, when receiving a page loading request sent by a target user device and before extracting device information corresponding to the page loading request, the page rendering method based on machine learning further includes:
acquiring a sample image type corresponding to a sample equipment type, and acquiring a sample compression ratio and a sample satisfaction degree corresponding to the sample image type;
selecting an optimal sample proportion corresponding to the sample image type from the sample compression proportions according to the sample satisfaction;
and obtaining a corresponding relation between the type of the sample equipment and the optimal proportion of the sample, and generating a preset image proportion optimization model according to the corresponding relation.
Preferably, the selecting an optimal sample proportion corresponding to the sample image type from the sample compression proportions according to the sample satisfaction specifically includes:
fitting the sample compression ratio and the sample satisfaction degree to obtain a target optimization function;
iterating the target optimization function by a gradient rise method to obtain the maximum value of the sample satisfaction degree;
and taking the sample compression ratio corresponding to the maximum value of the sample satisfaction degree as the sample optimal ratio of the sample image type.
Preferably, the iterating the objective optimization function by a gradient ascent method to obtain the maximum value of the sample satisfaction degree specifically includes:
calculating function values of the target optimization function every other preset step length;
judging whether the difference value between the last function value and the current function value is greater than a preset threshold value or not;
if the difference value is larger than the preset threshold value, returning to the step of judging whether the difference value between the last function value and the current function value is smaller than the preset threshold value;
and if the difference is less than or equal to the preset threshold, determining that the current function value is the maximum value of the sample satisfaction degree.
Preferably, before the calculating the function value of the objective optimization function every preset step length, the page rendering method based on machine learning further includes:
obtaining an independent variable value range of the target optimization function, and taking the product of the independent variable value range and preset precision as a preset step length;
correspondingly, the calculating the function value of the target optimization function every preset step length specifically includes:
and calculating the function value of the target optimization function every preset step length in the independent variable value range.
Preferably, the compressing the page image information according to the target optimal proportion to obtain the optimized image information specifically includes:
and compressing the pixels of the page image information according to the target optimal proportion by a preset compression tool to obtain optimized image information.
Preferably, when receiving a page loading request sent by a target user equipment, the detecting, according to the page loading request, a target equipment type corresponding to the target user equipment specifically includes:
when a page loading request sent by target user equipment is received, extracting target equipment information from the page loading request;
and detecting the type of the target equipment corresponding to the target user equipment according to the target equipment information.
In addition, to achieve the above object, the present invention further provides a page rendering device, which includes a memory, a processor, and a page rendering program based on machine learning, stored on the memory and executable on the processor, wherein the page rendering program based on machine learning is configured to implement the steps of the page rendering method based on machine learning as described above.
In addition, to achieve the above object, the present invention further provides a storage medium, on which a page rendering program based on machine learning is stored, and when the page rendering program based on machine learning is executed by a processor, the steps of the page rendering method based on machine learning as described above are implemented.
In addition, in order to achieve the above object, the present invention further provides a page rendering device based on machine learning, including:
the request receiving module is used for detecting the type of target equipment corresponding to the target user equipment according to a page loading request when the page loading request sent by the target user equipment is received;
the proportion prediction module is used for inputting the target equipment type into a preset image proportion optimization model so as to enable the preset image proportion optimization model to output a target optimal proportion corresponding to the target equipment type;
the information acquisition module is used for acquiring page text information and page image information corresponding to the page loading request;
the image compression module is used for compressing the page image information according to the target optimal proportion to obtain optimized image information;
and the page rendering module is used for rendering the page text information and the optimized image information to a current page.
In the invention, when a page loading request sent by target user equipment is received, the type of the target equipment corresponding to the target user equipment is detected according to the page loading request; inputting the type of the target equipment into a preset image proportion optimization model so that the preset image proportion optimization model outputs a target optimal proportion corresponding to the type of the target equipment; acquiring page text information and page image information corresponding to the page loading request; compressing the page image information according to the target optimal proportion to obtain optimized image information; rendering the page text information and the optimized image information to a current page. The target optimal proportion corresponding to the type of the target equipment is obtained through the model, and the page image information is compressed according to the target optimal proportion, so that the page rendering efficiency is improved under the condition of not reducing the image size, and the page loading speed and the user experience are considered.
Detailed Description
It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
Referring to fig. 1, fig. 1 is a schematic structural diagram of a page rendering device of a hardware operating environment according to an embodiment of the present invention.
As shown in fig. 1, the page rendering apparatus may include: a processor 1001, such as a Central Processing Unit (CPU), a communication bus 1002, a user interface 1003, a network interface 1004, and a memory 1005. Wherein a communication bus 1002 is used to enable connective communication between these components. The user interface 1003 may include a Display screen (Display), and the optional user interface 1003 may further include a standard wired interface and a wireless interface, and the wired interface for the user interface 1003 may be a USB interface in the present invention. The network interface 1004 may optionally include a standard wired interface, a WIreless interface (e.g., a WIreless-FIdelity (WI-FI) interface). The Memory 1005 may be a Random Access Memory (RAM) Memory or a Non-volatile Memory (NVM), such as a disk Memory. The memory 1005 may alternatively be a storage device separate from the processor 1001.
Those skilled in the art will appreciate that the architecture shown in FIG. 1 does not constitute a limitation of a page rendering device, and may include more or fewer components than those shown, or some components in combination, or a different arrangement of components.
As shown in fig. 1, a memory 1005, which is a type of computer storage medium, may include therein an operating system, a network communication module, a user interface module, and a machine learning-based page rendering program.
In the page rendering device shown in fig. 1, the network interface 1004 is mainly used for connecting a background server and performing data communication with the background server; the user interface 1003 is mainly used for connecting user equipment; the page rendering device calls a page rendering program based on machine learning stored in the memory 1005 through the processor 1001 and executes the page rendering method based on machine learning provided by the embodiment of the present invention.
The page rendering apparatus calls a machine learning based page rendering program stored in the memory 1005 through the processor 1001 and performs the following operations:
when a page loading request sent by target user equipment is received, detecting the type of the target equipment corresponding to the target user equipment according to the page loading request;
inputting the type of the target equipment into a preset image proportion optimization model so that the preset image proportion optimization model outputs a target optimal proportion corresponding to the type of the target equipment;
acquiring page text information and page image information corresponding to the page loading request;
compressing the page image information according to the target optimal proportion to obtain optimized image information;
rendering the page text information and the optimized image information to a current page.
Further, the page rendering apparatus calls a machine learning based page rendering program stored in the memory 1005 by the processor 1001, and also performs the following operations:
acquiring a sample image type corresponding to a sample equipment type, and acquiring a sample compression ratio and a sample satisfaction degree corresponding to the sample image type;
selecting an optimal sample proportion corresponding to the sample image type from the sample compression proportions according to the sample satisfaction;
and obtaining a corresponding relation between the type of the sample equipment and the optimal proportion of the sample, and generating a preset image proportion optimization model according to the corresponding relation.
Further, the page rendering apparatus calls a machine learning based page rendering program stored in the memory 1005 by the processor 1001, and also performs the following operations:
fitting the sample compression ratio and the sample satisfaction degree to obtain a target optimization function;
iterating the target optimization function by a gradient rise method to obtain the maximum value of the sample satisfaction degree;
and taking the sample compression ratio corresponding to the maximum value of the sample satisfaction degree as the sample optimal ratio of the sample image type.
Further, the page rendering apparatus calls a machine learning based page rendering program stored in the memory 1005 by the processor 1001, and also performs the following operations:
calculating function values of the target optimization function every other preset step length;
judging whether the difference value between the last function value and the current function value is greater than a preset threshold value or not;
if the difference value is larger than the preset threshold value, returning to the step of judging whether the difference value between the last function value and the current function value is smaller than the preset threshold value;
and if the difference is less than or equal to the preset threshold, determining that the current function value is the maximum value of the sample satisfaction degree.
Further, the page rendering apparatus calls a machine learning based page rendering program stored in the memory 1005 by the processor 1001, and also performs the following operations:
obtaining an independent variable value range of the target optimization function, and taking the product of the independent variable value range and preset precision as a preset step length;
correspondingly, the calculating the function value of the target optimization function every preset step length specifically includes:
and calculating the function value of the target optimization function every preset step length in the independent variable value range.
Further, the page rendering apparatus calls a machine learning based page rendering program stored in the memory 1005 by the processor 1001, and also performs the following operations:
and compressing the pixels of the page image information according to the target optimal proportion by a preset compression tool to obtain optimized image information.
Further, the page rendering apparatus calls a machine learning based page rendering program stored in the memory 1005 by the processor 1001, and also performs the following operations:
when a page loading request sent by target user equipment is received, extracting target equipment information from the page loading request;
and detecting the type of the target equipment corresponding to the target user equipment according to the target equipment information.
In the embodiment, when a page loading request sent by target user equipment is received, the type of the target equipment corresponding to the target user equipment is detected according to the page loading request; inputting the type of the target equipment into a preset image proportion optimization model so that the preset image proportion optimization model outputs a target optimal proportion corresponding to the type of the target equipment; acquiring page text information and page image information corresponding to the page loading request; compressing the page image information according to the target optimal proportion to obtain optimized image information; rendering the page text information and the optimized image information to a current page. The target optimal proportion corresponding to the type of the target equipment is obtained through the model, and the page image information is compressed according to the target optimal proportion, so that the page rendering efficiency is improved under the condition of not reducing the image size, and the page loading speed and the user experience are considered.
Based on the hardware structure, the embodiment of the page rendering method based on machine learning is provided.
Referring to fig. 2, fig. 2 is a flowchart illustrating a first embodiment of the page rendering method based on machine learning according to the present invention, and proposes the first embodiment of the page rendering method based on machine learning according to the present invention.
In a first embodiment, the method for rendering a page based on machine learning includes the following steps:
step S10: when a page loading request sent by target user equipment is received, detecting the type of the target equipment corresponding to the target user equipment according to the page loading request.
It should be noted that the execution subject of this embodiment is the page rendering device, and the page rendering device may be an electronic device such as a smart phone, a personal computer, or a tablet computer, which is not limited in this embodiment. The present embodiment divides user equipments into several types according to the device size, such as a large-sized device, a medium-sized device, and a small-sized device, wherein the device sizes of the five device types are reduced in order.
In specific implementation, a User Agent User-Agent in header information of the page loading request is automatically analyzed, and a target device type corresponding to the target User device is obtained.
Step S20: and inputting the type of the target equipment into a preset image proportion optimization model so that the preset image proportion optimization model outputs a target optimal proportion corresponding to the type of the target equipment.
It can be understood that, in order to increase the page rendering speed, the embodiment reduces the page image information, and if the compression ratio is too small, for example, 0.1, the page image information lacks a large number of pixels, so that the image distortion is caused, and the user's impression is affected; if the compression ratio is too large, for example, 0.9, the difference between the file sizes occupied by the reduced page image and the file size occupied by the page image before reduction is small, so that the improvement degree of the page rendering speed is small, and therefore, the optimal ratio needs to be selected from a plurality of compression ratios.
In the specific implementation, because the image pixels of the large-scale device are higher and the image pixels of the small-scale device are lower, the compression ratio of the large-scale device can be smaller than that of the small-scale device under the condition that the user impression is not influenced, in order to obtain the optimal ratio of the user devices of various device types, the preset image ratio optimization model is adopted to train the compression ratio and the satisfaction degree, and thus the compression ratio with higher satisfaction degree, namely the optimal ratio, is obtained. The preset image proportion optimization model comprises a mapping relation between equipment types and optimal proportions, and the optimal proportions of the target corresponding to the target equipment types can be predicted according to the target equipment types.
Step S30: and acquiring page text information and page image information corresponding to the page loading request.
It should be understood that the page content corresponding to the page loading request includes page text information and page image information, and the page text information and the page image information corresponding to the page loading request are obtained in advance for rendering the page content.
Step S40: and compressing the page image information according to the target optimal proportion to obtain optimized image information.
It should be noted that, compressing the page image information according to the target optimal proportion can reduce the image proportion corresponding to the page image information without affecting the look and feel of the user.
Step S50: rendering the page text information and the optimized image information to a current page.
It can be understood that the page image information is compressed, the pixels of the obtained optimized image information are smaller than the page image information, but the image size of the optimized image information is the same as the image size corresponding to the page image information, so that the page text information and the optimized image information are rendered to the current page, the page rendering efficiency can be improved, the loading speed of the page image is increased, the user impression is not influenced, and the user experience is considered.
In the embodiment, when a page loading request sent by target user equipment is received, the type of the target equipment corresponding to the target user equipment is detected according to the page loading request; inputting the type of the target equipment into a preset image proportion optimization model so that the preset image proportion optimization model outputs a target optimal proportion corresponding to the type of the target equipment; acquiring page text information and page image information corresponding to the page loading request; compressing the page image information according to the target optimal proportion to obtain optimized image information; rendering the page text information and the optimized image information to a current page. The target optimal proportion corresponding to the type of the target equipment is obtained through the model, and the page image information is compressed according to the target optimal proportion, so that the page rendering efficiency is improved under the condition of not reducing the image size, and the page loading speed and the user experience are considered.
Referring to fig. 3, fig. 3 is a flowchart illustrating a page rendering method based on machine learning according to a second embodiment of the present invention, and the second embodiment of the page rendering method based on machine learning according to the present invention is proposed based on the first embodiment illustrated in fig. 2.
In the second embodiment, before the step S10, the method for rendering a page based on machine learning further includes:
step S01: and acquiring a sample image type corresponding to the sample equipment type, and acquiring a sample compression ratio and a sample satisfaction corresponding to the sample image type.
It should be noted that, according to the device size, the user devices are divided into several types, such as large-scale devices, medium-scale devices, and small-scale devices, wherein the device sizes of the five device types are reduced in sequence; accordingly, as shown in table 1, images are classified into corresponding types according to image sizes, for example, a large image, a medium image, a small image, and a small image, which correspond to a large device, a medium device, and a small device, respectively, wherein the image sizes of the five image types are sequentially reduced.
Image grade
|
Minimum pixel
|
Maximum pixel
|
Large image
|
1920×1200
|
Is free of
|
Large and medium size images
|
1681×1051
|
1920×1200
|
Middle image
|
1025×769
|
1680×1050
|
Small and medium size images
|
257×257
|
1024×768
|
Small image
|
57×57
|
256×256 |
TABLE 1 Picture type Table
In a specific implementation, in order to obtain a preset image proportion optimization model through training, a sample image type corresponding to a sample device type is obtained, and a sample compression proportion and a sample satisfaction degree corresponding to the sample image type are obtained, so that the sample compression proportion and the sample satisfaction degree are used as training samples.
Step S02: and selecting the sample optimal proportion corresponding to the sample image type from the sample compression proportion according to the sample satisfaction degree.
It can be understood that fitting is carried out on the sample compression ratio and the sample satisfaction degree to obtain an objective optimization function; iterating the target optimization function by a gradient rise method to obtain the maximum value of the sample satisfaction degree; and taking the sample compression ratio corresponding to the maximum value of the sample satisfaction degree as the sample optimal ratio of the sample image type. The gradient ascent method is one of machine learning iterative methods, is a common method for solving an optimal value, and the calculation process is to find a maximum value along a certain direction, and the principle process is like going up a hill under a hill, and a higher position around the hill can be found, so that the hill can be reached all the way. The same is true of the principle of the gradient ascent method, which can be found by deriving the function, where a derivative of 0 is an extreme point in general. To optimize the problem of large oscillations present during training and to enable the training to converge, the learning rate is changed and the oscillations in the vertical direction are limited by the RMSprop optimizer using the root mean square on the gradient effect of weights and offsets, which maintains a moving average of the squared gradient of each weight and then divides the gradient by the square root of the average. Thus, the learning rate can be increased and the algorithm can take larger steps in the horizontal direction and converge faster.
Step S03: and obtaining a corresponding relation between the type of the sample equipment and the optimal proportion of the sample, and generating a preset image proportion optimization model according to the corresponding relation.
It should be noted that, after selecting the optimal sample proportion corresponding to the sample image type from the sample compression proportions according to the sample satisfaction, the corresponding relation between the sample device type and the optimal sample proportion is obtained according to the corresponding relation between the sample device type and the sample image type and the corresponding relation between the sample image type and the optimal sample proportion, and a preset image proportion optimization model is generated according to the corresponding relation between the sample device type and the optimal sample proportion.
In the embodiment, a sample image type corresponding to a sample equipment type is obtained, and a sample compression ratio and a sample satisfaction corresponding to the sample image type are obtained; selecting an optimal sample proportion corresponding to the sample image type from the sample compression proportions according to the sample satisfaction; and obtaining a corresponding relation between the type of the sample equipment and the optimal proportion of the sample, and generating a preset image proportion optimization model according to the corresponding relation. By iterating the sample compression ratio and the sample image type, the sample optimal ratio corresponding to the sample image type is obtained, so that the image can be compressed in the subsequent page rendering process, the rendering efficiency is improved, and the page loading speed is increased.
Referring to fig. 4, fig. 4 is a flowchart illustrating a page rendering method based on machine learning according to a third embodiment of the present invention, and the third embodiment of the page rendering method based on machine learning according to the present invention is proposed based on the second embodiment illustrated in fig. 3.
In a third embodiment, the iterating the objective optimization function by a gradient ascent method to obtain a maximum value of the sample satisfaction includes:
calculating function values of the target optimization function every other preset step length;
judging whether the difference value between the last function value and the current function value is greater than a preset threshold value or not;
if the difference value is larger than the preset threshold value, returning to the step of judging whether the difference value between the last function value and the current function value is smaller than the preset threshold value;
and if the difference is less than or equal to the preset threshold, determining that the current function value is the maximum value of the sample satisfaction degree.
It should be noted that the model is continuously trained according to the sample satisfaction and the sample compression ratio to finally obtain 5 types of sample optimal ratios, wherein the sample optimal ratio corresponding to the large image is 0.6, the sample optimal ratio corresponding to the large and medium images is 0.7, the sample optimal ratio corresponding to the medium image is 0.7, the sample optimal ratio corresponding to the small and medium images is 0.8, and the sample optimal ratio corresponding to the small image is 0.9. As shown in table 2, after the original image is compressed, the pixels of the image are obviously reduced, but the size of the optimized image is not changed, and the page text information and the optimized image information are rendered to the current page, so that the page rendering efficiency can be improved, the loading speed of the page image is increased, the user impression is not affected, and the user experience is considered. Therefore, the page rendering efficiency is improved under the condition that the image size is not reduced, and the page loading speed and the user experience are considered.
Image of a person
|
Pixel
|
Image size
|
Degree of satisfaction
|
Original image 1
|
3800*3800
|
13.1M
|
87%
|
Optimized image 1
|
2650*2650
|
7.86M
|
92%
|
Original image 2
|
1880*1675
|
7.27M
|
89%
|
Optimized image 2
|
1330*1135
|
5.09M
|
93%
|
Original image 3
|
376*381
|
420K
|
93%
|
Optimized image 3
|
326*330
|
378K
|
96% |
TABLE 2 Picture Pixel Change Table
Further, before the calculating the function value of the objective optimization function every preset step length, the page rendering method based on machine learning further includes:
obtaining an independent variable value range of the target optimization function, and taking the product of the independent variable value range and preset precision as a preset step length;
correspondingly, the calculating the function value of the target optimization function every preset step length specifically includes:
and calculating the function value of the target optimization function every preset step length in the independent variable value range.
It should be appreciated that the image will be scaled in order not to affect the user experience, where the scale ranges from [0, 1], 0 representing the lowest quality of the image, and 1 representing the image has not changed, to a scale before [0, 1] after machine learning according to the user's use of the device. Images of any width and height are downsampled using a minimum downsampling ratio without affecting the user experience. For example, 0.8 times the scale of the original image is commonly used for icons and logos, because for an originally small image, suddenly reducing the scale can cause image distortion to affect the user experience. The scale for large images is typically 0.6, which ensures that the resolution is maintained across different device types.
Further, the step S40 specifically includes:
step S401: and compressing the pixels of the page image information according to the target optimal proportion by a preset compression tool to obtain optimized image information.
It should be noted that the predetermined compression tool may be a data compression program (GNUzip, GZIP) or other compression tools, which is not limited in this embodiment. Due to the working mode of human eyes, all information of an image is not observed in observation, so that some information of partial pixels can be abandoned to reduce the file size of the image, and image optimization can be reduced to two standards: optimizing the number of bytes used for coding each image pixel and the optimized total number of pixels; the file size of an image is the product of the total number of pixels and the number of bytes used to encode each pixel. And compressing the pixels of the page image information according to the target optimal proportion so as to obtain optimized image information, reduce the size of the image and improve the page rendering efficiency and the page loading speed.
Further, the step S10 specifically includes:
when a page loading request sent by target user equipment is received, extracting target equipment information from the page loading request; and detecting the type of the target equipment corresponding to the target user equipment according to the target equipment information.
It can be understood that the page loading request is analyzed, target device information in the page loading request is extracted, a user agent is extracted from the target social security information, and a target device type corresponding to the target user device is detected according to the user agent.
In this embodiment, the function value of the objective optimization function is calculated by each preset step length; judging whether the difference value between the last function value and the current function value is greater than a preset threshold value or not; if the difference value is larger than the preset threshold value, returning to the step of judging whether the difference value between the last function value and the current function value is smaller than the preset threshold value; and if the difference is less than or equal to the preset threshold, determining that the current function value is the maximum value of the sample satisfaction degree. Through multiple iterations, the difference between adjacent function values is gradually reduced, when the difference is smaller than or equal to a preset threshold value, the maximum value of the sample satisfaction degree is obtained, the sample compression ratio corresponding to the maximum value of the sample satisfaction degree is used as the sample optimal ratio of the sample image type, the image of the sample image type is compressed through the sample optimal ratio, the image size is reduced, and the page rendering efficiency and the page loading speed can be improved.
In addition, an embodiment of the present invention further provides a storage medium, where a page rendering program based on machine learning is stored on the storage medium, and when executed by a processor, the page rendering program based on machine learning implements the following steps:
when a page loading request sent by target user equipment is received, detecting the type of the target equipment corresponding to the target user equipment according to the page loading request;
inputting the type of the target equipment into a preset image proportion optimization model so that the preset image proportion optimization model outputs a target optimal proportion corresponding to the type of the target equipment;
acquiring page text information and page image information corresponding to the page loading request;
compressing the page image information according to the target optimal proportion to obtain optimized image information;
rendering the page text information and the optimized image information to a current page.
Further, the machine learning based page rendering program when executed by the processor further performs the following operations:
acquiring a sample image type corresponding to a sample equipment type, and acquiring a sample compression ratio and a sample satisfaction degree corresponding to the sample image type;
selecting an optimal sample proportion corresponding to the sample image type from the sample compression proportions according to the sample satisfaction;
and obtaining a corresponding relation between the type of the sample equipment and the optimal proportion of the sample, and generating a preset image proportion optimization model according to the corresponding relation.
Further, the machine learning based page rendering program when executed by the processor further performs the following operations:
fitting the sample compression ratio and the sample satisfaction degree to obtain a target optimization function;
iterating the target optimization function by a gradient rise method to obtain the maximum value of the sample satisfaction degree;
and taking the sample compression ratio corresponding to the maximum value of the sample satisfaction degree as the sample optimal ratio of the sample image type.
Further, the machine learning based page rendering program when executed by the processor further performs the following operations:
calculating function values of the target optimization function every other preset step length;
judging whether the difference value between the last function value and the current function value is greater than a preset threshold value or not;
if the difference value is larger than the preset threshold value, returning to the step of judging whether the difference value between the last function value and the current function value is smaller than the preset threshold value;
and if the difference is less than or equal to the preset threshold, determining that the current function value is the maximum value of the sample satisfaction degree.
Further, the machine learning based page rendering program when executed by the processor further performs the following operations:
obtaining an independent variable value range of the target optimization function, and taking the product of the independent variable value range and preset precision as a preset step length;
correspondingly, the calculating the function value of the target optimization function every preset step length specifically includes:
and calculating the function value of the target optimization function every preset step length in the independent variable value range.
Further, the machine learning based page rendering program when executed by the processor further performs the following operations:
and compressing the pixels of the page image information according to the target optimal proportion by a preset compression tool to obtain optimized image information.
Further, the machine learning based page rendering program when executed by the processor further performs the following operations:
when a page loading request sent by target user equipment is received, extracting target equipment information from the page loading request;
and detecting the type of the target equipment corresponding to the target user equipment according to the target equipment information.
In the embodiment, when a page loading request sent by target user equipment is received, the type of the target equipment corresponding to the target user equipment is detected according to the page loading request; inputting the type of the target equipment into a preset image proportion optimization model so that the preset image proportion optimization model outputs a target optimal proportion corresponding to the type of the target equipment; acquiring page text information and page image information corresponding to the page loading request; compressing the page image information according to the target optimal proportion to obtain optimized image information; rendering the page text information and the optimized image information to a current page. The target optimal proportion corresponding to the type of the target equipment is obtained through the model, and the page image information is compressed according to the target optimal proportion, so that the page rendering efficiency is improved under the condition of not reducing the image size, and the page loading speed and the user experience are considered.
In addition, referring to fig. 5, an embodiment of the present invention further provides a page rendering apparatus based on machine learning, where the page rendering apparatus based on machine learning includes:
the request receiving module 10 is configured to detect a type of a target device corresponding to a target user device according to a page loading request when receiving the page loading request sent by the target user device.
It should be noted that the present embodiment divides the user equipment into several types according to the device size, such as a large-sized device, a medium-sized device, and a small-sized device, wherein the device sizes of the five device types are reduced in order.
In specific implementation, a User Agent User-Agent in header information of the page loading request is automatically analyzed, and a target device type corresponding to the target User device is obtained.
The ratio prediction module 20 is configured to input the type of the target device into a preset image ratio optimization model, so that the preset image ratio optimization model outputs a target optimal ratio corresponding to the type of the target device.
It can be understood that, in order to increase the page rendering speed, the embodiment reduces the page image information, and if the compression ratio is too small, for example, 0.1, the page image information lacks a large number of pixels, so that the image distortion is caused, and the user's impression is affected; if the compression ratio is too large, for example, 0.9, the difference between the file sizes occupied by the reduced page image and the file size occupied by the page image before reduction is small, so that the improvement degree of the page rendering speed is small, and therefore, the optimal ratio needs to be selected from a plurality of compression ratios.
In the specific implementation, because the image pixels of the large-scale device are higher and the image pixels of the small-scale device are lower, the compression ratio of the large-scale device can be smaller than that of the small-scale device under the condition that the user impression is not influenced, in order to obtain the optimal ratio of the user devices of various device types, the preset image ratio optimization model is adopted to train the compression ratio and the satisfaction degree, and thus the compression ratio with higher satisfaction degree, namely the optimal ratio, is obtained. The preset image proportion optimization model comprises a mapping relation between equipment types and optimal proportions, and the optimal proportions of the target corresponding to the target equipment types can be predicted according to the target equipment types.
The information obtaining module 30 is configured to obtain page text information and page image information corresponding to the page loading request.
It should be understood that the page content corresponding to the page loading request includes page text information and page image information, and the page text information and the page image information corresponding to the page loading request are obtained in advance for rendering the page content.
And the image compression module 40 is configured to compress the page image information according to the target optimal proportion to obtain optimized image information.
It should be noted that, compressing the page image information according to the target optimal proportion can reduce the image proportion corresponding to the page image information without affecting the look and feel of the user.
And a page rendering module 50, configured to render the page text information and the optimized image information to a current page.
It can be understood that the page image information is compressed, the pixels of the obtained optimized image information are smaller than the page image information, but the image size of the optimized image information is the same as the image size corresponding to the page image information, so that the page text information and the optimized image information are rendered to the current page, the page rendering efficiency can be improved, the loading speed of the page image is increased, the user impression is not influenced, and the user experience is considered.
In the embodiment, when a page loading request sent by target user equipment is received, the type of the target equipment corresponding to the target user equipment is detected according to the page loading request; inputting the type of the target equipment into a preset image proportion optimization model so that the preset image proportion optimization model outputs a target optimal proportion corresponding to the type of the target equipment; acquiring page text information and page image information corresponding to the page loading request; compressing the page image information according to the target optimal proportion to obtain optimized image information; rendering the page text information and the optimized image information to a current page. The target optimal proportion corresponding to the type of the target equipment is obtained through the model, and the page image information is compressed according to the target optimal proportion, so that the page rendering efficiency is improved under the condition of not reducing the image size, and the page loading speed and the user experience are considered.
In one embodiment, the machine learning based page rendering apparatus further includes:
the model building module is used for obtaining a sample image type corresponding to a sample equipment type, and obtaining a sample compression ratio and a sample satisfaction degree corresponding to the sample image type; selecting an optimal sample proportion corresponding to the sample image type from the sample compression proportions according to the sample satisfaction; and obtaining a corresponding relation between the type of the sample equipment and the optimal proportion of the sample, and generating a preset image proportion optimization model according to the corresponding relation.
In an embodiment, the model building module is further configured to fit the sample compression ratio and the sample satisfaction to obtain an objective optimization function; iterating the target optimization function by a gradient rise method to obtain the maximum value of the sample satisfaction degree; and taking the sample compression ratio corresponding to the maximum value of the sample satisfaction degree as the sample optimal ratio of the sample image type.
In an embodiment, the model building module is further configured to calculate a function value of the objective optimization function every preset step length; judging whether the difference value between the last function value and the current function value is greater than a preset threshold value or not; if the difference value is larger than the preset threshold value, returning to the step of judging whether the difference value between the last function value and the current function value is smaller than the preset threshold value; and if the difference is less than or equal to the preset threshold, determining that the current function value is the maximum value of the sample satisfaction degree.
In an embodiment, the model building module is further configured to obtain an independent variable value range of the target optimization function, and take a product of the independent variable value range and a preset precision as a preset step length; and calculating the function value of the target optimization function every preset step length in the independent variable value range.
In an embodiment, the image compression module 40 is further configured to compress the pixels of the page image information according to the target optimal proportion by using a preset compression tool, so as to obtain optimized image information.
In an embodiment, the request receiving module 10 is further configured to, when receiving a page loading request sent by a target user equipment, extract target device information from the page loading request;
and detecting the type of the target equipment corresponding to the target user equipment according to the target equipment information.
Other embodiments or specific implementation manners of the page rendering device based on machine learning according to the present invention may refer to the above method embodiments, and are not described herein again.
It should be noted that, in this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or system that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or system. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, method, article, or system that comprises the element.
The above-mentioned serial numbers of the embodiments of the present invention are merely for description and do not represent the merits of the embodiments. In the unit claims enumerating several means, several of these means may be embodied by one and the same item of hardware. The use of the words first, second, third and the like do not denote any order, but rather the words first, second and the like may be interpreted as indicating any order.
Through the above description of the embodiments, those skilled in the art will clearly understand that the method of the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but in many cases, the former is a better implementation manner. Based on such understanding, the technical solutions of the present invention or portions thereof that contribute to the prior art may be embodied in the form of a software product, where the computer software product is stored in a storage medium (e.g., a Read Only Memory (ROM)/Random Access Memory (RAM), a magnetic disk, an optical disk), and includes several instructions for enabling a terminal device (e.g., a mobile phone, a computer, a server, an air conditioner, or a network device) to execute the method according to the embodiments of the present invention.
The above description is only a preferred embodiment of the present invention, and not intended to limit the scope of the present invention, and all modifications of equivalent structures and equivalent processes, which are made by using the contents of the present specification and the accompanying drawings, or directly or indirectly applied to other related technical fields, are included in the scope of the present invention.