Initial commit
Browse files- .gitattributes +7 -0
- app.py +131 -0
- demo/Pleiades_HD15_Miami_Marina.jpg +3 -0
- demo/Pleiades_Neo_Tucson_USA.jpg +3 -0
- demo/SPOT_Storage.jpg +3 -0
- demo/Satellite_Image_Marina_New_Zealand.jpg +3 -0
- demo/airport01.jpg +3 -0
- demo/demo.jpg +3 -0
- demo/dota_demo.jpg +3 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,10 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
demo/demo.jpg filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
demo/dota_demo.jpg filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
demo/Pleiades_HD15_Miami_Marina.jpg filter=lfs diff=lfs merge=lfs -text
|
| 39 |
+
demo/Pleiades_Neo_Tucson_USA.jpg filter=lfs diff=lfs merge=lfs -text
|
| 40 |
+
demo/SPOT_Storage.jpg filter=lfs diff=lfs merge=lfs -text
|
| 41 |
+
demo/Satellite_Image_Marina_New_Zealand.jpg filter=lfs diff=lfs merge=lfs -text
|
| 42 |
+
demo/airport01.jpg filter=lfs diff=lfs merge=lfs -text
|
app.py
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import socket
|
| 3 |
+
import time
|
| 4 |
+
import gradio as gr
|
| 5 |
+
import numpy as np
|
| 6 |
+
from PIL import Image, ImageDraw
|
| 7 |
+
import base64
|
| 8 |
+
import requests
|
| 9 |
+
import json
|
| 10 |
+
|
| 11 |
+
# API for inferences
|
| 12 |
+
DL4EO_API_URL = "https://dl4eo--object-predict-raster.modal.run"
|
| 13 |
+
|
| 14 |
+
# Auth Token to access API
|
| 15 |
+
DL4EO_API_KEY = os.environ['DL4EO_API_KEY']
|
| 16 |
+
|
| 17 |
+
# width of the boxes on image
|
| 18 |
+
LINE_WIDTH = 2
|
| 19 |
+
|
| 20 |
+
# Check Gradio version
|
| 21 |
+
print(f"Gradio version: {gr.__version__}")
|
| 22 |
+
|
| 23 |
+
# Define the inference function
|
| 24 |
+
def predict_image(img, threshold):
|
| 25 |
+
|
| 26 |
+
if isinstance(img, Image.Image):
|
| 27 |
+
img = np.array(img)
|
| 28 |
+
|
| 29 |
+
if not isinstance(img, np.ndarray) or len(img.shape) != 3 or img.shape[2] != 3:
|
| 30 |
+
raise BaseException("predit_image(): input 'img' shoud be single RGB image in PIL or Numpy array format.")
|
| 31 |
+
|
| 32 |
+
# Encode the image data as base64
|
| 33 |
+
image_base64 = base64.b64encode(np.ascontiguousarray(img)).decode()
|
| 34 |
+
|
| 35 |
+
# Create a dictionary representing the JSON payload
|
| 36 |
+
payload = {
|
| 37 |
+
'image': image_base64,
|
| 38 |
+
'shape': img.shape,
|
| 39 |
+
'threshold': threshold,
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
headers = {
|
| 43 |
+
'Authorization': 'Bearer ' + DL4EO_API_KEY,
|
| 44 |
+
'Content-Type': 'application/json' # Adjust the content type as needed
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
# Send the POST request to the API endpoint with the image file as binary payload
|
| 48 |
+
response = requests.post(DL4EO_API_URL, json=payload, headers=headers)
|
| 49 |
+
|
| 50 |
+
# Check the response status
|
| 51 |
+
if response.status_code != 200:
|
| 52 |
+
raise Exception(
|
| 53 |
+
f"Received status code={response.status_code} in inference API"
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
+
json_data = json.loads(response.content)
|
| 57 |
+
pil_img = json_data['image']
|
| 58 |
+
shape = json_data['shape']
|
| 59 |
+
infos = json_data['infos']
|
| 60 |
+
duration = json_data['duration']
|
| 61 |
+
|
| 62 |
+
return pil_img, shape, infos, duration
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
# Define example images and their true labels for users to choose from
|
| 66 |
+
example_data = [
|
| 67 |
+
["./demo/demo.jpg", 0.8],
|
| 68 |
+
["./demo/dota_demo.jpg", 0.8],
|
| 69 |
+
["./demo/Satellite_Image_Marina_New_Zealand.jpg", 0.8],
|
| 70 |
+
["./demo/Pleiades_HD15_Miami_Marina.jpg", 0.8],
|
| 71 |
+
["./demo/SPOT_Storage.jpg", 0.8],
|
| 72 |
+
["./demo/airport01.jpg", 0.8],
|
| 73 |
+
["./demo/Pleiades_Neo_Tucson_USA.jpg", 0.8],
|
| 74 |
+
# Add more example images and labels as needed
|
| 75 |
+
]
|
| 76 |
+
|
| 77 |
+
# Define CSS for some elements
|
| 78 |
+
css = """
|
| 79 |
+
.image-preview {
|
| 80 |
+
height: 820px !important;
|
| 81 |
+
width: 800px !important;
|
| 82 |
+
}
|
| 83 |
+
"""
|
| 84 |
+
|
| 85 |
+
TITLE = "Oriented bounding boxes detection on Optical Satellite images"
|
| 86 |
+
|
| 87 |
+
# Define the Gradio Interface
|
| 88 |
+
demo = gr.Blocks(title=TITLE, css=css).queue()
|
| 89 |
+
with demo:
|
| 90 |
+
gr.Markdown(f"<h3><center>{TITLE}<center><h3>")
|
| 91 |
+
|
| 92 |
+
with gr.Row():
|
| 93 |
+
with gr.Column(scale=0):
|
| 94 |
+
input_image = gr.Image(type="pil", interactive=True)
|
| 95 |
+
run_button = gr.Button(value="Run")
|
| 96 |
+
with gr.Accordion("Advanced options", open=True):
|
| 97 |
+
threshold = gr.Slider(label="Confidence threshold", minimum=0.0, maximum=1.0, value=0.25, step=0.01)
|
| 98 |
+
dimensions = gr.Textbox(label="Image size", interactive=False)
|
| 99 |
+
detections = gr.Textbox(label="Predicted objects", interactive=False)
|
| 100 |
+
stopwatch = gr.Number(label="Execution time (sec.)", interactive=False, precision=3)
|
| 101 |
+
|
| 102 |
+
with gr.Column(scale=2):
|
| 103 |
+
output_image = gr.Image(type="pil", elem_classes='image-preview', interactive=False)
|
| 104 |
+
|
| 105 |
+
run_button.click(fn=predict_image, inputs=[input_image, threshold], outputs=[output_image, dimensions, detections, stopwatch])
|
| 106 |
+
gr.Examples(
|
| 107 |
+
examples=example_data,
|
| 108 |
+
inputs = [input_image, threshold],
|
| 109 |
+
outputs = [output_image, dimensions, detections, stopwatch],
|
| 110 |
+
fn=predict_image,
|
| 111 |
+
#cache_examples=True,
|
| 112 |
+
label='Try these images!'
|
| 113 |
+
)
|
| 114 |
+
|
| 115 |
+
gr.Markdown("""
|
| 116 |
+
<p>This demo is provided by <a href='https://www.linkedin.com/in/faudi/'>Jeff Faudi</a> and <a href='https://www.dl4eo.com/'>DL4EO</a>.
|
| 117 |
+
This model is based on the <a href='https://github.com/open-mmlab/mmrotate'>MMRotate framework</a> which provides oriented bounding boxes.
|
| 118 |
+
We believe that oriented bouding boxes are better suited for detection in satellite images. This model has been trained on the
|
| 119 |
+
<a href='https://captain-whu.github.io/DOTA/dataset.html'>DOTA dataset</a> which contains 15 classes: plane, ship, storage tank,
|
| 120 |
+
baseball diamond, tennis court, basketball court, ground track field, harbor, bridge, large vehicle, small vehicle, helicopter,
|
| 121 |
+
roundabout, soccer ball field and swimming pool. </p><p>The associated licenses are
|
| 122 |
+
<a href='https://about.google/brand-resource-center/products-and-services/geo-guidelines/#google-earth-web-and-apps'>GoogleEarth fair use</a>
|
| 123 |
+
and <a href='https://creativecommons.org/licenses/by-nc-sa/4.0/deed.en'>CC-BY-SA-NC</a>. This demonstration CANNOT be used for commercial puposes.
|
| 124 |
+
Please contact <a href='mailto:[email protected]'>me</a> for more information on how you could get access to a commercial grade model or API. </p>")
|
| 125 |
+
""")
|
| 126 |
+
|
| 127 |
+
demo.launch(
|
| 128 |
+
inline=False,
|
| 129 |
+
show_api=False,
|
| 130 |
+
debug=False
|
| 131 |
+
)
|
demo/Pleiades_HD15_Miami_Marina.jpg
ADDED
|
Git LFS Details
|
demo/Pleiades_Neo_Tucson_USA.jpg
ADDED
|
Git LFS Details
|
demo/SPOT_Storage.jpg
ADDED
|
Git LFS Details
|
demo/Satellite_Image_Marina_New_Zealand.jpg
ADDED
|
Git LFS Details
|
demo/airport01.jpg
ADDED
|
Git LFS Details
|
demo/demo.jpg
ADDED
|
Git LFS Details
|
demo/dota_demo.jpg
ADDED
|
Git LFS Details
|