Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand the Fast Migration style in Android

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains "how to understand the fast migration style in Android". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to understand the fast migration style in Android".

Effect.

Shortcoming

1. No componentization

two。 No confusion.

3. There are some places that are not abstract enough.

Deep Learning and the basic concept of Neural Network what is Deep Learning

1. Deep learning, the first three concepts are progressive. To put it simply, deep learning is a kind of machine learning. Deep learning is the use of machines to learn a lot of data, and machine learning is a way to achieve AI.

two。 There are two important things in deep learning: data and neural networks. There are two important processes in deep learning: training and testing. Data and network: 1. Data: we imagine a simple picture classification scene. We have 10000 pictures that have been manually classified, and each picture has a correct classification, such as cats, dogs and so on. two。 Network: we can imagine the neural network here as a function, our input is a picture, and the output is the score of the picture under each category. That is, an array of scores. two。 Training and testing: 1. Training: during the training, we will input the pictures in the picture set into the neural network again and again, and then get the score of the picture under each category again and again. Whenever we get a score array, we can calculate the loss value of the current neural network (the higher the accuracy of the current network, the lower the loss value). With the loss value, our goal is to reduce the loss value. Students who know the derivative know that we can get the gradient direction to reduce the loss value by deriving the loss value function, and then feed it back to the neural network. This cycle after cycle, so that the loss value to a minimum. two。 Test: when we train the neural network to the best state, we can input the pictures that we need to classify into the neural network, and get the final result of the neural network classification of the picture. 3. Conclusion: how on earth do you learn in depth? We can see that our training data are processed by people, so the process of deep learning is to solidify the human processing process into our neural network, and finally let the neural network replace the manual processing process. 4. The above is just an introduction to the basic process of in-depth learning. If you want to learn more, you can read this blog.

What is a neural network?

As we mentioned in the previous section, the process of processing data is eventually solidified into the neural network through our training. Now I will briefly introduce the neural network mentioned above.

1. Or in a simple picture classification scene: 1. Let's assume that the size of the picture is 100x100 (we tile the picture into a 1 * 10000 matrix). There are a total of 10 categories. two。 Then a two-layer neural network is like this: y = x * W1 * W2 (W1 is the matrix of 10000 * a, W2 is the matrix of a * 10), where the final y is the score of a picture under each category, and the multiplication in the formula is matrix multiplication. 3. Of course, a neural network with more layers has more w, and an in our W1 and W2 can be defined by ourselves.

two。 Explain y = x * W1 * W2: 1. Studies have shown that when we look at the picture x, we first look at the outline of the picture, where the neurons in our brain looking at the outline of the picture are equivalent to W12. After looking at the outline, we will have a basic sense of what is in this picture and determine which category the picture belongs to. The category here is x * W1. The result in 3.2 will be input into the neurons in the middle and lower layer of the brain. The neuron here is equivalent to W2, and after W2, we will output a result here is y. 4. Of course, there are far more layers of neurons in people than mentioned above.

3. The process of training y = x * W1 * w2 is equivalent to human comparison: we have a bunch of pictures for a child who doesn't know anything. At first, he is sure that the output is wrong, but every time we correct his mistake, then the neurons (w) in his head will be constantly modified and the recognition accuracy will continue to improve.

Tensorflow in Android

This section will describe how to use trained neural networks in Android

Start

In this article, I will only use one demo as an example, and the MyPhotoShop project mentioned earlier will be analyzed by another topic.

1.demo address: github address (https://github.com/whenSunSet/TensorflowPureDemo)

two。 Introduction of Tensorflow:compile 'org.tensorflow:tensorflow-android:+'

Concepts in Tensorflow

1. Graph (graph): we explained what a neural network looks like. In Tensorflow, each neuron w of the neural network belongs to a node in the graph, and all the nodes of the neural network form a directed acyclic graph, that is, a part of the Tensorflow graph. Of course, in addition to the nodes of the neural network, there are other auxiliary operations in the Tensorflow diagram, such as image decoding, image coding, image preprocessing and so on. Let's give an example of a graph: picture a muri-"decoding picture production bmurf -" processing b produces picture data matrix c (1 * 10000)-"c multiplies w1 (10000 * x) matrix to produce d (1 * x) -" d multiplies w2 (x * 10) matrix to produce e (1 * 10)-- selects the category with the highest e median value, and the neural network determines that picture an is the picture of this classification.

two。 Node: each node is part of the graph, and each node has: input parameters, output parameters, specific operation functions (such as matrix multiplication), and possibly a neuron value w.

3.TensorFlowInferenceInterface: a context trained in Tensorflow with different names in different languages. It contains all the examples needed in a training session.

Demo code explanation

Our demo only deals with the use of Tensorflow neural network model in Android, not the training process. There are two reasons: 1. The mobile end is not suitable for training neural network 2.Tensorflow for Android without trained API.

1. The neural network I use this time is a trained fast style transfer network.

two。 For the model, our input is: a picture is converted into a float type tensor with a size of (1 * 800 * 600 * 3), and the name of the input node is padsss:0, which is defined during the training process.

3. For this model, our output is a float type tensor of size (1 * 780x680x3). The name of the output node is squeezesss:0, which is also defined during the training process.

4. Let's look at the code. First, we use RxPermission to get the permission. After obtaining the success, we write the pictures that need to be processed in assets to the SD card for later use, and enter the make () method.

5. Read the pictures in 4 into memory

6. Take ARGB as an example, we know that each pixel in Bitmap is stored in int hexadecimal, similar to this form of FFFFFFFF, then every two bits is a channel value, the upper limit is 256. So the next step is to convert the pixel values in Bitmap into an array of type float, and the array size is (800x600x3).

7. A TensorFlowInferenceInterface object is created, and the input parameters are AssetManager and model file, which means that the neural network is set up in memory.

8. Output the name of each node

9. Input the name of the input node, the data of the input node, and the dimension of the data tensor to the neural network

10. To run the neural network, the input parameter is the name of the output node

11. The operation of the neural network is blocked, so after running well, you can get the data, which is stored in the float array.

twelve。 Reassemble the float array into the pixel values of Bitmap, which are then written into Bitmap.

Pay attention

1.demo will be slow to run. Wait patiently.

two。 The devices I run are: Xiaomi mix2, Android8.0. Other devices may have problems, either very slow, or not supported by cpu or the system version.

Thank you for your reading, the above is the content of "how to understand the fast migration style in Android". After the study of this article, I believe you have a deeper understanding of how to understand the rapid migration style in Android, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report