<?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 Ariel Drabkin on Medium]]></title>
        <description><![CDATA[Stories by Ariel Drabkin on Medium]]></description>
        <link>https://medium.com/@arieldrabkin1?source=rss-154addae9f7c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*4g7oLUfhaF7b3ZqTcjng1Q.jpeg</url>
            <title>Stories by Ariel Drabkin on Medium</title>
            <link>https://medium.com/@arieldrabkin1?source=rss-154addae9f7c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 04:26:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@arieldrabkin1/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 Object Detection in Aerial Imagery: A Comparative Study of Data Augmentation Techniques]]></title>
            <link>https://levelup.gitconnected.com/enhancing-object-detection-in-aerial-imagery-a-comparative-study-of-data-augmentation-techniques-02a5944d7b80?source=rss-154addae9f7c------2</link>
            <guid isPermaLink="false">https://medium.com/p/02a5944d7b80</guid>
            <category><![CDATA[data-augmentation]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[object-detection]]></category>
            <dc:creator><![CDATA[Ariel Drabkin]]></dc:creator>
            <pubDate>Mon, 04 Mar 2024 03:01:03 GMT</pubDate>
            <atom:updated>2024-04-21T12:09:56.873Z</atom:updated>
            <content:encoded><![CDATA[<h4>An experimental evaluation of Mosaic, MixUp, and Copy-Paste augmentations efficiency for an object detection model training</h4><h3>Abstract</h3><p>Following the article <a href="https://levelup.gitconnected.com/solar-panel-detector-guide-to-an-end-to-end-computer-vision-project-using-nothing-but-free-a7ee3610de43">“Solar-Panel-Detector: Guide to an End-to-End Computer Vision Project Using Nothing-But-Free Software”</a> which discussed how to turn a business idea into a deployable object detection application, this article investigates the significance of data augmentation in object detection model training, examining how different strategies affected the performance of the solar panel detector model and which augmentation strategy performed better than others.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*luFxBJUVObksH8dvcyIlTg.jpeg" /><figcaption><strong>Figure 1. </strong>Generated Image by DALL-E for the prompt: “an image representing different data augmentation techniques such as MixUp, Mosaic and Copy Paste in aerial imagery object detection.”</figcaption></figure><h3>Understanding Data Augmentation</h3><p>The primary goal of data augmentation is to generate a more diverse and comprehensive set of training examples without collecting new data, allowing for the development of more accurate and robust machine learning models capable of generalizing and performing effectively on diverse and previously unseen data.</p><p>Data augmentation is the process of artificially increasing the training dataset by introducing a wide range of variations, such as changes in orientation, lighting conditions, background, and more.</p><p>It is a popular method for improving machine learning training, particularly in computer vision tasks, because it is especially beneficial when training data is restricted or there is a requirement to closely mimic very specific real-world scenarios.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/685/0*Oqu5RGmE5HHxAvEE.png" /><figcaption><strong>Figure 2. </strong>Common Data Augmentation Techniques in Deep Learning as Described in <a href="https://journalofbigdata.springeropen.com/articles/10.1186/s40537-019-0197-0">“A survey on Image Data Augmentation for Deep Learning”</a> by Shorten &amp; Khoshgoftaar, 2019</figcaption></figure><h3>Data Augmentation Techniques Explored</h3><p>In this article, I will focus mainly on three data augmentation techniques—Mosaic, MixUp, and Copy-Paste.</p><p>These techniques are at the forefront of data augmentation for computer vision tasks and can be easily implemented during YOLO object-detecting model training with the Ultralytics package.</p><p>In this section, I will present an overview of these three strategies, including their implementation and the reasoning behind their selection for the solar panel detection model training.</p><h4>Mosaic Augmentation</h4><p>Mosaic augmentation is a technique that combines various images to create a single composite mosaic image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/505/1*HvzvcyfdaKTmSOv3x2KgGg.png" /><figcaption><strong>Figure 3.</strong> Mosaic Augmentation as Prsented in <a href="https://arxiv.org/pdf/2004.10934.pdf">”YOLOv4: Optimal Speed and Accuracy of Object Detection”</a> by Bochkovskiy et al. 2020</figcaption></figure><p>This strategy increases the diversity of training data and allows the model to incorporate contextual information by monitoring many items in different spatial configurations. Mosaic augmentation is especially useful in object detection tasks, where the model’s ability to recognize items of varied sizes is crucial, as it significantly aids in adapting the model to different object scales and improving detection precision within complex scenarios.</p><p>In the case of detecting solar panels in satellite images with various orientations and resolutions, Mosaic augmentation may directly address this need, ensuring that the model is trained to identify solar panels in a variety of situations representing real-world scenarios.</p><p>To implement mosaic augmentation during the training of the YOLO model for object detection using Ultralytics, a value between 0.0 and 1.0 for the amount of needed augmented data from the total training data should be added as a parameter:</p><pre>from ultralytics import YOLO<br><br># Load a model<br>model = YOLO(&#39;yolov8n.pt&#39;)  # load a pretrained model<br><br># Train the model <br>results = model.train(data=data, epochs=epochs, imgsz=imgsz, mosaic=0.5)</pre><h4>MixUp Augmentation</h4><p>Proposed by Cisse et al. in the paper <a href="https://arxiv.org/pdf/1710.09412.pdf">“mixup: BEYOND EMPIRICAL RISK MINIMIZATION”</a> in 2018, in MixUp augmentation, two dissimilar images are fused together with their respective labels to produce a new composite image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/425/1*fDY6xla9WLGY5Q-45QGV3Q.png" /><figcaption><strong>Figure 4.</strong> MixUp Augmentation as Prsented in <a href="https://arxiv.org/pdf/2004.10934.pdf">”YOLOv4: Optimal Speed and Accuracy of Object Detection”</a> by Bochkovskiy et al. 2020</figcaption></figure><p>The fusion process computes a weighted average of the pixel values from both images, producing an effect that encourages the model to learn more generalized features rather than memorizing specific data points by rote.</p><p>The fusion is implemented for both the images and the labels using the following formulas:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/305/1*omcx5Ml9T9O_8pZE9IoW0w.png" /></figure><p>(Xi, Yi) and (Xj, Yj) are two target vectors from the training data, with X representing the images and Y representing the labels. Xi and Xj are raw input vectors, while Yi and Yj are one-hot label encodings. Lambda values are in the [0, 1] range and are drawn from the beta distribution, which is the MixUp augmentation hyperparameter that controls the degree of interpolation between feature-target pairings.</p><p>A simple application of MixUp augmentation on two images (without the labels) using NumPy and Pillow packages and a random lambda value that is taken from a beta distribution (α = 0.3) can be implemented as follows:</p><pre>from PIL import Image <br>import numpy as np<br><br>def mixup_augmentation(image1, image2, alpha=0.3):<br>    &quot;&quot;&quot;<br>    Mixes two images using the MixUp augmentation technique.<br>    <br>    Args:<br>    image1 (PIL.Image.Image): The first image to mix.<br>    image2 (PIL.Image.Image): The second image to mix, which defines the size of the output image.<br>    alpha (int): The alpha value for the beta distribution<br>    <br>    Returns:<br>    PIL.Image.Image: The resulting mixed image.<br>    float: The generated lambda value used to mix the images.<br>    &quot;&quot;&quot;<br>    # Convert images to arrays<br>    array1, array2 = np.array(image1), np.array(image2)<br>    <br>    # Get the size of image 2, which will be the output image size<br>    shape_array2 = array2.shape<br>    <br>    # Create a new zeros array with the same shape as array2<br>    resized_array1 = np.zeros(shape_array2, dtype=array1.dtype)<br><br>    # Copy the contents of array1 into the resized array<br>    height, width = min(shape_array2[0], array1.shape[0]), min(shape_array2[1], array1.shape[1])<br>    resized_array1[:height, :width] = array1[:height, :width]<br>    <br>    # Replace zero-valued coordinates in resized_array1 with values from bigger array2<br>    zero_mask = (resized_array1 == 0)<br>    resized_array1[zero_mask] = array2[zero_mask]<br><br>    # Generate the lambda value from a suggested Beta distribution<br>    lam = np.random.beta(alpha, alpha)<br><br>    # Mix the images<br>    mixed_array = lam * resized_array1 + (1 - lam) * array2<br><br>    # Convert the mixed array back to an image<br>    mixed_image = Image.fromarray(np.uint8(mixed_array))<br><br>    return mixed_image, lam</pre><p>MixUp regularizes the neural network, promoting simple linear behavior between training samples and enhancing the generalization of advanced neural network models, improving neural network training by decreasing corrupt label memorization. It’s particularly good for enhancing the model’s ability to perform well on new, unseen data, thereby improving its robustness and reducing overfitting.</p><p>To implement MixUp augmentation during the training of object detection model with Ultralytics, similarly to mosaic augmentation, a parameter between 0.0 and 1.0 should be added for the amount of required augmented data:</p><pre>from ultralytics import YOLO<br><br># Load a model<br>model = YOLO(&#39;yolov8n.pt&#39;)  # load a pretrained model<br><br># Train the model<br>results = model.train(data=data, epochs=epochs, imgsz=imgsz, mixup=0.5)</pre><h4>Copy-Paste Augmentation</h4><p>Most commonly used in instance segmentation tasks, by copying objects from one image and pasting them into another, Copy-Paste augmentation enhances the model’s ability to detect objects in varying contexts and backgrounds.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*XXavndeEdOzgj3wBOSjnng.png" /><figcaption><strong>Figure 5. </strong>Copy-Paste Augmentation As Prsented in <a href="https://arxiv.org/abs/2012.07177">”Simple Copy-Paste is a Strong Data Augmentation Method for Instance Segmentation”</a> by Ghiasi et al. 2020</figcaption></figure><p>The Copy-Paste augmentation approach involves extracting pixels from one image and integrating them into another, thereby increasing the model’s exposure to objects in a variety of contextual backgrounds and lighting situations. Additionally, it enhances effective self-training strategies by including more unlabeled images.</p><p>This technique is useful for training models to recognize and properly detect objects in a wide range of settings and backdrops, considerably boosting their adaptability and performance in real-world scenarios.</p><p>The implementation of copy paste augmentation during the training of object detection YOLO using Ultralytics is similar:</p><pre>from ultralytics import YOLO<br><br># Load a model<br>model = YOLO(&#39;yolov8n.pt&#39;)  # load a pretrained model<br><br># Train the model<br>results = model.train(data=data, epochs=epochs, imgsz=imgsz, copy_paste=0.5)</pre><h3>Augmentation-Comparison Experiment</h3><p>For the Augmentation Comparison Experiment, I trained several experimental solar panel-detector models to compare and evaluate the effectiveness of the previously discussed augmentations: mosaic, mixup, and copy-paste (Fig. 6) in enhancing a satellite imaging-based solar panel-detecting model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/482/1*v9j1FCty9yKIVRz7ZPIqow.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*cJiJOHuGr1B4b-hoNbP6YA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/477/1*ELTQDcPxgyXg9siP6xz-7g.jpeg" /><figcaption><strong>Figure 6.</strong> Visual Comparison of Augmented Training Data: Mosaic, MixUp, and Copy-Paste Techniques</figcaption></figure><p>For further investigation, I conducted an experiment using a training set containing 0.8 mosaic and 0.2 mixup augmentations. Another experiment trained on a data set with no augmentations, serving as a baseline (Fig. 7).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/957/1*NfSRLorFLALV3OJcyAY0xw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/482/1*RQ0xguwIhQIW2X3Z-RDxJQ.jpeg" /><figcaption><strong>Figure 7.</strong> Augmentation Strategies in Action: Mosaic 0.8 MixUp 0.2 vs. No Augmentation</figcaption></figure><h4>Data Pre-processing</h4><p>The data for this study was obtained using the <a href="https://blog.roboflow.com/">Roboflow🤖</a> platform, where a total of 8,474 satellite images with solar panels were carefully selected and subjected to a post-labeling analysis to improve their quality for the training process.</p><p>The data was divided into three splits: 70% training (5,932 images), 20% validation (1,697 images), and 10% testing (845 images).</p><p>Additional preprocessing:</p><ol><li><strong>Auto-Orientation:</strong> standardizes image orientation and pixel arrangement.</li><li><strong>Resize:</strong> images were stretched to<strong> 640x640 </strong>in preparation for YOLO model training.</li><li><strong>Bounding-Box Shear Augmentation:</strong> Increasing perspective variability to strengthen the model’s robustness. This procedure increased the training data set to 17,791 images.</li></ol><p>All training experiments were performed under identical conditions to isolate the augmentation effect:</p><ol><li><strong>Same dataset split</strong></li><li><strong>Same random built-in hyperparameters</strong> of the Ultralytics package</li><li><strong>Close_mosaic hyperparameter was set to 0</strong> to prevent from stopping the training on the augmented data in the last 10 iterations</li><li>All trainings have been performed on a <strong>free Google Colab T4-GPU for 20 iterations</strong></li><li>Experiments were managed and <strong>analyzed with </strong><a href="https://clear.ml/"><strong>ClearML</strong></a><strong> platform</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aCUkzA9ozmdG4K5JFE0A7w.png" /><figcaption><strong>Figure 8.</strong> Augmentation Comparison Experiment Summary with ClearML</figcaption></figure><h3>Results and Discussion</h3><p>The results of the augmentation-comparison experiment focus on how different data augmentation procedures affect the performance of the solar panel detection model. My evaluation was focused on 4 metrics:</p><ol><li><strong>Training time</strong></li><li><strong>Validation Precision: </strong>calculated as the number of true positive detections (TP) divided by the total number of solar panels the model identified (TP + FP)</li><li><strong>Validation Recall: </strong>calculated as the number of true positive detections (TP) divided by the total number of solar panels (TP + FN)</li><li><strong>Validation mAP50: </strong>determined by finding the mean Average Precision (mAP) at Intersection over Union (IoU) threshold of 50, which mean that the overlap between the predicted bounding box and the ground truth bounding box is above 50%</li></ol><h4>Training Time</h4><p>Based on the data in Figures 8 and 9, it is clear that the <strong>MixUp augmentation significantly increases the training length per iteration</strong>, especially in the final five epochs, where each iteration went on for almost twice as long as the experiment did without any augmentations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*anvSqj1afrIr45JAK1uM8g.png" /><figcaption><strong>Figure 9.</strong> Training Time per Iteration</figcaption></figure><p>As expected, training the model without any augmentation was the most time-efficient approach. Mosaic and copy-paste augmentations resulted in approximately 10% longer training periods than without augmentations.</p><p>A notable observation is that integrating a small amount of MixUp augmentation (0.2) into the Mosaic training regimen considerably increases training time, from roughly 550 seconds per iteration for mosaic augmented data training to 650 seconds.</p><h4>Precision Recall and mAP Scores</h4><p>The analysis of the training confusion matrices for Mosaic and MixUp augmentations experiments (Fig. 10) reveals a superior training outcome for the Mosaic model, as indicated by a true positive (TP) rate of 11,697, compared to MixUp’s TP rate of 10,922, and reduced false detections for both false positive (FP) with 2603 to 3688 and false negative (FN) with 2093 to 2868.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I10ku4WtCJmfPiS9cNI-rA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DobDkH6P7iZF39MZHryLbA.png" /><figcaption><strong>Figure 10.</strong> Confusion Matrices for Mosaic and MixUp Training</figcaption></figure><p>The final results of the experiment (Fig. 11) and the mAP scores plot (Fig. 12) highlight the distinct influence of data augmentation strategies on the performance of an object detection model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/663/1*14TAmQtxYEVxRXjWmGcgeQ.png" /><figcaption><strong>Figure 11.</strong> Final Validation Scores</figcaption></figure><h4><strong>Mixup Augmentation</strong></h4><p>Surprisingly,<strong> the Mixup augmentation strategy had the lowest scores across all parameters</strong>. With a mAP of 0.805, precision of 0.836, and a significantly lower recall of 0.728, these results, along with the lagging mAP scored during the entire experiment, indicate that Mixup’s approach to feature generalization for this use case may have resulted in an inability to generalize the patterns and detect solar panels in satellite images, decreasing its effectiveness in this sort of detection task.</p><h4><strong>Mosaic Augmentation</strong></h4><p>The Mosaic augmentation appeared as the <strong>obvious winner of the</strong> <strong>“Solar Panel Detection Contest&quot;</strong> as it significantly enhanced model accuracy with the highest mAP, precision, and recall scores of 0.873, 0.882, and 0.803, respectively. The arrangements of mosaic images are likely to supply the model with additional diversely scaled training data, enhancing the model’s ability to generalize accurately and spot solar panels in a variety of circumstances.</p><h4><strong>Effect of Partial Mixup (0.2 Mixup)</strong></h4><p>Adding a small amount of MixUp augmented data (20%) to the Mosaic training regimen resulted in a decline in performance measures, with a mAP of 0.859, precision of 0.874, and recall of 0.786, indicating that the <strong>MixUp augmentation strategy is completely inappropriate for this task.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jpvlhGph_5U2PuNyMzs7Wg.png" /><figcaption><strong>Figure 12.</strong> mAP Scores Across Augmentations</figcaption></figure><h4><strong>No Augmentation</strong></h4><p>The model trained on a non-augmented data set beat those trained with MixUp augmentation. This finding suggests that <strong>using plain, unaugmented data in some detection tasks may be beneficial</strong>, especially when time and resource restrictions are considered.</p><h4><strong>Copy-Paste Augmentation</strong></h4><p>Interestingly, despite the longer training time per iteration, training on the Copy-Paste augmented data set performed identically to the no-augmentation strategy, with the same mAP, precision, and recall values, as well as the same training trend as the line blended with the no-augmentation line on the mAP scores line plot. This conclusion emphasizes the significance of selecting the optimum augmentation strategy for the work at hand in order to maximize resource consumption, particularly in scenarios involving GPU usage.</p><h3>Conclusion</h3><p>This study provides empirical evidence demonstrating how data augmentation strategies (Mosaic, MixUp, and Copy-Paste) impact the accuracy and training efficiency of object detection models.</p><p><strong>Mosaic augmentation emerged as the best strategy for this task</strong>, improving model accuracy by allowing for various object scales and complex image compositions. This finding highlights the need for rich, contextual training data to enhance object detection models, particularly for detecting small objects such as solar panels in aerial images.</p><p>In contrast, despite its theoretical promise,<strong> MixUp augmentation performed poorly in this case</strong>, most likely due to feature overgeneralization, which misled rather than helped the model in the detection task. I believe that this method is better suited for use scenarios in which the objects are larger, as the new fussioned data will reveal new dimensions of the objects that will improve training quality.</p><p><strong>Copy-paste augmentation did not improve the model’s ability to detect solar panels</strong>, presumably because it did not include any additional learning features. As mentioned by Ghiasi et al. (2020), this strategy is appropriate for segmentation tasks since the segmented object shapes tend to vary scene-specifically, and this is why the copy-paste augmented data set will increase the potentially learned object characteristics variance.</p><p>The goal of this article is to shed light on the critical significance of data augmentation in object detection models as well as provide a guide for selecting the best augmentation procedures to achieve superior model performance in real-world applications, particularly in similar use cases such as detecting solar panels from satellite images.</p><h3>References</h3><p>[1] <a href="https://medium.com/r?url=https%3A%2F%2Flevelup.gitconnected.com%2Fsolar-panel-detector-guide-to-an-end-to-end-computer-vision-project-using-nothing-but-free-a7ee3610de43">Drabkin, A., Solar-Panel-Detector: Guide to an End-to-End Computer Vision Project Using Nothing-But-Free Software (2024)<em>“Level Up Coding”</em></a></p><p>[2] <a href="https://journalofbigdata.springeropen.com/articles/10.1186/s40537-019-0197-0">Shorten, C., &amp; Khoshgoftaar, T. M., A survey on Image Data Augmentation for Deep Learning (2019) <em>Journal of Big Data</em>, 6(1), 60</a></p><p>[3] <a href="https://arxiv.org/abs/2004.10934">Bochkovskiy, A., Wang, C.-Y., &amp; Liao, H.-Y. M, YOLOv4: Optimal Speed and Accuracy of Object Detection (2020)</a> <a href="https://arxiv.org/abs/2004.10934"><em>arXiv preprint arXiv:2004.10934</em></a></p><p>[4] <a href="https://arxiv.org/abs/1710.09412">Cisse, M., Bojanowski, P., Grave, E., Dauphin, Y., &amp; Usunier, N., mixup: Beyond Empirical Risk Minimization(2018) <em>arXiv preprint arXiv:1710.09412</em></a></p><p>[5] <a href="https://arxiv.org/abs/2012.07177">Ghiasi, G., Cui, Y., Srinivas, A., Qian, R., Lin, T.-Y., Cubuk, E. D., Le, Q. V., &amp; Zoph, B., Simple Copy-Paste is a Strong Data Augmentation Method for Instance Segmentation (2020) <em>arXiv preprint arXiv:2012.07177</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=02a5944d7b80" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/enhancing-object-detection-in-aerial-imagery-a-comparative-study-of-data-augmentation-techniques-02a5944d7b80">Enhancing Object Detection in Aerial Imagery: A Comparative Study of Data Augmentation Techniques</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Solar-Panel-Detector: Guide to an End-to-End Computer Vision Project Using Nothing-But-Free…]]></title>
            <link>https://levelup.gitconnected.com/solar-panel-detector-guide-to-an-end-to-end-computer-vision-project-using-nothing-but-free-a7ee3610de43?source=rss-154addae9f7c------2</link>
            <guid isPermaLink="false">https://medium.com/p/a7ee3610de43</guid>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[solar-energy]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[deployment]]></category>
            <dc:creator><![CDATA[Ariel Drabkin]]></dc:creator>
            <pubDate>Mon, 01 Jan 2024 21:56:45 GMT</pubDate>
            <atom:updated>2024-11-14T07:51:24.327Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Solar-Panel-Detector: Guide to an </strong>End-to-End Computer Vision Project Using Nothing-But-Free Software</h3><h3>Abstract</h3><p>This article describes how to turn a business idea into an application through an end-to-end computer vision project developed around the state-of-the-art YOLOv8 model for object detection.</p><p>Each step is described in detail:</p><ol><li>The idea and the problem it suggests solving.</li><li>Data collection and organization.</li><li>Model training and evaluation processes.</li><li>Transformation of the technology into a user-friendly application.</li><li>Web deployment.</li></ol><p>Using free software tools for each phase of the process demonstrates that technological initiatives can be attainable with open source code and freely available software and platforms.</p><p>Let&#39;s start the solar revolution, one pixel at a time.</p><figure><img alt="“Generate a widescreen image of a futuristic cityscape during twilight. The city has a vibrant network of buildings with high-tech solar panels on their roofs, all illuminated by the soft glow of the setting sun in the background. Above the city, a large, advanced solar panel floats, connected by glowing energy lines to the infrastructure below. These lines represent a smart grid, indicative of a city powered entirely by renewable energy.“" src="https://cdn-images-1.medium.com/max/1024/1*XAONsRtkbKQK3rXjT65MvQ.png" /><figcaption>Created with Dall-E image generator (prompt in the image Alt text)</figcaption></figure><blockquote>“If the mountain won’t come to Muhammad,</blockquote><blockquote>then Muhammad must go to the mountain.“</blockquote><blockquote>Francis Bacon’s Essays (1625)</blockquote><blockquote>That was the thinking behind the idea of the Solar Panel Detector.</blockquote><h3><strong>Introduction</strong></h3><h4>Solar Energy</h4><p>At the present point in human history, it is widely acknowledged that embracing the use of renewable energy resources, particularly solar energy, is a key player in cutting down on the use of fossil fuels [<a href="https://www.iea.org/news/global-coal-demand-expected-to-decline-in-coming-years">1</a>]. This shift is crucial as it directly contributes to decreasing greenhouse gas emissions into the atmosphere[<a href="https://news.climate.columbia.edu/2022/10/26/solar-panels-reduce-co2-emissions-more-per-acre-than-trees-and-much-more-than-corn-ethanol/">2</a>] (<em>Eisenson, 2022</em>), which in turn helps reduce the global warming effect and climate change[<a href="https://www.nature.com/articles/nclimat">3</a>] (<em>Hu et al., 2015</em>).</p><p>Regardless of one’s interest in climate change, the financial savings from using solar energy for private households are undeniable and attractive to all.</p><p>Yet, according to the International Energy Agency (IEA), currently only around <strong>25 million</strong> households globally use solar panel systems[<a href="https://www.iea.org/reports/approximately-100-million-households-rely-on-rooftop-solar-pv-by-2030">4</a>], as the vast majority of people around the world have their roofs free of solar panels.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/225/1*JYhMFAc_V3Y7tPYQWlBFLg.png" /><figcaption>Figure 1. Attention gif #1 (<strong>credit:</strong> <a href="https://tenor.com/"><strong>https://tenor.com/</strong></a><strong>)</strong></figcaption></figure><h4>Why is the adoption of solar panels lagging?</h4><ol><li>The first reason could be regulation-related. While the global trend is towards greater adoption of solar energy, the regulatory environment plays a crucial role in determining the pace and scale of this adoption. Diverse policies and incentives, along with practical challenges such as local opposition and the need for infrastructure development, shape the solar energy landscape in different regions.</li><li>Another reason is the belief that the return on investment of a solar panel installation is not significant enough. However, on average, it can take <strong>10 to 13</strong> years for solar panels to recoup the initial outlay, and they can last <strong>25</strong> years or more[<a href="https://thumbwind.com/2022/12/16/why-dont-more-homes-have-solar-panels-installed/#the-cost-of-solar-panels">5</a>], which makes them a worthwhile long-term investment​​.</li><li>The third, and in my opinion, <strong>the most significant barrier</strong>, is the challenge of changing habits.</li></ol><p>While many are keen to contribute to a brighter future and enjoy reduced energy costs, switching to something as unfamiliar as solar energy can be intimidating. It’s not just about installing and connecting panels; it’s about adapting to a new way of living.</p><p>Luckily, initiatives like <a href="https://www.greendaysenergy.com/"><strong>#GreenDays</strong></a>, <a href="https://sunroof.withgoogle.com/"><strong>#SunRoof Project</strong></a> and <a href="https://www.energysage.com/"><strong>#Energysage</strong></a> are fantastic resources, offering comprehensive information on savings and the benefits of installing solar panels, as well as connecting people with potential installation providers.</p><p>Yet, these initiatives do not overcome the challenge of people who are interested in joining the solar revolution but hesitate to take that first step.</p><h4>Introducing the Solar-Panel-Detector 🛰️☀️</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/690/1*2rbNxTkJLAcggGG0Dl5ERg.gif" /><figcaption>Figure 2. Demo of the Solar-Panel-Detector. You can try it yourself <a href="https://arieldrabkin-solar-panel-detector.hf.space/"><strong>here</strong></a>🛰️☀️</figcaption></figure><p><strong>Q. What is the Solar-Panel-Detector?</strong></p><p>The Solar Panel Detector is a user-friendly application that utilizes an AI-driven object detection algorithm to identify solar panels in satellite images and confirm their presence at a given location.</p><p><strong>Q. How is the Solar-Panel-Detector used?</strong></p><p>With the combination of interactive global mapping services, the solar panel detection model can be applied to provide information regarding any given address or geographical coordinates, whether it has a solar panel or not.</p><p><strong>Q. Which outputs could the Solar-Panel-Detector produce?</strong></p><p>The key output of the Solar-Panel-Detector is identifying addresses without solar panels. These locations represent potential customers for solar energy initiatives, which makes this tool essential for companies aiming to expand their customer base in the solar energy market.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*YUNuxNsMZvfSSj0rdDvqBg.gif" /><figcaption>Figure 3. Attention gif #2 (<strong>credit:</strong> <a href="https://tenor.com/"><strong>https://tenor.com/</strong></a><strong>)</strong></figcaption></figure><h3>Methods</h3><p>The creation of the Solar-Panel-Detector project involved a series of orchestrated steps, utilizing the next cutting-edge tools and technologies:</p><ol><li><a href="https://app.roboflow.com/">Roboflow</a> 🤖</li><li><a href="https://www.ultralytics.com/yolo">Ultralytics</a> 🌊</li><li><a href="https://colab.research.google.com/">Google colab</a> ♾️</li><li><a href="https://lightning.ai/">Lightning AI</a>⚡</li><li><a href="https://clear.ml/">ClearML</a> 📉</li><li><a href="https://developers.google.com/maps/documentation/maps-static">Google Maps API</a> 🗺️</li><li><a href="https://www.gradio.app/">Gradio</a> 🎢</li><li><a href="https://huggingface.co/docs/hub/spaces-overview">Hugging Face Spaces</a> 🤗</li></ol><p>The Ultralytics open-source, state-of-the-art YOLOv8 object-detecting model was trained on satellite imaging data to detect solar panels.</p><p>Additionally, the Google Maps static API was used to get the satellite imagery of a specific geo-location.</p><p>The developed functions were wrapped up in a Gradio interface to create a user-friendly GUI that was later deployed on Hugging Face Space.</p><p>The code for each step is available in the project’s git repository: <a href="https://github.com/ArielDrabkin/Solar-Panel-Detector"><strong>🐈‍⬛</strong></a></p><p>Here is a step-by-step overview of how the project was brought to life:</p><h4>Data Preparation</h4><p>Utilizing Roboflow, I accessed relevant datasets, selecting <strong>8,474</strong> specific use case images for further processing. These images underwent post-labeling analysis to optimize their quality. The dataset was split into 70% training (<strong>5,932</strong> images), 20% validation (<strong>1,697 </strong>images), and 10% testing (<strong>845</strong> images) sets.</p><p>Key preprocessing stages included:</p><ul><li><a href="https://medium.com/r?url=https%3A%2F%2Fblog.roboflow.com%2Fexif-auto-orientation%2F"><strong>Auto-Orientation:</strong></a><strong> </strong>Standardizing image orientation and pixel ordering.</li><li><a href="https://blog.roboflow.com/you-might-be-resizing-your-images-incorrectly/"><strong>Resize:</strong></a> Stretching images to<strong> 640x640</strong>, preparing them for YOLO training.</li><li><a href="https://blog.roboflow.com/shear-augmentation/"><strong>Bounding-Box Shear Augmentation</strong></a><strong>: </strong>Enhancing perspective variability to boost the model’s resilience. This process tripled the training set to <strong>17,791</strong> images.</li><li><strong>Mosaic Augmentation:</strong> In pursuit of optimal model performance, I performed a comparison experiment to determine the most effective augmentation technique for the task among mosaic, mixup, and copypaste. The outcomes of this experiment, along with a detailed discussion of the selected mosaic augmentation method, are available in the article <a href="https://levelup.gitconnected.com/enhancing-object-detection-in-aerial-imagery-a-comparative-study-of-data-augmentation-techniques-02a5944d7b80">“Enhancing Object Detection in Aerial Imagery: A Comparative Study of Data Augmentation Techniques”</a>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/959/1*68LHf9UBY8BZljE23KTdTA.jpeg" /><figcaption>Figure 4. Batch from the labeled data</figcaption></figure><p>You can find the data set <a href="https://universe.roboflow.com/ariel-drabkin-tifqg/solar-panel-detector-imvoh/dataset/1"><strong>here</strong></a>.</p><h4><strong>Data Training</strong></h4><p>Leveraging the computational power of Google Colab and Lightning AI, a YOLOv8n model (<strong>~3.2</strong> million parameters) was trained over<strong> 40</strong> epochs.</p><p>The initial stages of training, focusing on hyperparameter tuning and model selection, were performed via the Google-Colab T4 GPU machine. The final model training was executed on a LightningAI GPU-powered virtual machine.</p><h4><strong>Training management and Analysis</strong></h4><p>ClearML was used to monitor the training process, allowing for detailed training analysis and model evaluations. The final training analysis set is available <a href="https://embed.clear.ml/projects/eebd747872564ba1a88240712feb86af/experiments/facfec77d44c40de992245e9cde333df/output/metrics/plots"><strong>here</strong></a>.</p><h4><strong>Image Acquisition</strong></h4><p>A Google Maps static API was used with the requests package for retrieving satellite images corresponding to specific addresses.</p><h4><strong>Interface Development</strong></h4><p>The Hugging Face Gradio package was used to design a user-friendly interface that accepts either an address or a satellite image and returns a prediction that includes a verbal prediction and an image with the predicted solar panel bounding box for the presence or absence of solar panels.</p><h4><strong>Deployment</strong></h4><p>The final model was hosted on HuggingFace Spaces, which is an excellent platform for deploying Gradio-based apps, making the application available to every user with online access. You can try it out for yourself <a href="https://huggingface.co/spaces/ArielDrabkin/Solar-Panel-Detector"><strong>here</strong></a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*Jak6uRpUTdJNk1eICAgpkw.gif" /><figcaption>Figure 5. Attention gif #3 (<strong>credit:</strong> <a href="https://tenor.com/"><strong>https://tenor.com/</strong></a><strong>)</strong></figcaption></figure><h3><strong>Results</strong></h3><p>Final Solar-Panel-Detector model was trained on a LightningAI virtual machine with a T4 GPU for <strong>40 epochs</strong> during <strong>2:09 hours.</strong> The model did not reach full convergence yet achieved <strong>0.903 mean Average Precision</strong> (<strong>mAP)</strong>,<strong> 0.915 precision</strong>, and <strong>0.835 recall </strong>scores, which are notable considering the relatively short and efficient training duration.</p><h4>Comparative Analysis</h4><p>For context, a comparison was made with a model trained using Roboflow’s automatic training setup, which utilized default hyperparameters (details available <a href="https://app.roboflow.com/ariel-drabkin-tifqg/solar-panel-detector-imvoh/1"><strong>here</strong></a>). The Roboflow model achieved slightly higher scores, but it underwent a significantly longer training period of <strong>300 epochs</strong> in <strong>20 hours,</strong> reaching scores of <strong>0.906 mAP, 0.926 precision</strong>, and <strong>0.838 recall.</strong></p><p>The training results of the Solar Panel Detector final model are shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z3PiM1a2WVPdw4ZKNdLgYA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TzJzeP4c6DOGWymn_UceIQ.png" /><figcaption>Table 1. Results of final model training</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SD89rrJIpUzT1QQ_e5w9Yw.png" /><figcaption>Figure 6. Results of final model training</figcaption></figure><h4>Overall Performance</h4><p>The model showed positive training dynamics, with the model improving on all fronts: bounding box localization (accurately identifying the location of solar panels), classification accuracy, precision (correctness of positive predictions), recall, and mean mAP.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QFpV7U36hTPd1kXM6zzEpQ.jpeg" /><figcaption>Figure 7. Labeled batch from validation set</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UinZ6vv66v0GePXkagoapA.jpeg" /><figcaption>Figure 8. Predicted batch from validation set</figcaption></figure><p>These trends are indicative of the model’s ability to learn effectively and generalize its knowledge to new, unseen data from the validation set.</p><h4>Confusion Matrix Analysis</h4><p>A closer look at the training set confusion matrix revealed that the model successfully detected<strong> 12,071</strong> solar panels (<strong>True Positives</strong>). However, it missed <strong>1,719</strong> solar panels (<strong>False Negatives</strong>) and incorrectly identified <strong>2,130</strong> objects as solar panels (<strong>False Positives</strong>).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NzBGtIbE_4_tBvAXKgL4Ig.png" /><figcaption>Figure 9. Training confusiom matrix plot</figcaption></figure><h4>Precision-Recall Curve</h4><p>This curve showed that the model achieved a <strong>mean Average Precision</strong> <strong>(mAP)</strong> of <strong>0.903</strong> at a confidence threshold of <strong>0.5</strong>. This means that when the model is <strong>50%</strong> sure, it’s correct about <strong>90.3%</strong> of the time in identifying solar panels.</p><h4>F1-Confidence Curve</h4><p>According to this curve, the model’s best <strong>F1 score</strong>—balancing <strong>precision and recall</strong>—is <strong>0.87</strong>, achieved at a confidence threshold of <strong>0.415</strong>. This suggests that the model performs best at distinguishing solar panels from the background when it is just over <strong>41%</strong> confident in its prediction.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DaZzdAo_ZE2LOuuPRcOe1A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V_dOpFEgZxHFudqHxbrdiQ.png" /><figcaption>Figure 10. Precision-recall and F1-Condifence Curves of the validation results plots</figcaption></figure><h3><strong>Discussion</strong></h3><p>Training an advanced model to yield accurate predictions solely with free software tools is undeniably challenging. Despite these hurdles, the Solar-Panel-Detector has achieved noteworthy results.</p><p>The model not only demonstrates robust performance but also stands as a testament to the potential of open-source tools in advanced AI projects.</p><p>A key observation from the model&#39;s results is the significantly lower number of false negatives in comparison to the true positives, indicating that the model has excellent recall or sensitivity, which means the model is quite adept at identifying solar panels when they are indeed present.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*84cdczmZrqkHU4UAYANmnQ.gif" /><figcaption>Figure 11. Attention gif #4 (<strong>credit:</strong> <a href="https://tenor.com/"><strong>https://tenor.com/</strong></a><strong>)</strong></figcaption></figure><h4>Optimizing the Confidence Threshold</h4><p>Based on the results, setting the confidence threshold between <strong>0.415 and 0.5</strong> seems optimal. This range strikes a balance, ensuring high precision (accuracy of positive predictions) while maintaining a robust F1 score (a measure that balances precision and recall).</p><h4>Addressing False Positives</h4><p>The occurrence of false positives is relatively high. This suggests that the model sometimes incorrectly identifies other objects as solar panels. To enhance the model’s accuracy, alongside the obvious longer training approach, several approaches could be taken:</p><ul><li><strong>Upgrading the Model:</strong> Employing a more advanced YOLO model with a higher number of parameters could increase accuracy.</li><li><strong>Hyperparameter Tuning:</strong> Expanding the scope of hyperparameter tuning could fine-tune the model’s performance.</li><li><strong>In-Depth Error Analysis: </strong>Perform an error analysis to pinpoint where the model underperforms. Following this, the model can be retrained with increased focus or weight on these weaker data points to enhance overall accuracy.</li><li><strong>Expanding Labeling for Better Discrimination:</strong> By incorporating additional labels for objects that are commonly mistaken for panels into the training dataset, the model can learn to recognize and distinguish potential distractors more effectively.</li><li><strong>Data Expansion for Specific Cases:</strong> By gathering more data on the scenarios where the model struggles, we can improve the model’s ability to accurately identify solar panels in these challenging situations.</li></ul><h3>Conclusion</h3><p>The development of the Solar Panel Detector app illustrates the promise of using the power of artificial intelligence for environmental sustainability. By combining advanced object detection algorithms with accessible satellite imagery, this tool provides a unique solution to a global challenge—accelerating the adoption of solar energy.</p><p>In showcasing this project, my goal was not only to highlight a tool that can identify potential customers for solar panel installations but also provide a practical, step-by-step guide for anyone interested in undertaking an end-to-end AI computer vision project using entirely free tools.</p><p>This approach opens doors to a world where technology, environmental consciousness, and the spirit of open-source learning unite to create impactful solutions for a better world.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*q6I_TxJp45xcEoYZvY5zEw.gif" /><figcaption>Figure 12. Attention gif #5 (<strong>credit:</strong> <a href="https://tenor.com/"><strong>https://tenor.com/</strong></a><strong>)</strong></figcaption></figure><p>Didn’t tried the Solar Panel Detector yet? Here it is:</p><p><a href="https://arieldrabkin-solar-panel-detector.hf.space/">Solar Panel Detector</a></p><h3>References</h3><p><strong>[1]</strong> <a href="https://www.iea.org/news/global-coal-demand-expected-to-decline-in-coming-years"><strong>Global coal demand expected to decline in coming years — News — IEA</strong></a></p><p><strong>[2]</strong> <a href="https://news.climate.columbia.edu/2022/10/26/solar-panels-reduce-co2-emissions-more-per-acre-than-trees-and-much-more-than-corn-ethanol/"><strong>Solar Panels Reduce CO2 Emissions More Per Acre Than Trees — and Much More Than Corn Ethanol</strong></a></p><p><strong>[3]</strong> <a href="https://doi.org/10.1038/nclimate2843"><strong>Impact of solar panels on global climate — Nature Climate Change</strong></a></p><p><strong>[4]</strong> <a href="https://www.iea.org/reports/approximately-100-million-households-rely-on-rooftop-solar-pv-by-2030"><strong>Approximately 100 million households rely on rooftop solar PV by 2030 — Analysis — IEA</strong></a></p><p><strong>[5]</strong> <a href="https://thumbwind.com/2022/12/16/why-dont-more-homes-have-solar-panels-installed/#the-cost-of-solar-panels"><strong>Why Don’t More Homes Have Solar Panels Installed In 2023</strong></a></p><p><strong>[6] </strong><a href="https://docs.roboflow.com/"><strong>Roboflow docs</strong></a></p><p><strong>[7] </strong><a href="https://docs.ultralytics.com/models/yolov8/#overview"><strong>YOLOv8 docs</strong></a></p><p><strong>[8] </strong><a href="https://colab.research.google.com/notebooks/basic_features_overview.ipynb"><strong>Colab overview</strong></a></p><p><strong>[9] </strong><a href="https://clear.ml/docs/latest/docs/"><strong>ClearML docs</strong></a></p><p><strong>[10] </strong><a href="https://developers.google.com/maps/documentation/maps-static"><strong>Google Maps Static docs</strong></a></p><p><strong>[11] </strong><a href="https://www.gradio.app/docs/interface"><strong>Gradio docs</strong></a></p><p><strong>[12] </strong><a href="https://huggingface.co/docs/hub/spaces-overview"><strong>Hugging Face Spaces overview</strong></a></p><p><strong>[13] </strong><a href="https://levelup.gitconnected.com/enhancing-object-detection-in-aerial-imagery-a-comparative-study-of-data-augmentation-techniques-02a5944d7b80"><strong>Enhancing Object Detection in Aerial Imagery: A Comparative Study of Data Augmentation Techniques</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a7ee3610de43" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/solar-panel-detector-guide-to-an-end-to-end-computer-vision-project-using-nothing-but-free-a7ee3610de43">Solar-Panel-Detector: Guide to an End-to-End Computer Vision Project Using Nothing-But-Free…</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>