<?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 Fatimazahra Belharar on Medium]]></title>
        <description><![CDATA[Stories by Fatimazahra Belharar on Medium]]></description>
        <link>https://medium.com/@fatimazahra.belharar?source=rss-68ebad88e1e6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*kF2Qe9MKDqPyF3hg.jpg</url>
            <title>Stories by Fatimazahra Belharar on Medium</title>
            <link>https://medium.com/@fatimazahra.belharar?source=rss-68ebad88e1e6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 10:32:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@fatimazahra.belharar/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[Enhancing Classification Accuracy for Imbalanced Image Data Using SMOTE]]></title>
            <link>https://medium.com/@fatimazahra.belharar/enhancing-classification-accuracy-for-imbalanced-image-data-using-smote-41737783a720?source=rss-68ebad88e1e6------2</link>
            <guid isPermaLink="false">https://medium.com/p/41737783a720</guid>
            <category><![CDATA[smote]]></category>
            <category><![CDATA[image-processing]]></category>
            <category><![CDATA[imbalanced-data]]></category>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[image-classification]]></category>
            <dc:creator><![CDATA[Fatimazahra Belharar]]></dc:creator>
            <pubDate>Wed, 07 Jun 2023 17:58:57 GMT</pubDate>
            <atom:updated>2023-06-07T17:58:57.930Z</atom:updated>
            <content:encoded><![CDATA[<p>In the world of data analysis and machine learning, not all datasets are created equal. One common challenge that often arises is dealing with imbalanced data, where one class is significantly more prevalent than the others. This imbalance can have a detrimental effect on the performance of deep learning and machine learning models, particularly when it comes to accurately predicting the minority class. Fortunately, there are techniques available to address this issue, and one such powerful technique is the Synthetic Minority Over-sampling Technique (SMOTE).</p><p>Imbalanced data is pervasive across various domains, from fraud detection and medical diagnosis to customer churn prediction and anomaly detection. Traditional machine learning algorithms tend to be biased towards the majority class, as they strive to optimize overall accuracy. This results in models that struggle to identify and predict instances from the minority class accurately. The consequences of misclassification in these cases can be significant, leading to missed opportunities or critical errors.</p><p>SMOTE offers a solution to this challenge by addressing the class imbalance problem head-on. Developed by Chawla et al. in 2002, SMOTE is an oversampling technique that synthetically creates new instances for the minority class, effectively rebalancing the dataset. By generating synthetic examples in the feature space, SMOTE helps to overcome the limitations of traditional approaches and enables the machine learning model to learn more effectively from the minority class.</p><p>The underlying idea behind SMOTE is to identify minority class instances and create synthetic samples by interpolating between them. This is achieved by selecting random instances from the minority class, determining their nearest neighbors, and then creating new instances along the line segments connecting them. The result is a more balanced dataset that better reflects the underlying distribution of the data, enabling the machine learning model to learn and generalize more effectively.</p><p>Applying SMOTE to imbalanced data has been shown to have several benefits. It improves the predictive accuracy of machine learning and deep learning models, especially in cases where the minority class is crucial or rare events need to be detected. By providing the model with more examples from the minority class, SMOTE helps to alleviate the bias towards the majority class and leads to a better understanding of the underlying patterns and relationships within the data.</p><p>Preprocessing steps like resizing, normalization, and feature extraction are crucial for image data preparation in SMOTE. They ensure uniform dimensions, reduce variations, and capture relevant information. Consistent preprocessing across original and synthetic samples maintains data integrity. It aligns dimensions, scales pixel values, and extracts features consistently for fair representation. Inconsistent preprocessing can introduce biases and hinder model performance. Resizing ensures consistent dimensions, normalization reduces variations, and feature extraction captures discriminative information. Applying these steps uniformly enhances the effectiveness of SMOTE and improves classification accuracy for imbalanced image data.</p><p>To apply SMOTE specifically to image data, the process involves identifying minority class instances by analyzing class labels, selecting nearest neighbors based on distance metrics such as Euclidean or cosine similarity, and performing interpolation between them to generate synthetic samples by preserving visual characteristics, texture, and spatial information.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/608/1*Dd3JczZPKKAytxxLYUD6ZA.jpeg" /><figcaption>Number of samples per class before and after SMOTE on IDRID Dataset</figcaption></figure><p>Here is an example of applying SMOTE to an image dataset:</p><pre>import pandas as pd<br>import numpy as np<br>import os<br>import sys<br>from shutil import copyfile<br>import os.path<br>import cv2<br>import numpy as np<br>from keras.preprocessing.image import ImageDataGenerator, array_to_img, img_to_array,load_img<br>from PIL import Image<br>from sklearn.model_selection import train_test_split<br>from numpy import load<br>import matplotlib.pyplot as plt<br>imagegen = ImageDataGenerator()<br><br># load train data from drive<br>train_generator=imagegen.flow_from_directory(&quot;/content/gdrive/MyDrive/idrid&quot;, class_mode=&quot;categorical&quot;, shuffle=False, batch_size=128, target_size=(512, 512),seed=42 )<br>x=np.concatenate([train_generator.next()[0] for i in range(train_generator.__len__())])<br>y=np.concatenate([train_generator.next()[1] for i in range(train_generator.__len__())])<br>print(x.shape)<br>print(y.shape)<br>#Converting  our color images to a vector<br>X_train=x.reshape(103,512*512*3)<br><br>#Apply SMOTE method <br>from imblearn.over_sampling import SMOTE<br>sm = SMOTE(random_state=2)<br>X_smote, y_smote = sm.fit_resample(X_train, y)<br><br>#Retrieve the image and save it to drive. Here&#39;s an example for a single image<br>Xsmote_img=X_smote.reshape(585,512,512,3)<br>pil_img = array_to_img(Xsmote_img[80]* 255)<br>pil_img.save(&#39;/content/gdrive/My Drive/demo.jpg&#39;)<br><br>#Save all images generated by the SMOTE method to the drive<br><br>train_sep_dir=&#39;/content/gdrive/My Drive/idrid/testfolder/&#39;<br><br>#Create a &quot;testfolder&quot; if it does not exist on the drive<br>if not os.path.exists(train_sep_dir):<br>    os.mkdir(train_sep_dir)<br><br>#This function return label name <br>def get_key(val): <br>    for key, value in patho.items(): <br>         if val == value: <br>  return key <br><br>for i in range(len(Xsmote_img)):<br>  label=get_key(str(y_smote[i]))  <br>  if not os.path.exists(train_sep_dir + str(label)):<br>    os.mkdir(train_sep_dir + str(label))<br>  pil_img = array_to_img(Xsmote_img[i]* 255)<br>  pil_img.save(train_sep_dir + str(label) +&#39;/&#39;+ &#39;smote_&#39;+ str(i) + &#39;.jpg&#39;)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/224/1*YY2v0UJaCFNKiXMfo4TXZQ.jpeg" /><figcaption>Original image</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/224/1*H09WaIwZkD8Rhbmkoa7Oig.jpeg" /><figcaption>Image generate by SMOTE method</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=41737783a720" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Object Detection using CNN: An Introduction to the YOLO Algorithm]]></title>
            <link>https://medium.com/@fatimazahra.belharar/object-detection-using-cnn-an-introduction-to-the-yolo-algorithm-df0f7b173c6?source=rss-68ebad88e1e6------2</link>
            <guid isPermaLink="false">https://medium.com/p/df0f7b173c6</guid>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[yolo]]></category>
            <category><![CDATA[cnn]]></category>
            <dc:creator><![CDATA[Fatimazahra Belharar]]></dc:creator>
            <pubDate>Mon, 05 Jun 2023 17:55:23 GMT</pubDate>
            <atom:updated>2023-06-05T17:55:23.829Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/586/1*uzdWZNptHa8iGWnwEHofvg.jpeg" /></figure><p>Object detection is a fundamental task in computer vision that involves identifying and localizing objects within an image or video. Convolutional Neural Networks (CNNs) have revolutionized the field of object detection, enabling accurate and efficient detection in real-time applications. One such popular algorithm is YOLO (You Only Look Once), known for its single-stage architecture and impressive performance. In this article, we will explore the concept of object detection using CNNs, with a focus on understanding the YOLO algorithm.</p><p>Object detection involves two main components: localizing objects by drawing bounding boxes around them and classifying those objects into specific categories. CNNs have proven to be highly effective in learning discriminative features for object detection tasks due to their ability to capture hierarchical and spatial information in images.</p><p>The YOLO algorithm takes a unique approach to object detection. Unlike traditional two-stage methods, YOLO performs detection in a single pass through the network, making it significantly faster. YOLO divides the input image into a grid and predicts bounding boxes and class probabilities for each grid cell. This grid-based approach allows YOLO to detect objects at multiple scales and capture their spatial relationships efficiently.</p><p>In YOLO, each grid cell is responsible for predicting objects that fall within it. For each grid cell, the algorithm predicts multiple bounding boxes, each with a confidence score indicating the presence of an object. Additionally, class probabilities are assigned to each bounding box to identify the object category.</p><p>YOLO utilizes anchor boxes, which are pre-defined bounding box shapes of different sizes and aspect ratios. These anchor boxes are associated with each grid cell and used to predict the coordinates of the bounding boxes relative to the anchor box shapes. This allows YOLO to handle objects of varying sizes and shapes effectively.</p><p>After generating multiple bounding box predictions, YOLO applies a technique called non-maximum suppression (NMS) to eliminate duplicate or overlapping predictions. NMS selects the most confident bounding boxes and removes redundant ones, ensuring that each object is detected only once.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3B3Ffy0jA49rsdklQ8zXCw.png" /><figcaption>Source: YOLO’s paper You Only Look Once: Unified, Real-TimeObjectDetection</figcaption></figure><p>Training YOLO involves providing annotated training data with bounding box labels. The algorithm learns to predict bounding box coordinates and class probabilities by minimizing a loss function that considers both localization and classification errors. The training process involves forward and backward propagation through the network to update the model parameters.</p><p>YOLO has seen several iterations, each improving upon the previous version. YOLOv8 is the most recent iteration of the YOLO-based Object Detection models developed by Ultralytics, offering cutting-edge performance. Building upon the foundations of earlier YOLO versions, the YOLOv8 model achieves enhanced speed and accuracy, providing a unified framework for training models to perform various tasks.</p><p>One of the notable advantages of YOLO is its real-time performance. The single-stage architecture and efficient design allow YOLO to achieve impressive detection speeds, making it suitable for applications such as video surveillance, autonomous driving, and robotics.</p><p>YOLO models can benefit from transfer learning by leveraging pretrained models trained on large-scale datasets like COCO. These pretrained models capture general object detection knowledge and can be fine-tuned on custom datasets with relatively fewer annotated samples.</p><p>While YOLO has demonstrated remarkable performance, it still faces challenges in detecting small objects accurately. Future research aims to address these challenges by exploring techniques like feature pyramid networks (FPN) and incorporating attention mechanisms to improve performance further.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/794/1*Y67t-eNVLT2IybVzcvXMLg.png" /><figcaption>The YOLO V8 model encounters difficulties in detecting small objects, such as birds, in this image.</figcaption></figure><p>Convolutional Neural Networks have revolutionized object detection, and the YOLO algorithm has emerged as a powerful approach in this domain. Its single-stage architecture, real-time performance, and impressive accuracy have made it popular among researchers and practitioners. By understanding the concepts and principles behind YOLO, you can apply this algorithm to various computer vision applications effectively.</p><pre>#To install YOLO V8 from PIP using these commands:<br>!pip install ultralytics<br> <br>#Import YOLO model &amp;libraries<br>from ultralytics import YOLO<br>import cv2<br>from matplotlib import pyplot as plt<br>model = YOLO(&#39;yolov8n.pt&#39;)<br>model.predict(<br>   source=&#39;https://media.roboflow.com/notebooks/examples/dog.jpeg&#39;,<br>   save=True,<br>   show = True,<br>   conf=0.25<br>)<br><br># create figure<br>fig = plt.figure(figsize=(10, 20))<br><br># setting values to rows and column variables<br>rows = 2<br>columns = 2<br>Image1 = cv2.imread(&#39;/content/dog.jpeg&#39;)<br>Image2 = cv2.imread(&#39;/content/runs/detect/predict/dog.jpeg&#39;)<br>fig.add_subplot(rows, columns, 1)<br># showing image<br>plt.imshow(Image1)<br>plt.axis(&#39;off&#39;)<br>plt.title(&quot;Original image&quot;)<br>fig.add_subplot(rows, columns, 2)<br># showing image<br>plt.imshow(Image2)<br>plt.axis(&#39;off&#39;)<br>plt.title(&quot;Predicted image&quot;)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/794/1*JfgcbUfZ20WGjTDfIGcarg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=df0f7b173c6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>