Main strategies of large-scale neural network for smartphone running

Source: Internet
Author: User

The computer has high-storage hard disks and powerful CPUs and GPUs. But the smartphone is not, and to compensate for this flaw, we need the skill to get the smartphone to run the deep learning application efficiently.

Introduced

Deep learning is an incredibly flexible and powerful technology, but running neural networks can require very large power in terms of computing and disk space requirements. This is usually not a problem that cloud space solves, and typically requires a drive running on a large hard disk server and multiple GPU modules.

Unfortunately, it's not easy to run a neural network on a mobile device. In fact, even if smartphones become more powerful, they still have limited computing power, battery life and free disk space, especially for applications that we want to keep as light as possible. This allows for faster download speeds, smaller update times, and longer battery life, which are appreciated by the user.

To perform image classification, portrait mode photography, text prediction, and dozens of other tasks, smartphones need to use tricks to quickly and accurately run a neural network without using too much disk space.

In this article, we will see some of the most powerful techniques to enable neural networks to run in real time on mobile phones.

Technology that makes neural networks smaller and faster

Basically, we are interested in three indicators: the accuracy of the model, the speed and the amount of space it occupies on the phone. There is no such thing as a free lunch, so we must make a compromise.

For most technologies, we will keep an eye on our indicators and look for what we call the saturation point. This is the moment when the yield of an indicator stops while other indicators are lost. By keeping the optimization value before the saturation point, we can get the best value.

In this case, we can significantly reduce the number of expensive operations without adding errors. However, near the saturation point, the error becomes too high to accept.

1. Avoid a fully connected layer

Fully connected layers are one of the most common components of neural networks that have ever created miracles. However, because each neuron is connected to all the neurons in the previous layer, they need to store and update many parameters. This is detrimental to speed and disk space.

A convolution layer is a layer that leverages local consistency (usually an image) in the input. Each neuron is no longer connected to all neurons in the previous layer. This helps to reduce the number of connections/weights while maintaining high accuracy.

Connections/weights in the fully connected layer are much more than the convolution layer.

Using a layer with little or no full connectivity can reduce the size of the model while maintaining high precision. This can improve speed and disk usage.

In the above configuration, there is a fully connected layer with 1024 inputs and 512 outputs, and this fully connected layer has approximately 500k parameters. If you have the same characteristics and 32 convolutional layer feature mappings, then it will only have 50K parameters, which is a 10 times-fold improvement!

2. Reduce the number of channels and kernel size

This step represents a very straightforward tradeoff between the complexity and speed of the model. There are many channels in the convolutional layer that allow the network to extract relevant information, but at a cost. Removing some of these features is an easy way to save space and make the model faster.

We can do the same thing with the accepted domain of the convolution operation. By reducing the kernel size, the convolution has less knowledge of local patterns, but fewer parameters are involved.

Smaller accepted area/kernel sizes are less expensive to calculate, but less information is conveyed.

In both cases, the number of map/kernel sizes is selected by looking at the saturation point so that the accuracy does not degrade too much.

3. Optimized reduction sampling (optimizing the downsampling)

For a fixed number of layers and a fixed number of pool operations, neural networks can behave very differently. This comes from the fact that the data and the calculated amount depend on the completion of the pool operation:

· The dimension of the data is reduced when the pooling operation is completed earlier. The smaller the dimension means that the faster the network is processed, but it means that the less information is, the worse the accuracy.

· When networked operations are completed late in the network, most of the information is retained for high accuracy. However, this also means that calculations are made on objects with many dimensions and are more expensive to compute.

· The uniform distribution of samples throughout the neural network provides a good balance between accuracy and speed, as an experience-efficient architecture.

Early pooling is fast, and late-stage pooling is accurate, and a homogeneous interval of pooling is a bit of both.

4. Trim weight (pruning the weights)

In the trained neural network, some weights play a strong role in the activation of neurons, while others have little effect on the results. Nevertheless, we still do some calculations on these weak weights.

Pruning is the process of completely removing the minimum magnitude connection so that we can skip the calculation. This may reduce accuracy, but make the network lighter and faster. We need to find the saturation point so as to remove as many connections as possible without unduly compromising accuracy.

Eliminate the weakest connections to save computational time and space.

5. Quantification weights (quantizing the weights)

In order to keep the network on disk, we need to record the value of each single weight in the network. This means that a floating-point number is saved for each parameter, which represents the amount of space occupied on the disk. As a reference, in C, a floating-point occupies 4 bytes, or 32 bits. A network with a parameter of hundreds of millions of (for example, google-net or VGG-16) can easily reach hundreds of megabytes, which is unacceptable on mobile devices.

One way to keep your network footprint as small as possible is by quantifying them to reduce the resolution of the weights. In this process, we change the representation of a number so that it no longer gains any value, but is quite limited to a subset of the values. This allows us to store only one quantization value and then refer to the weight of the network.

Quantize weights store keys instead of floating.

We will again determine how many values to use by looking at the saturation point. More values mean higher accuracy, but also larger storage space. For example, by using 256 quantization values, each weight can be referenced using only 1 bytes, or 8 bits. We have divided the size by 4 compared to the previous (32-bit)!

6. Representation of the encoding model

We've dealt with some things about weights, but we can further improve the network! This technique relies on the fact that the weights are unevenly distributed. Once quantified, we do not have the same number of weights to carry each quantization value. This means that in our model representation, some references will appear more frequently than other references, and we can use it!

Huffman coding is the perfect solution to this problem. It is achieved by attributing the minimum space-occupying key to the most commonly used value and the minimum space-consuming value. This helps to reduce the error of the model on the device, and the best result is no loss of precision.

The most frequent symbols use only 1 bits of space, and the least frequent use of 3 bits. This is balanced by the fact that the latter seldom appears in the representation.

This simple technique allows us to further reduce the space occupied by the neural network, usually around 30%.

Note: Quantization and encoding are different for each layer in the network, providing greater flexibility

7. Correction of accuracy loss (Correctiong the accuracy loss)

Using our technique, our neural network has become very rough. We removed the weak connection (trim) and even changed some weights (quantization). While this makes the network super lightweight and fast, it's not as accurate as it is.

To solve this problem, we need to retrain the network every step of the way. This simply means that after trimming or quantifying weights, we need to train the network again so that it adapts to the changes and repeats the process until the weight stops changing too much.

Conclusion

While smartphones do not have the disk space, computing power, or battery life of older desktop computers, they are still very good targets for deep learning applications. With a few tricks, and at the cost of a few percent accuracy, it is now possible to run powerful neural networks on these multifunctional handheld devices. This opens the door to thousands of exciting applications.

If you are still curious, see some of the best mobile-oriented neural networks, such as Squeezenet or mobilenets.

Main strategies of large-scale neural network for smartphone running

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.