<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Clairenyz on Medium]]></title>
        <description><![CDATA[Stories by Clairenyz on Medium]]></description>
        <link>https://medium.com/@clairenyz?source=rss-e8a565729e15------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*fAHglFJ-8Oc0Dw3G.jpg</url>
            <title>Stories by Clairenyz on Medium</title>
            <link>https://medium.com/@clairenyz?source=rss-e8a565729e15------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 16:24:03 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@clairenyz/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Attention-based Convolutional Neural Network]]></title>
            <link>https://medium.com/@clairenyz/attention-based-convolutional-neural-network-a719693058a7?source=rss-e8a565729e15------2</link>
            <guid isPermaLink="false">https://medium.com/p/a719693058a7</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[convolutional-network]]></category>
            <dc:creator><![CDATA[Clairenyz]]></dc:creator>
            <pubDate>Thu, 15 Dec 2022 19:35:17 GMT</pubDate>
            <atom:updated>2022-12-15T20:20:55.989Z</atom:updated>
            <content:encoded><![CDATA[<p>A convolutional neural network (CNN) is a type of artificial neural network specifically designed for pattern recognition tasks, such as image classification. It is composed of multiple layers of interconnected nodes, where each layer is responsible for a specific task.</p><p>The key feature of a CNN is the use of convolutional layers, which apply a convolution operation to the input data. This operation allows the network to extract important features from the data, such as edges, textures, and patterns. The convolutional layers are typically followed by pooling layers, which reduce the dimensions of the data by summarizing the information in small regions.</p><p>CNNs are widely used in a variety of applications, including image and video classification, object detection, and segmentation. They are particularly well-suited for tasks that require the extraction of spatial and temporal features from data, such as in image recognition or video analysis.</p><p>One of the main advantages of CNNs is their ability to learn hierarchical representations of data. Through the use of multiple convolutional and pooling layers, a CNN can learn to recognize increasingly complex patterns in the data, allowing it to make highly accurate predictions. Another advantage of CNNs is their ability to learn from data with a limited amount of labeling. This makes them well-suited for tasks where the amount of labeled data is limited, such as in medical imaging or satellite imagery.</p><p>Attention mechanisms in deep learning models are inspired by the way the human brain processes information. When we see an image, for example, our brain automatically focuses on the most relevant parts of the image and filters out irrelevant information. This allows us to quickly understand and make sense of the image. In a similar way, attention mechanisms in deep learning models allow the model to automatically learn to focus on the most important parts of an input, which can improve the model’s performance on a wide range of tasks.</p><p>There are many different ways to implement attention mechanisms in deep learning models, and the specific implementation will depend on the specific task and the type of model being used. In the case of an attention-based CNN, the attention mechanism is typically implemented by adding an additional layer to the model that learns the attention weights for each part of the input. These weights are then applied to the output of the CNN model, allowing the model to focus on the most relevant features in the input.</p><p>Attention-based CNNs have been shown to perform well on a variety of tasks, including image classification, object detection, and natural language processing. In image classification tasks, for example, attention-based CNNs can learn to focus on specific objects or features in the input images, which can improve the model’s ability to accurately classify the images. In natural language processing tasks, attention-based CNNs can learn to focus on the most important words in a sentence, which can improve the model’s ability to understand the meaning of the sentence.</p><p>Here is an example of how to implement an attention-based CNN in Python using the TensorFlow library:</p><pre>import tensorflow as tf<br><br># Define the input placeholder<br>inputs = tf.placeholder(dtype=tf.float32, shape=[None, height, width, channels])<br># Define the CNN model<br>cnn_model = tf.keras.layers.Conv2D(filters=64, kernel_size=3, padding=&quot;same&quot;, activation=&quot;relu&quot;)(inputs)<br>cnn_model = tf.keras.layers.MaxPool2D(pool_size=2)(cnn_model)<br>cnn_model = tf.keras.layers.Conv2D(filters=128, kernel_size=3, padding=&quot;same&quot;, activation=&quot;relu&quot;)(cnn_model)<br>cnn_model = tf.keras.layers.MaxPool2D(pool_size=2)(cnn_model)<br># Define the attention mechanism<br>attention_weights = tf.keras.layers.Dense(units=1, activation=&quot;sigmoid&quot;)(cnn_model)<br>attention_weights = tf.keras.layers.Reshape((-1,))(attention_weights)<br>attention_weights = tf.keras.layers.Softmax(axis=1)(attention_weights)<br># Apply the attention weights to the output of the CNN model<br>attention_output = tf.keras.layers.Dot(axes=[1,1])([attention_weights, cnn_model])<br># Define the rest of the model<br>outputs = tf.keras.layers.Flatten()(attention_output)<br>outputs = tf.keras.layers.Dense(units=10, activation=&quot;softmax&quot;)(outputs)<br># Compile the model<br><br>model = tf.keras.Model(inputs=inputs, outputs=outputs)<br>model.compile(optimizer=&quot;adam&quot;, loss=&quot;categorical_crossentropy&quot;, metrics=[&quot;accuracy&quot;])</pre><p>In this example, we first define the input placeholder, which will hold the data that is fed into the model. Then we define the CNN model, which consists of a series of convolutional and pooling layers. Next, we define the attention mechanism, which uses a dense layer with a sigmoid activation function to learn the attention weights for each part of the input. These weights are then applied to the output of the CNN model using a dot product operation. Finally, we define the rest of the model, which consists of a flatten layer and a dense layer with a softmax activation function, and compile the model using the Adam optimizer and categorical cross-entropy loss.</p><p>Furthermore, here is a graphic example of attention-based CNN:</p><p><strong>BCNN：Basic Bi-CNN</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/282/1*ehd3l3OndpbG7tmDRYeUtw.png" /><figcaption>Yin et al.</figcaption></figure><p>BCNN consists of four parts: input layer, convolutional layer, pooling layer, and output layer. In practical applications, the length of two sentences will be unified, and the shorter sentence will be filled, here the original sentence length is kept for the convenience of illustration.</p><p><strong>Input layer:</strong></p><p>Input layer is to replace each word in the sentence with the corresponding word vector to get the initial vector representation, here the 300-dimensional word2vec embedding is used.</p><p><strong>Convolution layer:</strong></p><p>The convolution layer is a wide convolution, i.e., the edges of the sentence are zeroed</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/547/1*mPgiif7l1uuCwVbC8Udysw.png" /><figcaption>Yin et al.</figcaption></figure><p>The words in the sentence are denoted by v1,v2,… ,vs, ci∈Rw⋅d0,0&lt;i&lt;s+w means that w is the window length, and vi-w+1,… ,vi are spliced together to obtain the embedding, which is convolved to obtain the phrase vi-w+1,… ,vi<br>representation, which is given by the following equation：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/312/1*dAXqDR0gzVrI0Kjd35VfdA.png" /></figure><p>Here W∈Rd1×wd0 are the parameters of the convolutional network.</p><p><strong>Average pooling layer:</strong></p><p>For the last convolutional layer in the network structure, average pooling is performed for all columns, which is referred to here as all-ap. For the other convolutional layers in the network, average pooling is performed for consecutive w columns according to the window size w. When the window size of the convolutional network is w, after the convolutional layer, the input s column feature becomes When the window size of the convolutional network is w, the input s-column features become s+w-1 columns, and after pooling, they become s-columns again, so this structure allows multi-layer superposition into a deeper network structure to obtain more abstract features.</p><p><strong>Output layer: </strong>The output layer is determined by different tasks. In addition, the authors found that if the output of each convolutional layer is all-ap (pooling over all columns) and then used as features in the output layer, the model can be improved.</p><p>Referred by <a href="https://openaccess.thecvf.com/content_cvpr_2017/papers/Fu_Look_Closer_to_CVPR_2017_paper.pdf">Fu et al. in their paper, </a>✎ EditSignthe authors take a network with three scales as an example, as shown in Figure 1, and more fine-scale networks can be constructed in that manner.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/588/1*1NQiR65gSGSuZjIIvU1gaw.png" /><figcaption>Fu et al.</figcaption></figure><p>The inputs in the above figure are coarse full-size images to finer regional attention (from top to bottom). The different networks used for classification (labeled blue) and attention recommendation (labeled red) are alternatively optimized, i.e., the classification loss Lcls between the labeled prediction Y(s) and the true value Y∗ at different scales, and the pairwise ranking loss Lrank for pt(s) and pt(s+1) between adjacent scales, where pt(s) and pt(s+1) denote the probability on the correct category and s denotes the scale. apn is the attention recommendation network, fc denotes the fully connected layer, and the softmax layer passes through the fc layer matches the category entries and then performs the softmax operation. ⊕ denotes the cropping and scaling operations.</p><p>The input is cyclic from the full-scale image of a1 to the fine-grained discriminative regions of a2 and a3, where a2 and a3 take the attention regions from a1 and a2, respectively, as input. One, images of different scales are fed into the convolutional layers ( b1 to b3 ) to extract region-based feature representations. Two, the network continues to predict probability scores through the fully connected and softmax layers ( c1 to c3 ) and region attention through the attention recommendation network ( d1 , d2 ). The proposed RA-CNN is fitted by alternately learning the softmax classification loss at each scale and the pairwise ranking loss between adjacent scales.</p><p>Attention-based Convolutional Neural Network is also applied by other researchers in different fields. Kun Wang, Jun He, and Lei Zhang have done research in attention-based Convolutional Neural Network for weakly labeled human activities recognition with wearable sensors. Here is a graph of their model:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/554/1*7Z5accnRuB_0jpV_GXGVIw.png" /><figcaption>Figure 1 Wang, K., He, J., &amp; Zhang, L. (2019)</figcaption></figure><p>Their approach aims to identify and localize human activity in sensor data with undesirable markers. The attention mechanism identifies important activity data regions and increases their impact, while suppressing irrelevant and perhaps confusing information in other activity data regions. The model is composed of a basic CNN pipeline and an attention submodule (Fig 1). As such, it has many applications in weakly supervised learning. The model can filter out a large amount of background noise signals while focusing on labeled activities in a long string of sensor data.</p><p>Further, the authors applied Fundamental CNN.</p><p>The basic model on which the attention submodule is based is a deep CNN, which includes a convolutional layer, a pooling layer, and a fully connected layer. As shown in Figure 1, the shorthand description is: C(32)-C(64)-C(128)-P-C(128)-P-C(128)-P-F C(128)-softmax, where C(L s) denotes the convolutional layer s with L s feature maps, P is the maximum pooling layer, F C(n) is the fully connected layer with n units, and Softmax is the softmax classifier. In addition, the output of each layer is transformed with the ReLU activation function. The purpose of not having pooling layers after the first two convolutional layers is to ensure a higher resolution of the local feature maps extracted from the three convolutional layers C(128) for estimating attention.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/289/1*4LA2luo5b58sRWtrb20-IA.png" /><figcaption>Calculating compatibility scores Wang, K., He, J., &amp; Zhang, L.</figcaption></figure><p>Lastly, they applied Location Function.</p><p>For a primitive CNN architecture, a global feature descriptor G is usually computed from the input data and a fully connected layer is used to output the class prediction probabilities. In order to make the classes linearly separable from each other, G must be expressed by mapping the input to a high-dimensional space where salient higher-order data concepts are represented by different dimensions. The attentional approach places filters at an early stage of the CNN pipeline to learn similar mappings, which are compatible with the original architecture for outputting G. Due to the attention mechanism of our model, the compatibility score C(L s , G) should be high when and only when the corresponding patch contains the fraction of the dominant data category. That is, for weakly labeled sensor data, regions with high compatibility scores tend to be locations where labeling activity occurs, while those regions where background activity occurs have lower compatibility scores. Using this concept, we can not only get a good identification result, but also determine the specific location of the tagging activity in a long string of weakly tagged data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/489/1*yDXXbW1QB7GB3inLvLVPpA.png" /><figcaption>Wang, K., He, J., &amp; Zhang, L.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/485/1*ZzETY1ksSY2YVwpc0kW2xQ.png" /><figcaption>Wang, K., He, J., &amp; Zhang, L.</figcaption></figure><p>As the result, on the standard UCI HAR dataset, the proposed attention model can be compared with established ways of recognizing human activity. Importantly, the accuracy of their model on the weakly labeled dataset exceeds that of traditional deep learning models.</p><p>Other researchers have used attention-based CNN in other field applications too. For example, Bofei Zhang, Jimin Tan, Kyunghyun Cho, Gregory Chang, and Cem M. Deniz from New York University have applied this technique for Knee osteoarthritis detection. They formulated OA as a supervised classification problem using plain radiographs as inputs and Kellgren-Lawrence grade (KL-grade) as labels.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/380/1*BxZey89ysvyrpvYu8FJ_ag.png" /><figcaption>B. Zhang, J. Tan, K. Cho, G. Chang and C. M. Deniz</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/743/1*aVPPz-OJAQ9k53aWcWEnWw.png" /><figcaption>B. Zhang, J. Tan, K. Cho, G. Chang and C. M. Deniz</figcaption></figure><p>Knee osteoarthritis (OA) is a common condition that can cause physical disability and require total knee joint replacement. It is typically diagnosed based on symptoms such as joint pain, stiffness, and reduced range of motion. Knee radiography is often used to diagnose radiographic OA, which is assessed using the Kellgren-Lawrence grading system (KL-grade). KL-grade is used to track the progression of OA, assess it in studies, and determine the need for total knee replacement.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/390/1*UBg9a3HXxgClF2TesMmuew.png" /><figcaption>Model Architecture B. Zhang, J. Tan, K. Cho, G. Chang and C. M. Deniz</figcaption></figure><p>Bilateral radiographs of the knees were converted to 2D matrices and inverted if labeled as MONOCHROME1. Global contrast normalization was applied to each image. Two different preprocessing steps were used for two separate tasks: knee joint localization and KL-grade classification. Bicubic spline interpolation was used to resize the bilateral radiographs to 896x896 for the knee joint localization task. The trained localization model was then used to annotate bounding boxes in the OAI dataset.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/385/1*ieAGodAjNgDsJ-MDEVFMvA.png" /><figcaption>Distribution of KL grades B. Zhang, J. Tan, K. Cho, G. Chang and C. M. Deniz</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/707/1*RqsXnOYJVyXS3PCshdiTCw.png" /><figcaption>Confusion matrix comparison of different models B. Zhang, J. Tan, K. Cho, G. Chang and C. M. Deniz</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/377/1*HU5EycThwdl8j5tgiNC-6A.png" /><figcaption>Model Results B. Zhang, J. Tan, K. Cho, G. Chang and C. M. Deniz</figcaption></figure><p>In this research, a new method for automatic classification of knee images using plain radiographs has been proposed. This method uses a ResNet model with a convolutional block attention model and outperforms previous methods in terms of multi-class average accuracy, MSE, and quadratic Kappa score. This new method also allows for the use of knee radiographs with high spatial resolution, whereas previous methods required a reduction in spatial resolution. These findings suggest that higher resolution and contrast in medical imaging can improve the performance of CNN models in diagnosis.</p><h3><strong>Conclusion:</strong></h3><p>One of the key contributions of attention-based CNNs is their ability to automatically learn to focus on the most important parts of an input, rather than processing the entire input equally. This allows the model to be more efficient and effective at extracting relevant features from the input data. Additionally, attention mechanisms can help improve the interpretability of the model, as they provide a way to visualize which parts of the input the model is focusing on.</p><p>In terms of future applications, attention-based CNNs are likely to continue to be used in a wide range of tasks, particularly in areas such as medical imaging and natural language processing. In medical imaging, for example, attention-based CNNs can be used to automatically identify and classify objects in medical images, which can improve the accuracy and efficiency of diagnostic procedures. In natural language processing, attention-based CNNs can be used to improve the ability of language models to understand and generate human-like text.</p><p>Overall, attention-based CNNs happen to be an existing promising approach that is going to belong to improving the performance that belongs to deep learning models on top of an existing wide range that belongs to tasks. During the same time that the field that belongs to deep learning continues to advance, it happens to be likely that attention-based CNNs is going to continue to exist as an existing valuable tool that is going to belong to solving complex problems inside of an existing variety that belongs to domains.</p><p><strong>References:</strong></p><p>B. Zhang, J. Tan, K. Cho, G. Chang and C. M. Deniz, “Attention-based CNN for KL Grade Classification: Data from the Osteoarthritis Initiative,” 2020 IEEE 17th International Symposium on Biomedical Imaging (ISBI), 2020, pp. 731–735, doi: 10.1109/ISBI45749.2020.9098456.</p><p>Fu, J., Zheng, H., &amp; Mei, T. (2017). Look Closer to See Better: Recurrent Attention Convolutional Neural Network for Fine-Grained Image Recognition. <em>2017 IEEE Conference on Computer Vision and Pattern Recognition (CVPR)</em>, 4476–4484.</p><p>K. Wang, J. He and L. Zhang, “Attention-Based Convolutional Neural Network for Weakly Labeled Human Activities’ Recognition With Wearable Sensors,” in <em>IEEE Sensors Journal</em>, vol. 19, no. 17, pp. 7598–7604, 1 Sept.1, 2019, doi: 10.1109/JSEN.2019.2917225.</p><p>Wang, K., He, J., &amp; Zhang, L. (2019). Attention-based convolutional neural network for weakly labeled human activities’ recognition with wearable sensors. <em>IEEE Sensors Journal</em>, <em>19</em>(17), 7598–7604.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a719693058a7" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>