mayrajeo commited on
Commit
0fb9587
1 Parent(s): 2c89d92
Files changed (3) hide show
  1. README.md +1 -1
  2. app.py +70 -0
  3. requirements.txt +4 -0
README.md CHANGED
@@ -1,6 +1,6 @@
1
  ---
2
  title: Marine Vessel Detection
3
- emoji:
4
  colorFrom: green
5
  colorTo: indigo
6
  sdk: gradio
 
1
  ---
2
  title: Marine Vessel Detection
3
+ emoji: 🛥️
4
  colorFrom: green
5
  colorTo: indigo
6
  sdk: gradio
app.py ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sys, os
2
+
3
+ import gradio as gr
4
+ import plotly.express as px
5
+ import numpy as np
6
+ import random
7
+ from ultralytics import YOLO
8
+ from sahi.models.yolov8 import *
9
+ from sahi.predict import get_sliced_prediction
10
+ from sahi.utils.cv import visualize_object_predictions
11
+ import PIL
12
+
13
+ model_base = "https://huggingface.co/mayrajeo/marine-vessel-detection/resolve/main/"
14
+
15
+ def inference(
16
+ im:gr.inputs.Image=None,
17
+ model_path:gr.inputs.Dropdown=None,
18
+ conf_thr:gr.inputs.Slider=0.25
19
+ ):
20
+ model = Yolov8DetectionModel(model_path=f'{model_base}/{model_path}/best.pt',
21
+ device='cpu',
22
+ confidence_threshold=conf_thr,
23
+ image_size=640)
24
+
25
+ res = get_sliced_prediction(im, model, slice_width=320,
26
+ slice_height=320, overlap_height_ratio=0.2,
27
+ overlap_width_ratio=0.2, verbose=0)
28
+ img = PIL.Image.open(im)
29
+ visual_result = visualize_object_predictions(image=np.array(img),
30
+ object_prediction_list=res.object_prediction_list,
31
+ text_size=0.3,
32
+ rect_th=1)
33
+ fig = px.imshow(visual_result['image'])
34
+ fig.update_layout(showlegend=False, hovermode=False)
35
+ fig.update_xaxes(visible=False)
36
+ fig.update_yaxes(visible=False)
37
+ return fig
38
+
39
+ inputs = [
40
+ gr.Image(type='filepath', label='Input'),
41
+ gr.components.Dropdown([
42
+ 'YOLOv8n',
43
+ 'YOLOv8s',
44
+ 'YOLOv8m',
45
+ 'YOLOv8l',
46
+ 'YOLOv8x'
47
+ ],
48
+ value='YOLOv8n', label='Model'),
49
+ gr.components.Slider(minimum=0.0, maximum=1.0, value=0.25, step=0.05, label='Confidence Threshold'),
50
+ ]
51
+
52
+ outputs = [
53
+ gr.Plot(label='Predictions')
54
+ ]
55
+
56
+ example_images = [[f'examples/{f}'] for f in os.listdir('examples')]
57
+
58
+
59
+
60
+ gr.Interface(
61
+ fn=inference,
62
+ inputs=inputs,
63
+ outputs=outputs,
64
+ allow_flagging='never',
65
+ examples=example_images,
66
+ examples_per_page=32,
67
+ title='Boat detection from Sentinel 2 images',
68
+ description="""Detecting marine vessels from Sentinel 2 imagery.
69
+ Each example image covers 1500x1500 pixels."""
70
+ ).launch(share=True, server_name='0.0.0.0')
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ torch
2
+ ultralytics
3
+ plotly
4
+ sahi