mirror of
https://github.com/bellingcat/RS4OSINT.git
synced 2026-06-11 04:58:35 +03:00
fixed image paths
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
|
||||
|
||||
|
||||
<title>Remote Sensing for OSINT - 12 Object Detection</title>
|
||||
<title>Remote Sensing for OSINT - Object Detection</title>
|
||||
<style>
|
||||
code{white-space: pre-wrap;}
|
||||
span.smallcaps{font-variant: small-caps;}
|
||||
@@ -202,20 +202,17 @@ gtag('config', 'G-RK9ZLZQ6GL', { 'anonymize_ip': true});
|
||||
<ul id="quarto-sidebar-section-1" class="collapse list-unstyled sidebar-section depth1 ">
|
||||
<li class="sidebar-item">
|
||||
<div class="sidebar-item-container">
|
||||
<a href="./index.html" class="sidebar-item-text sidebar-link">
|
||||
<span class="menu-text"><span class="chapter-number">1</span> <span class="chapter-title">Overview</span></span></a>
|
||||
<a href="./index.html" class="sidebar-item-text sidebar-link"><span class="chapter-title">Overview</span></a>
|
||||
</div>
|
||||
</li>
|
||||
<li class="sidebar-item">
|
||||
<div class="sidebar-item-container">
|
||||
<a href="./A2_Remote_Sensing.html" class="sidebar-item-text sidebar-link">
|
||||
<span class="menu-text"><span class="chapter-number">2</span> <span class="chapter-title">Remote Sensing</span></span></a>
|
||||
<a href="./A2_Remote_Sensing.html" class="sidebar-item-text sidebar-link"><span class="chapter-title">Remote Sensing</span></a>
|
||||
</div>
|
||||
</li>
|
||||
<li class="sidebar-item">
|
||||
<div class="sidebar-item-container">
|
||||
<a href="./A3_Data_Acquisition.html" class="sidebar-item-text sidebar-link">
|
||||
<span class="menu-text"><span class="chapter-number">3</span> <span class="chapter-title">Data Acquisition</span></span></a>
|
||||
<a href="./A3_Data_Acquisition.html" class="sidebar-item-text sidebar-link"><span class="chapter-title">Data Acquisition</span></a>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
@@ -231,26 +228,22 @@ gtag('config', 'G-RK9ZLZQ6GL', { 'anonymize_ip': true});
|
||||
<ul id="quarto-sidebar-section-2" class="collapse list-unstyled sidebar-section depth1 ">
|
||||
<li class="sidebar-item">
|
||||
<div class="sidebar-item-container">
|
||||
<a href="./B1_Getting_Started.html" class="sidebar-item-text sidebar-link">
|
||||
<span class="menu-text"><span class="chapter-number">4</span> <span class="chapter-title">Getting Started</span></span></a>
|
||||
<a href="./B1_Getting_Started.html" class="sidebar-item-text sidebar-link"><span class="chapter-title">Getting Started</span></a>
|
||||
</div>
|
||||
</li>
|
||||
<li class="sidebar-item">
|
||||
<div class="sidebar-item-container">
|
||||
<a href="./B2_Interpreting_Images.html" class="sidebar-item-text sidebar-link">
|
||||
<span class="menu-text"><span class="chapter-number">5</span> <span class="chapter-title">Interpreting Images</span></span></a>
|
||||
<a href="./B2_Interpreting_Images.html" class="sidebar-item-text sidebar-link"><span class="chapter-title">Interpreting Images</span></a>
|
||||
</div>
|
||||
</li>
|
||||
<li class="sidebar-item">
|
||||
<div class="sidebar-item-container">
|
||||
<a href="./B3_Image_Series.html" class="sidebar-item-text sidebar-link">
|
||||
<span class="menu-text"><span class="chapter-number">6</span> <span class="chapter-title">Image Series</span></span></a>
|
||||
<a href="./B3_Image_Series.html" class="sidebar-item-text sidebar-link"><span class="chapter-title">Image Series</span></a>
|
||||
</div>
|
||||
</li>
|
||||
<li class="sidebar-item">
|
||||
<div class="sidebar-item-container">
|
||||
<a href="./B4_Vectors_Tables.html" class="sidebar-item-text sidebar-link">
|
||||
<span class="menu-text"><span class="chapter-number">7</span> <span class="chapter-title">Vectors and Tables</span></span></a>
|
||||
<a href="./B4_Vectors_Tables.html" class="sidebar-item-text sidebar-link"><span class="chapter-title">Vectors and Tables</span></a>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
@@ -266,32 +259,27 @@ gtag('config', 'G-RK9ZLZQ6GL', { 'anonymize_ip': true});
|
||||
<ul id="quarto-sidebar-section-3" class="collapse list-unstyled sidebar-section depth1 show">
|
||||
<li class="sidebar-item">
|
||||
<div class="sidebar-item-container">
|
||||
<a href="./C1_Lights.html" class="sidebar-item-text sidebar-link">
|
||||
<span class="menu-text"><span class="chapter-number">8</span> <span class="chapter-title">War at Night</span></span></a>
|
||||
<a href="./C1_Lights.html" class="sidebar-item-text sidebar-link"><span class="chapter-title">War at Night</span></a>
|
||||
</div>
|
||||
</li>
|
||||
<li class="sidebar-item">
|
||||
<div class="sidebar-item-container">
|
||||
<a href="./C2_Refineries.html" class="sidebar-item-text sidebar-link">
|
||||
<span class="menu-text"><span class="chapter-number">9</span> <span class="chapter-title">Refinery Identification</span></span></a>
|
||||
<a href="./C2_Refineries.html" class="sidebar-item-text sidebar-link"><span class="chapter-title">Refinery Identification</span></a>
|
||||
</div>
|
||||
</li>
|
||||
<li class="sidebar-item">
|
||||
<div class="sidebar-item-container">
|
||||
<a href="./C3_Blast.html" class="sidebar-item-text sidebar-link">
|
||||
<span class="menu-text"><span class="chapter-number">10</span> <span class="chapter-title">Blast Damage Assessment</span></span></a>
|
||||
<a href="./C3_Blast.html" class="sidebar-item-text sidebar-link"><span class="chapter-title">Blast Damage Assessment</span></a>
|
||||
</div>
|
||||
</li>
|
||||
<li class="sidebar-item">
|
||||
<div class="sidebar-item-container">
|
||||
<a href="./C4_Ships.html" class="sidebar-item-text sidebar-link">
|
||||
<span class="menu-text"><span class="chapter-number">11</span> <span class="chapter-title">Ship Detection</span></span></a>
|
||||
<a href="./C4_Ships.html" class="sidebar-item-text sidebar-link"><span class="chapter-title">Ship Detection</span></a>
|
||||
</div>
|
||||
</li>
|
||||
<li class="sidebar-item">
|
||||
<div class="sidebar-item-container">
|
||||
<a href="./C5_Object_Detection.html" class="sidebar-item-text sidebar-link active">
|
||||
<span class="menu-text"><span class="chapter-number">12</span> <span class="chapter-title">Object Detection</span></span></a>
|
||||
<a href="./C5_Object_Detection.html" class="sidebar-item-text sidebar-link active"><span class="chapter-title">Object Detection</span></a>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
@@ -306,18 +294,18 @@ gtag('config', 'G-RK9ZLZQ6GL', { 'anonymize_ip': true});
|
||||
<h2 id="toc-title">Table of contents</h2>
|
||||
|
||||
<ul>
|
||||
<li><a href="#object-detection-in-satellite-imagery" id="toc-object-detection-in-satellite-imagery" class="nav-link active" data-scroll-target="#object-detection-in-satellite-imagery"><span class="header-section-number">12.1</span> Object Detection in Satellite Imagery</a>
|
||||
<li><a href="#object-detection-in-satellite-imagery" id="toc-object-detection-in-satellite-imagery" class="nav-link active" data-scroll-target="#object-detection-in-satellite-imagery">Object Detection in Satellite Imagery</a>
|
||||
<ul class="collapse">
|
||||
<li><a href="#yolov5" id="toc-yolov5" class="nav-link" data-scroll-target="#yolov5"><span class="header-section-number">12.1.1</span> YOLOv5</a></li>
|
||||
<li><a href="#yolov5" id="toc-yolov5" class="nav-link" data-scroll-target="#yolov5">YOLOv5</a></li>
|
||||
</ul></li>
|
||||
<li><a href="#training" id="toc-training" class="nav-link" data-scroll-target="#training"><span class="header-section-number">12.2</span> Training</a>
|
||||
<li><a href="#training" id="toc-training" class="nav-link" data-scroll-target="#training">Training</a>
|
||||
<ul class="collapse">
|
||||
<li><a href="#accuracy-assessment" id="toc-accuracy-assessment" class="nav-link" data-scroll-target="#accuracy-assessment"><span class="header-section-number">12.2.1</span> Accuracy Assessment</a></li>
|
||||
<li><a href="#accuracy-assessment" id="toc-accuracy-assessment" class="nav-link" data-scroll-target="#accuracy-assessment">Accuracy Assessment</a></li>
|
||||
</ul></li>
|
||||
<li><a href="#inference" id="toc-inference" class="nav-link" data-scroll-target="#inference"><span class="header-section-number">12.3</span> Inference</a>
|
||||
<li><a href="#inference" id="toc-inference" class="nav-link" data-scroll-target="#inference">Inference</a>
|
||||
<ul class="collapse">
|
||||
<li><a href="#loading-a-trained-model" id="toc-loading-a-trained-model" class="nav-link" data-scroll-target="#loading-a-trained-model"><span class="header-section-number">12.3.1</span> 1. Loading a trained model</a></li>
|
||||
<li><a href="#loading-the-input-imagery" id="toc-loading-the-input-imagery" class="nav-link" data-scroll-target="#loading-the-input-imagery"><span class="header-section-number">12.3.2</span> 2. Loading the input imagery</a></li>
|
||||
<li><a href="#loading-a-trained-model" id="toc-loading-a-trained-model" class="nav-link" data-scroll-target="#loading-a-trained-model">1. Loading a trained model</a></li>
|
||||
<li><a href="#loading-the-input-imagery" id="toc-loading-the-input-imagery" class="nav-link" data-scroll-target="#loading-the-input-imagery">2. Loading the input imagery</a></li>
|
||||
</ul></li>
|
||||
</ul>
|
||||
<div class="toc-actions"><div><i class="bi bi-github"></i></div><div class="action-links"><p><a href="https://github.com/oballinger/RS4OSINT/edit/main/C5_Object_Detection.qmd" class="toc-action">Edit this page</a></p></div></div></nav>
|
||||
@@ -327,7 +315,7 @@ gtag('config', 'G-RK9ZLZQ6GL', { 'anonymize_ip': true});
|
||||
|
||||
<header id="title-block-header" class="quarto-title-block default">
|
||||
<div class="quarto-title">
|
||||
<h1 class="title"><span class="chapter-number">12</span> <span class="chapter-title">Object Detection</span></h1>
|
||||
<h1 class="title"><span class="chapter-title">Object Detection</span></h1>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -355,13 +343,13 @@ gtag('config', 'G-RK9ZLZQ6GL', { 'anonymize_ip': true});
|
||||
<div class="column-screen">
|
||||
<p><img src="images/obj_det2.jpg" class="img-fluid"></p>
|
||||
</div>
|
||||
<section id="object-detection-in-satellite-imagery" class="level2" data-number="12.1">
|
||||
<h2 data-number="12.1" class="anchored" data-anchor-id="object-detection-in-satellite-imagery"><span class="header-section-number">12.1</span> Object Detection in Satellite Imagery</h2>
|
||||
<section id="object-detection-in-satellite-imagery" class="level2">
|
||||
<h2 class="anchored" data-anchor-id="object-detection-in-satellite-imagery">Object Detection in Satellite Imagery</h2>
|
||||
<p>Object detection in satellite imagery has a variety of useful applications.</p>
|
||||
<p>There’s the needle-in-a-haystack problem of needing to monitor a large area for a small number of objects. Immediately prior to the invasion of Ukraine, for example, a number of articles emerged showing Russian military vehicles and equipment popping up in small clearings in the forest near the border with Ukraine. Many of these deployments were spotted by painstakingly combing through high resolution satellite imagery, looking for things that look like trucks. One problem with this approach is that you need to know roughly where to look. The second, and more serious problem, is that you need to be on the lookout in the first place. Object detection, applied to satellite imagery, can automatically comb through vast areas and identify objects of interest. If planes and trucks start showing up in unexpected places, you’ll know about it.</p>
|
||||
<p>Perhaps you’re not monitoring that large of an area, but you want frequent updates about what’s going on. What sorts of objects (planes, trucks, cars, etc.) are present? How many of each? Where are they located? Instead of having to manually look through new imagery as it becomes available, you could have a model automatically analyze new collections and output a summary.</p>
|
||||
<section id="yolov5" class="level3" data-number="12.1.1">
|
||||
<h3 data-number="12.1.1" class="anchored" data-anchor-id="yolov5"><span class="header-section-number">12.1.1</span> YOLOv5</h3>
|
||||
<section id="yolov5" class="level3">
|
||||
<h3 class="anchored" data-anchor-id="yolov5">YOLOv5</h3>
|
||||
<p>Object detection is a fairly complicated task, and there are a number of different approaches to it. In this tutorial, we’ll be using a model called <strong>YOLOv5</strong>. YOLO stands for <strong>You Only Look Once</strong>, and it’s a model that was developed by <a href="https://pjreddie.com/">Joseph Redmon</a> et. al., and the full paper detailing the model can be found <a href="https://arxiv.org/abs/1506.02640">here</a>.</p>
|
||||
<p>The YOLOv5 model is a <strong>convolutional neural network</strong> (CNN), which is a type of deep learning model. CNNs are very good at identifying patterns in images, particularly in small regions of images. This is important for object detection, because we want to be able to identify objects even if they’re partially obscured by other objects.</p>
|
||||
<p>YOLO works by chopping an image up into a grid, and then predicting the location and size of objects in each grid cell:</p>
|
||||
@@ -370,8 +358,8 @@ gtag('config', 'G-RK9ZLZQ6GL', { 'anonymize_ip': true});
|
||||
<p>Luckily, we can simply re-train the YOLOv5 model on datasets of labeled satellite imagery. The rest of this tutorial will walk through the process of training YOLOv5 on a custom dataset, and then using it to dynamically identify objects in satellite imagery pulled from Google Earth Engine.</p>
|
||||
</section>
|
||||
</section>
|
||||
<section id="training" class="level2 page-columns page-full" data-number="12.2">
|
||||
<h2 data-number="12.2" class="anchored" data-anchor-id="training"><span class="header-section-number">12.2</span> Training</h2>
|
||||
<section id="training" class="level2 page-columns page-full">
|
||||
<h2 class="anchored" data-anchor-id="training">Training</h2>
|
||||
<p>The process of re-training the YOLOv5 model on satellite imagery is fairly straightforward and can be accomplished in just three steps; first, we’re going to clone the YOLOv5 repository which contains the model code and the training scripts. Then, we’ll download a dataset of satellite imagery and labels from Roboflow, and finally, we’ll train the model on that dataset.</p>
|
||||
<p>Let’s start by cloning the YOLOv5 repository. Note: we’ll be using a fork of the original repository that I’ve modified to include some pre-trained models that we’ll be using later on.</p>
|
||||
<div class="sourceCode" id="cb1"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="op">!</span>git clone https:<span class="op">//</span>github.com<span class="op">/</span>oballinger<span class="op">/</span>yolov5_RS <span class="co"># clone repo</span></span>
|
||||
@@ -397,8 +385,8 @@ gtag('config', 'G-RK9ZLZQ6GL', { 'anonymize_ip': true});
|
||||
<p>Finally, we can train our YOLOv5 model on the dataset we just downloaded in just one line of code:</p>
|
||||
<div class="sourceCode" id="cb3"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="op">!</span>python train.py <span class="op">--</span>data {dataset.location}<span class="op">/</span>data.yaml <span class="op">--</span>batch <span class="dv">32</span> <span class="op">--</span>cache</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||||
<p>This should take about an hour.</p>
|
||||
<section id="accuracy-assessment" class="level3 page-columns page-full" data-number="12.2.1">
|
||||
<h3 data-number="12.2.1" class="anchored" data-anchor-id="accuracy-assessment"><span class="header-section-number">12.2.1</span> Accuracy Assessment</h3>
|
||||
<section id="accuracy-assessment" class="level3 page-columns page-full">
|
||||
<h3 class="anchored" data-anchor-id="accuracy-assessment">Accuracy Assessment</h3>
|
||||
<p>Using Tensorboard, we can log the performance of our model over the course of the training process:</p>
|
||||
<div class="column-page">
|
||||
<iframe src="https://tensorboard.dev/experiment/Yiyl7AsoQcyJ3uw699CR8A/#scalars" width="100%" height="700px">
|
||||
@@ -433,16 +421,16 @@ gtag('config', 'G-RK9ZLZQ6GL', { 'anonymize_ip': true});
|
||||
<p>This number is very useful when training a model in several different ways using the same dataset, in order to select the best performing one. It’s not that useful for comparing models trained on different datasets, since the mAP 0.5 is dependent on the number of classes in the dataset and the nature of those classes. For example, in the next section we’ll be using a different model trained on the DOTA dataset which has a mAP 0.5 of around 0.68, largely due to the fact that it has around twice as many classes and many of them are similar to each other.</p>
|
||||
</section>
|
||||
</section>
|
||||
<section id="inference" class="level2 page-columns page-full" data-number="12.3">
|
||||
<h2 data-number="12.3" class="anchored" data-anchor-id="inference"><span class="header-section-number">12.3</span> Inference</h2>
|
||||
<section id="inference" class="level2 page-columns page-full">
|
||||
<h2 class="anchored" data-anchor-id="inference">Inference</h2>
|
||||
<p>Now that we’ve got a trained model, we can use it to conduct object detection on new images. we’ll build a data processing pipeline in three steps by:</p>
|
||||
<ol type="1">
|
||||
<li>Loading our trained model</li>
|
||||
<li>Creating an interactive map to define the area we want to analyze.</li>
|
||||
<li>Defining a function to run object detection within this area.</li>
|
||||
</ol>
|
||||
<section id="loading-a-trained-model" class="level3" data-number="12.3.1">
|
||||
<h3 data-number="12.3.1" class="anchored" data-anchor-id="loading-a-trained-model"><span class="header-section-number">12.3.1</span> 1. Loading a trained model</h3>
|
||||
<section id="loading-a-trained-model" class="level3">
|
||||
<h3 class="anchored" data-anchor-id="loading-a-trained-model">1. Loading a trained model</h3>
|
||||
<p>During the training process, YOLO is iteratively tweaking the model to try to maximize mAP 0.5. It automatically saves the best version of the model in the following location: <code>YOLOv5_RS/runs/train/exp/weights/best.pt</code>. You can save this file for later use, which I have done in case you just want to use this model without having to train it yourself. I’ve also included several other pre-trained models which you can find in the <code>YOLOv5_RS/weights/</code> directory, including:</p>
|
||||
<ul>
|
||||
<li><p><code>lowres_ships.pt</code>: the model we just trained on Sentinel-2 imagery.</p></li>
|
||||
@@ -451,8 +439,8 @@ gtag('config', 'G-RK9ZLZQ6GL', { 'anonymize_ip': true});
|
||||
</ul>
|
||||
<p>So far, we’ve trained a model to detect ships in Sentinel-2 imagery. But to show the versatility of this general approach, the rest of this tutorial will load up the <code>general.pt</code> model, and use it to detect a wide range of aircraft in high resolution imagery.</p>
|
||||
</section>
|
||||
<section id="loading-the-input-imagery" class="level3 page-columns page-full" data-number="12.3.2">
|
||||
<h3 data-number="12.3.2" class="anchored" data-anchor-id="loading-the-input-imagery"><span class="header-section-number">12.3.2</span> 2. Loading the input imagery</h3>
|
||||
<section id="loading-the-input-imagery" class="level3 page-columns page-full">
|
||||
<h3 class="anchored" data-anchor-id="loading-the-input-imagery">2. Loading the input imagery</h3>
|
||||
<p>To get started with object detection on satellite imagery using these pre-trained models, we need to define an Area of Interest (AOI) and load satellite imagery. We’ll do this by accessing Google Earth Engine from the Python notebook we’re working in, and creating an interactive map that will let us draw an AOI for analysis.</p>
|
||||
<p>First, we first need to import a few packages:</p>
|
||||
<div class="sourceCode" id="cb4"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a><span class="op">!</span>pip install geemap <span class="op">-</span>q</span>
|
||||
@@ -572,7 +560,7 @@ Once you've done this, you can run the following line of code to automatically i
|
||||
|
||||
|
||||
|
||||

|
||||

|
||||
|
||||
|
||||
-->
|
||||
@@ -933,7 +921,7 @@ window.document.addEventListener("DOMContentLoaded", function (event) {
|
||||
<nav class="page-navigation">
|
||||
<div class="nav-page nav-page-previous">
|
||||
<a href="./C4_Ships.html" class="pagination-link">
|
||||
<i class="bi bi-arrow-left-short"></i> <span class="nav-page-text"><span class="chapter-number">11</span> <span class="chapter-title">Ship Detection</span></span>
|
||||
<i class="bi bi-arrow-left-short"></i> <span class="nav-page-text"><span class="chapter-title">Ship Detection</span></span>
|
||||
</a>
|
||||
</div>
|
||||
<div class="nav-page nav-page-next">
|
||||
|
||||
Reference in New Issue
Block a user