WWDC16 simply finished and Apple left us with new astounding imaginative APIs. This year discourse acknowledgment, proactive applications, machine learning, client expectations, and neural systems have been the most successive terms utilized amid the gathering. In this way, other than another rich variant 3 of Swift, practically every new expansion to iOS, tvOS and macOS is connected with manmade brainpower. For instance, Metal and Accelerate in iOS 10 give an execution of convolutional neural systems (CNNs) for the GPU and CPU individually. Amid the keynote, Craig Federighi (Apple's SVP Software Engineering) indicated how the Photos application on iOS sorts out our photographs as per distinctive keen criteria. He featured that Photos application utilizes profound figuring out how to give such usefulness. Additionally, Federighi indicated how Siri, now accessible to engineers, can propose what we require.
Late advances in machine learning joined with the expansion of the GPU processing power and the reduction of their expenses can help us to play out the above characterization issue (and not just that) utilizing a unique sort of calculations known as Artificial Neural Networks (or in a matter of seconds, ANNs or NNs). An ANN is a numerical apparatus we can use to take care of the grouping issue in a practically programmed way. Neural systems are not new to established researchers and industry, but rather they were practically deserted, in view of the gigantic measure of calculations they required. At the point when the expenses of the Graphics Processing Units (GPUs) began to drop, researchers and engineers reevaluated neural systems. Particularly the work done amid the previous 4 or 5 years and the presentation of another kind of ANNs, known as Convolutional Neural Network (CNNs), has upheld the advancement of new applications in light of neural systems. This opened likewise another field of Machine Learning known as Deep Learning. The figure below highlights an ANN. For the moment, think of it as a black box. Later, we will see how the ANN looks like and how to implement it in Swift. Neural Network OverviewAs you can see in the above picture, the ANN has a single input (an image of a person) and 7 outputs. The number of inputs and outputs depends on the particular classification problem we want to solve. For each input image we provide to it, the neural network will tell us who the person in the image is. Of course, an ANN cannot be 100% accurate. Indeed, a neural network provides you with an estimation of the likelihood that the input image shows the person Steve. In the previous picture, this likelihood is represented by a number between zero (likelihood = 0%) and one (likelihood = 100%). How does the ANN compute this likelihood? It learns from data through a process known as training. In this process, we provide the ANN with labelled examples. For each labelled example, we force the ANN to adjust its internal states. The process works in the following way. You present a labelled image to the ANN. Then, the ANN computes the likelihood for each of its output. Now, if you provide an image of the person Steve, you would expect that the probability of the output “Steve” would be almost one, while the probability of the remaining outputs would be almost zero. However, since the ANN is starting to learn now and it really doesn’t know who Steve is, it can provide an erroneous result. So, we compute the error between the expected result (Steve = 1, other people = 0) and the actual result. Then, using an algorithm known as back propagation, we inject this error back in the ANN through its outputs. The error is then propagated back until it reaches the ANN’s input. The back-propagation process changes the internal states of the ANN. Once this is done, we present a new photo to the ANN and wait for the neural network to compute the new results. Then, we repeat this process many times until the output error does not change anymore. At that point, we say that the neural network has converged. We stop the training here and we collect the internal states (represented by a large data set of floating point numbers called weights - see later). This data set is what then we use in the final application. If you want to make your app able to classify images, sounds, or any type of digital signal, you need a neural network and the back-propagation algorithm. The back-propagation process is automatic, but it is very computational expensive and extensive. Here is where GPUs become really helpful. They can enormously reduce the training time. So, instead of spending days to train the neural network, you can use arrays of GPUs and reduce the training time to just few hours. Besides the processing time, you need to prepare many labelled samples. There are ways to generate these labelled samples automatically, but this is not always possible. So, in some cases you need to collect the data and then, manually label them one by one. These labeled data are also known as the training set. There are some studies about how large the training set should be to train a neural network, but I am not going to cover these details here. As I mentioned above, in iOS 10, macOS 10.12, and tvOS 10, the Metal and Accelerate frameworks will provide developers with an implementation of a Convolutional Neural Network. Unfortunately, the training algorithm will not be available. So, you would need to train your neural network using third-party tools or you have to develop them by yourself. You have different alternative solutions. For example, you can use TensorFlow from Google or Caffe from Berkley Vision and Learning Center. Other commercial or open-source solutions are also available on the market. INVASIVECODE, developed the training algorithms based on Metal and Accelerate framework. Additionally, because we are expert in computer vision and pattern recognition, we can preprocess your image or audio data and prepare them for the neural network. Our convolutional neural network supports iOS 8, iOS 9 and iOS 10. Neuron, Synapsis and LayerLet’s see the main components of an artificial neural network. For sure, the most important component is the Neuron or Node. An ANN can contain hundreds or thousands of neurons organized in Layers. Each neuron is connected to other neurons through Synapses or Connections. The following image highlights an ANN with four layers (L0, L1, L2, and L3). Example of a neural networkEach ANN can contain any number of layers and each layer can contain any number of neurons. The first layer (L0 in the previous figure) is known as the input layer. The last network layer (L3 in the previous figure) is the output layer. Additional layers between the input and output layers are known as hidden layers. The ANN represented in the previous figure is also a fully-connected neural network (FCNN), because each neuron of a hidden layer is connected with every neuron of the previous and next layers. FCNNs are convenient for practical implementations, but you can also have NN were each neuron is connected only to some of the neurons of the previous or next layer. Synapses and neurons apply transformations to the input data. The data flow from the input layer to the first hidden layer; then, from the the first hidden layer to the second hidden layer, and so on, until they reach the output layer. Each synapsis input is the output of a neuron. In the same way, the synapsis output becomes the input of a neuron. A synapsis multiplies its input for a value known as weight. Each connection has its own weight. During the neural network training process, the back-propagation algorithm modifies the value of each weight of each synapsis. Synapses can be implemented in Swift in a very simple way: struct Synapsis { var input: Double var weight: Double var output: Double { return input * weight } } Neurons perform two sequential operations on its inputs (see figure below):
A NeuronIf we want to build a neuron in Swift, it is very simple too: struct Neuron { var inputs: [Double] var output: Double { let sum = inputs.reduce(0, combine: +) //1 return activate(value: sum) //2 } func activate(value v: Double) -> Double { return 1.0 / (1.0 + exp(-v)) //2 } } Line 1 computes the sum of the neuron’s inputs. Instead of using an initial value zero, it is very common to use a value different from zero, known as the bias of the neuron. Line 2 applies the activation function to the previously computed sum. There are different types of activation functions proposed by scientists. In line 2, I am using a sigmoid function (see next figure). Sigmoid functionOther activation functions proposed in the literature are the hyperbolic tangent, the rectified linear unit (ReLU), the leaky rectified linear unit (leaky ReLU), the exponential linear unit (ELU). The following code snippet shows the implementation of the most important activation functions: enum ActivationFunction { case sigmoid case tanh case reLU case leakyReLU case eLU } func activate(value v: Double, using activationFunction: ActivationFunction) -> Double { switch activationFunction { case .sigmoid: return 1.0 / (1.0 + exp(-v)) case .tanh: return tanh(v) case .reLU: return max(0.0, v) case .leakyReLU: return max(0.01 * v, v) case .eLU: return (v > 0) ? v : 0.01*(exp(v) - 1.0) } } With some little extra code you can have a fully functional neural network. ApplicationsSo, what can you do with an artificial neural network? The number of applications is enormous. If you think carefully about the classification problem I described above, you will find out that this type of issues are very frequent in many applications. For example, face recognition is a classification problem. Or, if you want to let the machine understand your mood just looking at your facial expression, this is also a classification problem. Another typical application is handwriting recognition. Navigation assistance algorithms use CNNs to decide if the object moving in front of the car is a pedestrian or another car. Neural networks are used nowadays in many fields: military, health, social, risk management, traffic, entertainment and so on. ConclusionsMachine learning and computer vision open new kind of applications for iOS, tvOS and macOS devices. Smarter, more user-friendly and convenient applications are already starting to appear on mobile devices. But we are just at the beginning. And to make it even more convenient for you, we have developed preprocessing and training algorithms that will be available for purchase very soon. Stay tuned! SOURCE : https://www.invasivecode.com -SHREETHAANU Leave a Reply. |
|
Photo used under Creative Commons from nan palmero