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

What is convolution neural network LeNet

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly introduces "what is convolution neural network LeNet". In daily operation, I believe that many people have doubts about what is convolution neural network LeNet. The editor consulted all kinds of data and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "what is convolution neural network LeNet"! Next, please follow the editor to study!

Catalogue

LeNet

Model training

In this section, we will introduce LeNet, one of the earliest released convolution neural networks. The model was proposed (and named after) by Yann LeCun, a researcher at AT&T Bell Laboratories, in 1989 to recognize handwritten numbers. At that time, LeNet achieved results comparable to the performance of support vector machine, and became the mainstream method of supervised learning. LeNet is widely used in ATMs to help identify the numbers that process checks.

LeNet

Overall, LeNet (LeNet-5) consists of two parts:

Convolutional encoder: composed of two convolution layers

Full connection layer dense and fast: composed of three full connection layers

The basic units in each convolution block are a convolution layer, an sigmoid activation function, and an average pooling layer. Here, although ReLU and the maximum pooling layer are more efficient, they did not appear in the 1990s. Each convolution layer uses a 5 × 5 5\ times5 5 × 5 convolution kernel and a sigmoid activation function. These layers map inputs to multiple 2D feature outputs, usually increasing the number of channels at the same time. The first convolution layer has 6 output channels, while the second convolution layer has 16 output channels. Each 2 × 22\ times2 2 × 2 pool operation reduces the dimension by 4 times through spatial downsampling.

In order to pass the output from the convolution block to the dense block, we must level each sample in a small batch. LeNet's dense Fast has three fully connected layers with 120,84 and 10 outputs, respectively. Because we are still performing classification, the 10 dimensions of the output layer correspond to the number of final output results.

Through the following LeNet code, we will believe that the deep learning framework is very easy to implement such a model. All we need to do is instantiate a Sequential block and wire together the layers we need.

Import torchfrom torch import nnfrom d21 import torch as d2lclass Reshape (torch.nn.Module): def forward (self, x): return x.view (- 1,1,28,28) net = torch.nn.Sequential (Reshape (), nn.Conv2d (1,6, kernel_size=5, padding=2), nn.Sigmoid (), nn.AvgPool2d (kernel_size=2, stride=2), nn.Conv2d (6,16, kernel_size=5), nn.Sigmoid () Nn.AvgPool2d (kernel_size=2, stride=2), nn.Flatten (), nn.Linear (16 * 5 * 5120), nn.Sigmoid (), nn.Linear (120,84), nn.Sigmoid (), nn.Linear (84,10))

We made a small change to the original model to remove the Gaussian activation at the last layer. In addition, this network is consistent with the original LeNet-5. Next, we pass a single-channel (black and white) image with a size of 28 × 28 28\ times28 28 × 28 through LeNet. By printing the shape of the output at each layer, we can check the model to make sure that its operation is consistent with what we expect from the following image.

X = torch.rand (size= (1,1,28,28), dtype=torch.float32) for layer in net: X = layer (X) print (layer.__class__.__name__, 'output shape:\ tasking, X.shape) Reshape output shape: torch.Size ([1,1,28,28]) Conv2d output shape: torch.Size ([1,6,28,28]) Sigmoid output shape: torch.Size ([1,6,28]) 28]) AvgPool2d output shape: torch.Size ([1,6,14,14]) Conv2d output shape: torch.Size ([1,16,10,10]) Sigmoid output shape: torch.Size ([1,16,10,10]) AvgPool2d output shape: torch.Size ([1,16,5,5]) Flatten output shape: torch.Size ([1,400]) Linear output shape: torch.Size ([1,120]) Sigmoid output shape: torch.Size ([1,120]) Linear output shape: torch.Size ([1,120]) 84]) Sigmoid output shape: torch.Size ([1,84]) Linear output shape: torch.Size ([1,10])

Notice that throughout the convolution block, the height and width of each layer feature is reduced compared to the previous layer. The first convolution layer is filled with 2 pixels to compensate for the feature reduction caused by the 5 × 5 convolution core. In contrast, the second convolution layer is not filled, so the height and width are reduced by 4 pixels. As the cascading rises, the number of channels increases from 1 at input to 6 after the first convolution layer, and then to 16 after the second convolution layer. At the same time, the height and width of each convergence layer are halved. Finally, each fully connected layer reduces dimensions and finally outputs an output that matches the number of categories of the results.

Model training

Now that we have implemented LeNet, let's look at the performance of LeNet on the Fashion-MNIST dataset.

Batch_size = 256train_iter, test_iter = d2l.load_data_fashion_mnist (batch_size = batch_size)

Although convolution neural networks have fewer parameters, compared with depth multilayer perceptrons, their computational cost is still very high, because each parameter is involved in more multiplication.

If we have a chance to use GPU, we can use it to speed up training.

At this point, the study of "what is convolution neural network LeNet" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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