{"id":170478,"date":"2026-02-19T14:55:52","date_gmt":"2026-02-19T13:55:52","guid":{"rendered":"https:\/\/liora.io\/en\/?p=170478"},"modified":"2026-02-19T14:55:53","modified_gmt":"2026-02-19T13:55:53","slug":"convolutional-neural-network-everything-you-need-to-know","status":"publish","type":"post","link":"https:\/\/liora.io\/en\/convolutional-neural-network-everything-you-need-to-know","title":{"rendered":"Convolutional Neural Network: Everything You Need to Know"},"content":{"rendered":"<p><strong>In this section, we will focus on one of the most powerful algorithms in Deep Learning: Convolutional Neural Networks (CNNs). These are powerful programming models that enable image recognition, in particular, by automatically assigning a label to each image provided as input, corresponding to the class to which it belongs.<\/strong><\/p>\n<!-- \/wp:post-content -->\n\n<!-- wp:paragraph -->\n<p>Welcome to the third episode of our Deep Learning series. After introducing Deep Learning and its applications in the first part, and diving into the structure and operation of <a href=\"https:\/\/liora.io\/en\/recurrent-neural-network-what-is-it\">neural networks<\/a> in the second, let&#8217;s continue our journey!<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:embed {\"url\":\"https:\/\/youtu.be\/ugALxRuTh00\",\"type\":\"video\",\"providerNameSlug\":\"youtube\",\"responsive\":true,\"className\":\"wp-embed-aspect-16-9 wp-has-aspect-ratio\"} -->\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\">\n  <div class=\"wp-block-embed__wrapper\">\n<iframe title=\"The different roles in Data Science - Data Scientest\" width=\"500\" height=\"281\" src=\"https:\/\/www.youtube.com\/embed\/ugALxRuTh00?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n  <\/div>\n<\/figure>\n<!-- \/wp:embed -->\n\n<!-- wp:image {\"linkDestination\":\"custom\",\"align\":\"center\"} -->\n\n<!-- \/wp:image -->\n\n<!-- wp:heading -->\n<h2 id=\"h-what-are-the-main-applications-for-cnns\" class=\"wp-block-heading\">What are the main applications for CNNs?<\/h2>\n<!-- \/wp:heading -->\n\n<!-- wp:paragraph -->\n<p>A<strong> convolutional neural network<\/strong> draws inspiration from nature, as the connectivity between artificial neurons resembles the organization of the animal visual cortex. One of its primary use cases is image recognition.<strong> Convolutional networks<\/strong> learn faster and achieve lower error rates in this domain. They are also used, to a lesser extent, for video analysis. This type of network is employed in natural language processing as well. CNN models are highly effective for semantic analysis, sentence modeling, classification, and translation.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:paragraph -->\n<p>Compared to traditional methods like recurrent neural networks, convolutional neural networks can represent different contextual realities of language without relying on a sequential assumption. Convolutional networks have also been applied in drug discovery. They aid in identifying potential treatments by predicting interactions between molecules and biological proteins. CNNs have notably been used in game software for Go and chess, where they can excel. Another application is anomaly detection in input images.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:heading -->\n<h2 id=\"h-convolutional-neural-network-cnn-architecture\" class=\"wp-block-heading\">Convolutional Neural Network-CNN architecture<\/h2>\n<!-- \/wp:heading -->\n\n<!-- wp:quote -->\n<blockquote class=\"wp-block-quote\"><!-- wp:paragraph -->\n<p><strong>Convolutional Neural Networks (CNNs)<\/strong><a href=\"https:\/\/liora.io\/en\/deep-neural-network-what-is-it-and-how-is-it-working\"> constitute a subcategory of neural networks<\/a> and are currently one of the most renowned models for image classification due to their exceptional performance.<\/p>\n<!-- \/wp:paragraph --><\/blockquote>\n<!-- \/wp:quote -->\n\n<!-- wp:paragraph -->\n<p>Their mode of operation may seem simple at first glance: the user provides an input image in the form of a pixel matrix. This image has three dimensions:<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:paragraph -->\n<p>Two dimensions for a grayscale image.<br>A third dimension with a depth of 3 to represent the fundamental colors (Red, Green, Blue).<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:paragraph -->\n<p>Unlike a standard Multi-Layer Perceptron (MLP) model, which contains only a classification part, the architecture of the Convolutional Neural Network has two distinct parts:<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:paragraph -->\n<p><strong>1. Convolutional Part: I<\/strong>ts ultimate goal is to extract specific features from each image by compressing them to reduce their initial size. In summary, the input image goes through a series of filters, creating new images called convolution maps. Finally, the obtained convolution maps are concatenated into a feature vector called the CNN code.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:paragraph -->\n<p><strong>2. Classification Part:<\/strong> The CNN code obtained as the output of the convolutional part is fed into a second part, consisting of fully connected layers called a Multi-Layer Perceptron (MLP). The role of this part is to combine the features of the CNN code to classify the image. For more information on this part, feel free to refer to the article on the subject.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:heading -->\n<h3 id=\"h-convolution-part-what-is-convolution-used-for\" class=\"wp-block-heading\">Convolution part: What is convolution used for?<\/h3>\n<!-- \/wp:heading -->\n\n<!-- wp:heading {\"level\":3} -->\n<h4 id=\"h-first-of-all-what-is-convolution-used-for\" class=\"wp-block-heading\">First of all, what is convolution used for?<\/h4>\n<!-- \/wp:heading -->\n\n<!-- wp:paragraph -->\n<p>Convolution is a simple mathematical operation generally used for image processing and recognition. Its effect on an image is similar to filtering, which works as follows:<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:image {\"linkDestination\":\"custom\",\"style\":{\"spacing\":{\"margin\":{\"top\":\"var:preset|spacing|columns\",\"bottom\":\"var:preset|spacing|columns\"}}}} -->\n<figure class=\"wp-block-image\" style=\"margin-top:var(--wp--preset--spacing--columns);margin-bottom:var(--wp--preset--spacing--columns)\"><a href=\"https:\/\/www.natural-solutions.eu\/blog\/la-reconnaissance-dimage-avec-les-rseaux-de-neurones-convolutifs#:~:text=Qu'est%2Dce%20que%20la,%C3%A0%20la%20reconnaissance%20d'image.\"><img decoding=\"async\" src=\"https:\/\/liora.io\/app\/uploads\/sites\/9\/2023\/09\/Fichier-98.png\" alt=\"\"><\/a><figcaption class=\"wp-element-caption\">Diagram of how the filter window moves across the image<\/figcaption><\/figure>\n<!-- \/wp:image -->\n\n<!-- wp:paragraph -->\n<p><\/p><p>Initially, you define the size of the filter window, typically starting from the top-left corner.<br><\/p><p>The filter window, representing a feature, moves progressively from left to right by a predetermined number of cells (the stride) until it reaches the end of the image.<\/p>For each encountered portion of the image, a convolution calculation is performed, resulting in an output activation map or feature map that indicates where the features are located in the image. The higher the value in the feature map, the more the scanned portion of the image resembles the feature being sought. This process helps CNNs identify meaningful patterns and features within the input image.<p><\/p><p><\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:heading {\"level\":3} -->\n<h4 id=\"h-example-of-a-classical-convolution-filter\" class=\"wp-block-heading\">Example of a classical convolution filter<\/h4>\n<!-- \/wp:heading -->\n\n<!-- wp:paragraph -->\n<p>During the<strong> convolutional part of a Convolutional Neural Network<\/strong>, the input image passes through a sequence of convolution filters. For example, there are commonly used convolution filters that are designed to extract more meaningful features than individual pixels, such as edge detection (derivative filter) or geometric shape detection. The choice and application of these filters are automatically determined by the model.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:paragraph -->\n<p>Among the most well-known filters are the averaging filter (which computes the average of each pixel with its 8 neighboring pixels) and the Gaussian filter (which is used to reduce noise in an input image). Here&#8217;s an example of the effects of these two different filters on an image with significant noise (imagine a photograph taken in low light conditions, for example). However, one drawback of noise reduction is that it often comes with a reduction in sharpness.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:image {\"width\":\"auto\",\"height\":\"400px\",\"align\":\"center\",\"style\":{\"spacing\":{\"margin\":{\"top\":\"var:preset|spacing|columns\",\"bottom\":\"var:preset|spacing|columns\"}}}} -->\n<figure class=\"wp-block-image aligncenter is-resized\" style=\"margin-top:var(--wp--preset--spacing--columns);margin-bottom:var(--wp--preset--spacing--columns)\"><img decoding=\"async\" src=\"https:\/\/liora.io\/app\/uploads\/sites\/9\/2023\/09\/CNN-4.png\" alt=\"\" style=\"width:auto;height:400px\"><figcaption class=\"wp-element-caption\">Effect of averaging and Gaussian filters &#8211; Liora<\/figcaption><\/figure>\n<!-- \/wp:image -->\n\n<!-- wp:paragraph -->\n<p>As you can see, unlike the averaging filter, the Gaussian filter reduces noise without significantly reducing sharpness.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:paragraph -->\n<p>In addition to its filtering function, the convolutional part of a CNN is valuable because it extracts features unique to each image while compressing them to reduce their initial size, using subsampling methods like Max-Pooling.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:buttons {\"className\":\"is-layout-flex wp-block-buttons-is-layout-flex is-content-justification-center\",\"layout\":{\"type\":\"flex\",\"justifyContent\":\"center\"}} -->\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex is-content-justification-center\"><!-- wp:button -->\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link wp-element-button\" href=\"https:\/\/liora.io\/en\/courses\/data-ai\/data-scientist\">Become a Data Scientist<\/a><\/div>\n<!-- \/wp:button --><\/div>\n<!-- \/wp:buttons -->\n\n<!-- wp:heading -->\n<h3 id=\"h-sub-sampling-method-max-pooling\" class=\"wp-block-heading\">Sub-sampling method: Max-Pooling<\/h3>\n<!-- \/wp:heading -->\n\n<!-- wp:paragraph -->\n<p><strong>Max-Pooling<\/strong> is a subsampling process based on sampling. Its goal is to downsample an input representation (image, hidden layer output matrix, etc.) by reducing its dimension. Additionally, it reduces computational cost by reducing the number of parameters to learn and provides invariance to small translations (if a small translation does not change the maximum value in the sampled region, the maximum value in each region will remain the same, and therefore, the newly created matrix will remain identical).<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:paragraph -->\n<p>To make the action of Max-Pooling more concrete, let&#8217;s consider an example: imagine we have a 4&#215;4 matrix representing our initial input and a 2&#215;2 window filter that we apply to our input. For each of the regions scanned by the filter, Max-Pooling takes the maximum value, thus creating a new output matrix where each element corresponds to the maximum value in each encountered region.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:paragraph -->\n<p>Let&#8217;s illustrate the process:<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:image {\"linkDestination\":\"custom\",\"style\":{\"spacing\":{\"margin\":{\"top\":\"var:preset|spacing|columns\",\"bottom\":\"var:preset|spacing|columns\"}}}} -->\n<figure class=\"wp-block-image\" style=\"margin-top:var(--wp--preset--spacing--columns);margin-bottom:var(--wp--preset--spacing--columns)\"><a href=\"https:\/\/cs231n.github.io\/convolutional-networks\/\"><img decoding=\"async\" src=\"https:\/\/liora.io\/app\/uploads\/sites\/9\/2023\/09\/Fichier-97.png\" alt=\"\"><\/a><figcaption class=\"wp-element-caption\">Max-Pooling process<\/figcaption><\/figure>\n<!-- \/wp:image -->\n\n<!-- wp:paragraph -->\n<p>The filter window moves two pixels to the right (stride\/step = 2) and at each step retrieves the &#8220;argmax&#8221; corresponding to the largest of the 4 pixel values.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:image {\"linkDestination\":\"custom\",\"align\":\"center\",\"style\":{\"spacing\":{\"margin\":{\"top\":\"var:preset|spacing|columns\",\"bottom\":\"var:preset|spacing|columns\"}}}} -->\n<figure class=\"wp-block-image aligncenter\" style=\"margin-top:var(--wp--preset--spacing--columns);margin-bottom:var(--wp--preset--spacing--columns)\"><a href=\"https:\/\/cs231n.github.io\/convolutional-networks\/\"><img decoding=\"async\" src=\"https:\/\/liora.io\/app\/uploads\/2020\/06\/Fichier-96.png\" alt=\"\" title=\"\"><\/a><figcaption class=\"wp-element-caption\">Example of the effect of Max-Pooling<\/figcaption><\/figure>\n<!-- \/wp:image -->\n\n<!-- wp:paragraph -->\n<p>The purpose of the convolutional part of a CNN becomes clearer: unlike a traditional MLP model, adding the convolutional part upstream allows us to obtain an output &#8220;feature map&#8221; or &#8220;CNN code&#8221; (the pixel matrix on the right in the example) with smaller dimensions than those of the original image. This significantly reduces the number of parameters to be computed in the model.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:heading {\"level\":3} -->\n<h3 id=\"h-example-of-a-cnn-architecture-and-its-output\" class=\"wp-block-heading\">Example of a CNN architecture and its output<\/h3>\n<!-- \/wp:heading -->\n\n<!-- wp:paragraph -->\n<p>After the convolutional part of a CNN comes the classification part. This classification part, common to all neural network models, corresponds to a Multi-Layer Perceptron (MLP) model.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:paragraph -->\n<p>Its goal is to assign a label describing its class membership to each data sample.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:image {\"linkDestination\":\"custom\",\"style\":{\"spacing\":{\"margin\":{\"top\":\"var:preset|spacing|columns\",\"bottom\":\"var:preset|spacing|columns\"}}}} -->\n<figure class=\"wp-block-image\" style=\"margin-top:var(--wp--preset--spacing--columns);margin-bottom:var(--wp--preset--spacing--columns)\"><a href=\"https:\/\/www.natural-solutions.eu\/blog\/histoire-du-deep-learning#:~:text=Les%20perceptrons%20multicouches%3A%20MLP%20(1986)&amp;text=Les%20perceptrons%20multicouches%20ont%20pour,mieux%20cette%20base%20de%20donn%C3%A9es.\"><img decoding=\"async\" src=\"https:\/\/liora.io\/app\/uploads\/sites\/9\/2023\/09\/Fichier-95.png\" alt=\"\"><\/a><figcaption class=\"wp-element-caption\">Representation of a multilayer perceptron<\/figcaption><\/figure>\n<!-- \/wp:image -->\n\n<!-- wp:paragraph -->\n<p>The algorithm that perceptrons use to update their weights (or network coefficients) is called backpropagation of the error gradient, a famous gradient descent algorithm that we will delve into in more detail later on.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:image {\"linkDestination\":\"custom\",\"style\":{\"spacing\":{\"margin\":{\"top\":\"var:preset|spacing|columns\",\"bottom\":\"var:preset|spacing|columns\"}}}} -->\n<figure class=\"wp-block-image\" style=\"margin-top:var(--wp--preset--spacing--columns);margin-bottom:var(--wp--preset--spacing--columns)\"><a href=\"http:\/\/dspace.univ-tlemcen.dz\/bitstream\/112\/12235\/1\/Classification-des-images-avec-les-reseaux-de-neurones.pdf\"><img decoding=\"async\" src=\"https:\/\/liora.io\/app\/uploads\/sites\/9\/2023\/09\/convolution-pooling.png\" alt=\"\"><\/a><figcaption class=\"wp-element-caption\">Example of a CNN architecture<\/figcaption><\/figure>\n<!-- \/wp:image -->\n\n<!-- wp:paragraph -->\n<p>Generally, the architecture of a Convolutional Neural Network is quite similar:<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:paragraph -->\n<p><strong>1. Convolutional Layer (CONV):<\/strong> The role of this first layer is to analyze the input images and detect the presence of a set of features. It produces a set of feature maps as output (as explained earlier: what is the purpose of convolution?).<br><strong>2. Pooling Layer (POOL):<\/strong> The pooling layer is typically applied between two convolutional layers. It takes the feature maps generated by the convolutional layer as input and aims to reduce the size of the images while preserving their essential characteristics. Among the most commonly used pooling methods are max-pooling (mentioned earlier) and average pooling, which calculates the average value of the filter window at each step.<br><strong>3. Rectified Linear Units (ReLU) Activation Layer:<\/strong> This layer replaces all negative input values with zeros. The purpose of these activation layers is to make the model nonlinear and, therefore, more complex.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:paragraph -->\n<p>The final output of the pooling layer retains the same number of feature maps as input but in a considerably compressed form.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:image {\"width\":\"auto\",\"height\":\"400px\",\"linkDestination\":\"custom\",\"align\":\"center\",\"style\":{\"spacing\":{\"margin\":{\"top\":\"var:preset|spacing|columns\",\"bottom\":\"var:preset|spacing|columns\"}}}} -->\n<figure class=\"wp-block-image aligncenter is-resized\" style=\"margin-top:var(--wp--preset--spacing--columns);margin-bottom:var(--wp--preset--spacing--columns)\"><a href=\"https:\/\/ml4a.github.io\/ml4a\/fr\/neural_networks\/\"><img decoding=\"async\" src=\"https:\/\/liora.io\/app\/uploads\/sites\/9\/2023\/09\/CNN-9.png\" alt=\"\" style=\"width:auto;height:400px\"><\/a><figcaption class=\"wp-element-caption\">ReLU activation function<\/figcaption><\/figure>\n<!-- \/wp:image -->\n\n<!-- wp:list -->\n<ul class=\"wp-block-list\"><!-- wp:list-item -->\n<li><strong>Fully Connected (FC) Layer:<\/strong> These layers are placed at the end of the CNN architecture and are fully connected to all output neurons (hence the term fully-connected). After receiving an input vector, the FC layer applies a linear combination followed by an activation function, ultimately aiming to classify the input image (see the following diagram). In the end, it outputs a vector of size d, corresponding to the number of classes, where each component represents the probability of the input image belonging to a class.<\/li>\n<!-- \/wp:list-item --><\/ul>\n<!-- \/wp:list -->\n\n<!-- wp:image {\"width\":\"auto\",\"height\":\"400px\",\"align\":\"center\",\"style\":{\"spacing\":{\"margin\":{\"top\":\"var:preset|spacing|columns\",\"bottom\":\"var:preset|spacing|columns\"}}}} -->\n<figure class=\"wp-block-image aligncenter is-resized\" style=\"margin-top:var(--wp--preset--spacing--columns);margin-bottom:var(--wp--preset--spacing--columns)\"><img decoding=\"async\" src=\"https:\/\/liora.io\/app\/uploads\/sites\/9\/2023\/09\/CNN-10.png\" alt=\"\" style=\"width:auto;height:400px\"><figcaption class=\"wp-element-caption\">Operation of a neural network with 2 hidden layers<\/figcaption><\/figure>\n<!-- \/wp:image -->\n\n<!-- wp:heading -->\n<h2 id=\"h-implementation-of-a-pre-trained-cnn-on-python\" class=\"wp-block-heading\">Implementation of a pre-trained CNN on Python :<\/h2>\n<!-- \/wp:heading -->\n\n<!-- wp:paragraph -->\n<p>For practical purposes and given the complexity of creating effective CNNs from scratch, we will use pre-trained networks available in the Torchvision module. Let&#8217;s see how this can be implemented in <a href=\"https:\/\/liora.io\/en\/python-programming-for-beginners-episode-3\">Python:<\/a><\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:heading {\"level\":3} -->\n<h3 id=\"h-application-of-a-cnn-identification-of-any-images-from-the-imagenet-dataset-ten-million-labelled-images\" class=\"wp-block-heading\">Application of a CNN: Identification of any images from the ImageNet dataset: ten million labelled images<\/h3>\n<!-- \/wp:heading -->\n\n<!-- wp:paragraph -->\n<p>ImageNet is a database of over ten million labeled images produced by the organization of the same name, intended for computer vision research. Here is an excerpt from this extensive dataset:<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:image {\"width\":\"1000px\",\"height\":\"auto\",\"linkDestination\":\"custom\",\"align\":\"center\",\"style\":{\"spacing\":{\"margin\":{\"top\":\"var:preset|spacing|columns\",\"bottom\":\"var:preset|spacing|columns\"}}}} -->\n\n<!-- \/wp:image -->\n\n<!-- wp:buttons {\"className\":\"is-layout-flex wp-block-buttons-is-layout-flex is-content-justification-center\",\"style\":{\"spacing\":{\"margin\":{\"top\":\"var:preset|spacing|columns\",\"bottom\":\"var:preset|spacing|columns\"}}},\"layout\":{\"type\":\"flex\",\"justifyContent\":\"center\"}} -->\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex is-content-justification-center\" style=\"margin-top:var(--wp--preset--spacing--columns);margin-bottom:var(--wp--preset--spacing--columns)\"><!-- wp:button -->\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link wp-element-button\" href=\"https:\/\/liora.io\/en\/courses\/data-ai\/data-scientist\">D\u00e9couvrir notre formation de Data Scientist<\/a><\/div>\n<!-- \/wp:button --><\/div>\n<!-- \/wp:buttons -->\n\n<!-- wp:paragraph -->\n<p>Step 0: First of all, let&#8217;s import all the libraries we&#8217;ll need for the rest of the process<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:code {\"style\":{\"spacing\":{\"margin\":{\"top\":\"var:preset|spacing|columns\",\"bottom\":\"var:preset|spacing|columns\"}}},\"fontSize\":\"xsmall\"} -->\n<pre class=\"wp-block-code has-xsmall-font-size\" style=\"margin-top:var(--wp--preset--spacing--columns);margin-bottom:var(--wp--preset--spacing--columns)\"><code>from keras.preprocessing.image import load_img\nfrom keras.preprocessing.image import img_to_array\nfrom keras.applications.vgg16 import preprocess_input\nfrom keras.applications.vgg16 import decode_predictions\nfrom keras.applications.vgg16 import VGG16<\/code><\/pre>\n<!-- \/wp:code -->\n\n<!-- wp:paragraph -->\n<p>Step 1: Training the VGG16 pre-trained model<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:code {\"style\":{\"spacing\":{\"margin\":{\"top\":\"var:preset|spacing|columns\",\"bottom\":\"var:preset|spacing|columns\"}}},\"fontSize\":\"xsmall\"} -->\n<pre class=\"wp-block-code has-xsmall-font-size\" style=\"margin-top:var(--wp--preset--spacing--columns);margin-bottom:var(--wp--preset--spacing--columns)\"><code>model = VGG16()<\/code><\/pre>\n<!-- \/wp:code -->\n\n<!-- wp:paragraph -->\n<p>Step 2: Importing the 3 images to be predicted<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:code {\"style\":{\"spacing\":{\"margin\":{\"top\":\"var:preset|spacing|columns\",\"bottom\":\"var:preset|spacing|columns\"}}},\"fontSize\":\"xsmall\"} -->\n<pre class=\"wp-block-code has-xsmall-font-size\" style=\"margin-top:var(--wp--preset--spacing--columns);margin-bottom:var(--wp--preset--spacing--columns)\"><code># Importation des 3 images suivantes : avion de guerre de type reaper, loup, ballon de football.\nimg1 = load_img('reaper.jpeg', target_size=(224, 224))\nimg2 = load_img('loup.jpeg', target_size=(224, 224))\nimg3 = load_img('ballon.jpg', target_size=(224, 224))<\/code><\/pre>\n<!-- \/wp:code -->\n\n<!-- wp:gallery {\"linkTo\":\"none\"} -->\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped\"><!-- wp:image {\"id\":170493,\"sizeSlug\":\"large\",\"linkDestination\":\"none\",\"style\":{\"spacing\":{\"margin\":{\"top\":\"var:preset|spacing|columns\",\"bottom\":\"var:preset|spacing|columns\"}}}} -->\n\n<!-- \/wp:image -->\n\n<!-- wp:image {\"id\":4477,\"sizeSlug\":\"large\",\"linkDestination\":\"none\",\"style\":{\"spacing\":{\"margin\":{\"top\":\"var:preset|spacing|columns\",\"bottom\":\"var:preset|spacing|columns\"}}}} -->\n<figure class=\"wp-block-image size-large\" style=\"margin-top:var(--wp--preset--spacing--columns);margin-bottom:var(--wp--preset--spacing--columns)\"><img decoding=\"async\" width=\"290\" height=\"193\" src=\"https:\/\/liora.io\/app\/uploads\/sites\/9\/2020\/06\/CNN-13.png\" alt=\"\" class=\"wp-image-4477\"><\/figure>\n<!-- \/wp:image -->\n\n<!-- wp:image {\"id\":170495,\"sizeSlug\":\"large\",\"linkDestination\":\"none\",\"style\":{\"spacing\":{\"margin\":{\"top\":\"var:preset|spacing|columns\",\"bottom\":\"var:preset|spacing|columns\"}}}} -->\n\n<!-- \/wp:image --><\/figure>\n<!-- \/wp:gallery -->\n\n<!-- wp:paragraph -->\n<p>Stage 3: Image pre-processingStage 3: Image pre-processing<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:code {\"style\":{\"spacing\":{\"margin\":{\"top\":\"var:preset|spacing|columns\",\"bottom\":\"var:preset|spacing|columns\"}}},\"fontSize\":\"xsmall\"} -->\n<pre class=\"wp-block-code has-xsmall-font-size\" style=\"margin-top:var(--wp--preset--spacing--columns);margin-bottom:var(--wp--preset--spacing--columns)\"><code># Conversion image (matrice de pixels) en un numpy array\ndef preprocess(image) :\n    image = img_to_array(image)\n\n    # Redimensionnage \n    image = image.reshape((1, image.shape[0], image.shape[1], image.shape[2]))\n\n    # Preprocessing\n    image = preprocess_input(image)\n    \n    return image<\/code><\/pre>\n<!-- \/wp:code -->\n\n<!-- wp:paragraph -->\n<p>Stage 4<b> :<\/b> Pr\u00e9diction du mod\u00e8le<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:code {\"style\":{\"spacing\":{\"margin\":{\"top\":\"var:preset|spacing|columns\",\"bottom\":\"var:preset|spacing|columns\"}}},\"fontSize\":\"xsmall\"} -->\n<pre class=\"wp-block-code has-xsmall-font-size\" style=\"margin-top:var(--wp--preset--spacing--columns);margin-bottom:var(--wp--preset--spacing--columns)\"><code>def pred_modele(image) :\n    \n    image = preprocess(image)\n    # Pr\u00e9diction\n    y_pred = model.predict(image)\n\n    # Conversion des probabilit\u00e9s en classe label\n    label = decode_predictions(y_pred)\n    \n    # Affectation du label ayant la plus grande probabilit\u00e9\n    label = label[0][0]\n\n \n    return ((label[1], label[2]*100))\n\nimg=[img1,img2,img3]\n\nfor i in range(3) :\n    print(\"Pr\u00e9diction image\",i+1,\":\",pred_modele (img[i])[0], 'avec une probabilit\u00e9 de',round(pred_modele (img[i])[1],2),'%')<\/code><\/pre>\n<!-- \/wp:code -->\n\n<!-- wp:image {\"align\":\"center\",\"style\":{\"spacing\":{\"margin\":{\"top\":\"var:preset|spacing|columns\",\"bottom\":\"var:preset|spacing|columns\"}}}} -->\n<figure class=\"wp-block-image aligncenter\" style=\"margin-top:var(--wp--preset--spacing--columns);margin-bottom:var(--wp--preset--spacing--columns)\"><img decoding=\"async\" src=\"https:\/\/liora.io\/app\/uploads\/sites\/9\/2023\/09\/cnn-2.png\" alt=\"\"><figcaption class=\"wp-element-caption\">Display of VGG16 model predictions<\/figcaption><\/figure>\n<!-- \/wp:image -->\n\n<!-- wp:paragraph -->\n<p>We can also display the 5 labels considered most likely by VGG16 :<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:code {\"style\":{\"spacing\":{\"margin\":{\"top\":\"var:preset|spacing|columns\",\"bottom\":\"var:preset|spacing|columns\"}}},\"fontSize\":\"xsmall\"} -->\n<pre class=\"wp-block-code has-xsmall-font-size\" style=\"margin-top:var(--wp--preset--spacing--columns);margin-bottom:var(--wp--preset--spacing--columns)\"><code>import pandas as pd\n\nimg = load_img('\/Users\/Bedoucha\/Desktop\/loup.jpeg', target_size=(224, 224))\nimg = preprocess(img)\n\n# Pr\u00e9diction\ny_pred = model.predict(img)\n\n# Cr\u00e9ation d'un DataFrame avec les 5 labels les plus probables\nlabel_5_plus_probable = decode_predictions(y_pred)\n\nl=[]\nm=[]\nfor i in range(5) :\n    l.append(label_5_plus_probable[0][i][1])\n    m.append(round(label_5_plus_probable[0][i][2]*100,2))\n    \ndf_5_plus_probable=pd.DataFrame({'Etiquette': l, 'Probabilit\u00e9 (%)' : m},index = list(range(1,6)))\ndf_5_plus_probable<\/code><\/pre>\n<!-- \/wp:code -->\n\n<!-- wp:image {\"align\":\"center\",\"style\":{\"spacing\":{\"margin\":{\"top\":\"var:preset|spacing|columns\",\"bottom\":\"var:preset|spacing|columns\"}}}} -->\n\n<!-- \/wp:image -->\n\n<!-- wp:paragraph -->\n<p>\u2192 VGG16 has successfully predicted with high confidence (95.6%) that not only the input image was a wolf but even went further by specifying its breed, which in this case is an Eastern Gray Wolf (timber wolf). Impressive, isn&#8217;t it?<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:paragraph -->\n<p>In the end, the operating principle of a CNN is quite easy to understand. However, paradoxically, implementing such a process to classify images remains very complex due to the considerable number of parameters to define: the number, size, movement of filters, choice of pooling method, the number of layers of neurons, the number of neurons per layer, and so on.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:paragraph -->\n<p>To overcome this obstacle, Python, through the Torchvision module, offers the possibility to use powerful pre-trained CNN models such as VGG16, Resnet101, etc.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:paragraph -->\n<p>In this article, we&#8217;ve explained the operation and architecture of Convolutional Neural Networks, with a focus on its specificity: the convolutional part.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:paragraph -->\n<p>We still have one more step in <a href=\"https:\/\/liora.io\/en\/management-of-unbalanced-classification-problems-i\">classification<\/a> to cover: backpropagation of the error gradient, the famous gradient descent algorithm. Don&#8217;t worry, the next episode on this topic will be coming soon on the blog!<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:buttons {\"layout\":{\"type\":\"flex\",\"justifyContent\":\"center\"}} -->\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex is-content-justification-center\"><!-- wp:button -->\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link wp-element-button\" href=\"https:\/\/liora.io\/en\/courses\/\">Discover our training courses<\/a><\/div>\n<!-- \/wp:button --><\/div>\n<!-- \/wp:buttons -->\n\n<!-- wp:html -->\n<script type=\"application\/ld+json\">\n{\n  \"@context\": \"https:\/\/schema.org\",\n  \"@type\": \"FAQPage\",\n  \"mainEntity\": [\n    {\n      \"@type\": \"Question\",\n      \"name\": \"What are the main applications for CNNs?\",\n      \"acceptedAnswer\": {\n        \"@type\": \"Answer\",\n        \"text\": \"Convolutional Neural Networks are powerful deep learning models inspired by the visual cortex that excel at image recognition and are also used for video analysis, semantic analysis, sentence modelling, classification and drug discovery.\u00a0([turn0search0])\"\n      }\n    },\n    {\n      \"@type\": \"Question\",\n      \"name\": \"What is a Convolutional Neural Network (CNN) architecture?\",\n      \"acceptedAnswer\": {\n        \"@type\": \"Answer\",\n        \"text\": \"A CNN\u2019s architecture typically has a convolutional part that extracts features from input images and a classification part where fully connected layers combine these features to assign a class label to the image.\u00a0([turn0view0])\"\n      }\n    },\n    {\n      \"@type\": \"Question\",\n      \"name\": \"What is convolution used for in a CNN?\",\n      \"acceptedAnswer\": {\n        \"@type\": \"Answer\",\n        \"text\": \"Convolution is a mathematical operation used to scan an image with filters that extract patterns and create feature maps indicating where relevant features occur in the input.\u00a0([turn0view0])\"\n      }\n    },\n    {\n      \"@type\": \"Question\",\n      \"name\": \"What is max\u2011pooling in CNNs?\",\n      \"acceptedAnswer\": {\n        \"@type\": \"Answer\",\n        \"text\": \"Max\u2011pooling is a subsampling method that reduces the dimensions of feature maps by selecting the maximum value in each region, decreasing computational cost and adding invariance to small translations.\u00a0([turn0view0])\"\n      }\n    },\n    {\n      \"@type\": \"Question\",\n      \"name\": \"What are the typical layers in a CNN?\",\n      \"acceptedAnswer\": {\n        \"@type\": \"Answer\",\n        \"text\": \"Typical CNN layers include convolution layers that detect features, pooling layers that downsample outputs, activation layers like ReLU adding non\u2011linearity, and fully connected layers that perform classification at the end.\u00a0([turn0search5])\"\n      }\n    }\n  ]\n}\n<\/script>\n\n<!-- \/wp:html -->","protected":false},"excerpt":{"rendered":"<p>In this section, we will focus on one of the most powerful algorithms in Deep Learning: Convolutional Neural Networks (CNNs). These are powerful programming models that enable image recognition, in particular, by automatically assigning a label to each image provided as input, corresponding to the class to which it belongs. Welcome to the third episode [&hellip;]<\/p>\n","protected":false},"author":50,"featured_media":207553,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"editor_notices":[],"footnotes":""},"categories":[2433],"class_list":["post-170478","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-data-ai"],"acf":[],"_links":{"self":[{"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/posts\/170478","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/users\/50"}],"replies":[{"embeddable":true,"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/comments?post=170478"}],"version-history":[{"count":5,"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/posts\/170478\/revisions"}],"predecessor-version":[{"id":207554,"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/posts\/170478\/revisions\/207554"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/media\/207553"}],"wp:attachment":[{"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/media?parent=170478"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/categories?post=170478"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}