bills commited on
Commit
580a94d
1 Parent(s): e48560c

Add some changes on app.py

Browse files
Files changed (1) hide show
  1. apps.py +80 -0
apps.py ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import time
2
+ from turtle import width
3
+ import torch
4
+ import folium
5
+ import numpy as np
6
+ import pandas as pd
7
+ import streamlit as st
8
+ from folium.plugins import MarkerCluster
9
+ from streamlit_folium import folium_static
10
+
11
+ st.set_page_config(
12
+ page_title="Ship Detection using YOLOv5 Medium Model",
13
+ page_icon=":ship:",
14
+ layout="wide"
15
+ )
16
+
17
+ st.write("# Welcome to Ship Detection Application! :satellite:")
18
+ st.markdown(
19
+ """
20
+ This application is build based on YOLOv5 with extral large model. User just
21
+ upload an image, and press the 'Predict' button to make a prediction base on
22
+ a training model before.
23
+
24
+ ### For more information, please visit:
25
+
26
+ - Check out [my github](https://github.com/bills1912)
27
+ - Jump into YOLOv5 [documentation](https://docs.ultralytics.com/)
28
+
29
+ """
30
+ )
31
+
32
+ st.write("## Ship Imagery Prediction")
33
+ map_col1, map_col2, map_col3 = st.columns(3)
34
+
35
+ ais = pd.read_csv("https://raw.githubusercontent.com/bills1912/marin-vessels-detection/main/data/MarineTraffic_VesselExport_2022-11-25.csv")
36
+ ais_jakarta = ais[ais['Destination Port'] == 'JAKARTA']
37
+ ais_list = ais_jakarta.values.tolist()
38
+ f = folium.Figure(width=1000, height=500)
39
+ jakarta_vessels = folium.Map(location=[-5.626954250925966, 106.70735731868719], zoom_start=8).add_to(f)
40
+ ais_data = folium.FeatureGroup(name="marine_vessels")
41
+ mCluster = MarkerCluster(name="Marine Vessels")
42
+ for i in ais_list:
43
+ html = f"<h3>{i[1]}</h3> Vessel Type: {i[8]} </br> Destination Port: {i[2]} </br> Reported Destination: {i[4]} </br> Current Port: {i[6]}\
44
+ </br> Latitude: {i[9]} </br> Longitude: {i[10]}"
45
+ iframe = folium.IFrame(html)
46
+ popup = folium.Popup(iframe, min_width=250, max_width=300)
47
+ ais_data.add_child(mCluster.add_child(folium.Marker(location=[i[10], i[11]], popup=popup, icon=folium.Icon(color="black", icon="ship", prefix="fa"))))
48
+ jakarta_vessels.add_child(ais_data)
49
+ folium_static(jakarta_vessels, width=1370, height=700)
50
+
51
+
52
+ st.write("### Model evaluation:")
53
+ eval_col1, eval_col2, eval_col3, eval_col4 = st.columns(spec=4)
54
+ eval_col1.metric("Precision", "89.52%")
55
+ eval_col2.metric("Recall", "83.54%")
56
+ eval_col3.metric("mAP 0.5", "85.39%")
57
+ eval_col4.metric("mAP 0.5:0.95", "62.63%")
58
+
59
+ uploaded_file = st.file_uploader("Choose a ship imagery")
60
+ if uploaded_file is not None:
61
+ st.image(uploaded_file, caption='Image to predict')
62
+ # st.write(uploaded_file.)
63
+
64
+ prediction = st.button("Predict")
65
+ if prediction:
66
+ folder_path = st.text_input('Input the folder path of image')
67
+ ship_model = torch.hub.load('ultralytics/yolov5', 'custom', path="supercomputer/best.pt", force_reload=True)
68
+ # results = ship_model(f"C:/Users/bilva/YOLOv5/ship_test/{uploaded_file.name}")
69
+ results = ship_model(f"{folder_path}/{uploaded_file.name}")
70
+ with st.spinner("Loading..."):
71
+ time.sleep(3.5)
72
+ st.success("Done!")
73
+ st.image(np.squeeze(results.render()))
74
+ results.print()
75
+ # with st.echo():
76
+ # st.text(f"results.print()")
77
+ # st.markdown(results.print())
78
+ # for percent_progress in range (100):
79
+ # time.sleep(0.1)
80
+ # progress.progress(percent_progress + 1)