onlyshrey98 commited on
Commit
89ebd39
·
1 Parent(s): 0e64c6a

Initial commit: Adding corrosion detection app

Browse files
Files changed (3) hide show
  1. app.py +41 -0
  2. best.pt +3 -0
  3. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from ultralytics import YOLO
3
+ import torch
4
+
5
+ # Set device to CPU
6
+ device = "cpu"
7
+
8
+ # Load your trained YOLOv8 model
9
+ model = YOLO('best.pt')
10
+ model.to(device)
11
+
12
+ def detect_corrosion(input_image):
13
+ """
14
+ Performs corrosion detection on the input image and returns the image with bounding boxes.
15
+ """
16
+ # Run inference on the image
17
+ results = model(input_image)
18
+
19
+ # The 'plot' method returns a NumPy array with the bounding boxes and labels drawn
20
+ plotted_image = results[0].plot() # This returns a BGR numpy array
21
+
22
+ # Convert BGR to RGB for web display
23
+ plotted_image_rgb = plotted_image[..., ::-1]
24
+
25
+ return plotted_image_rgb
26
+
27
+ # --- Gradio Interface ---
28
+ # Create the interface without the examples
29
+ iface = gr.Interface(
30
+ fn=detect_corrosion,
31
+ inputs=gr.Image(type="numpy", label="Upload Ship Hull Image"),
32
+ outputs=gr.Image(type="numpy", label="Detection Result"),
33
+ title="🚢 Corrosion Detection in Ship Hulls",
34
+ description="An AI-powered tool to detect corrosion patches on ship hulls. Upload an image, and the YOLOv8 model will highlight any detected corrosion areas.",
35
+ article="Model: YOLOv8 | Developed for maritime maintenance.",
36
+ allow_flagging="never"
37
+ )
38
+
39
+ # Launch the app
40
+ if __name__ == "__main__":
41
+ iface.launch()
best.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1d1fe42a82fa16ae60b080a7f97b466cc0d7c5c1b060fcd8840466f4a5979cdf
3
+ size 87652083
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ gradio
2
+ ultralytics
3
+ torch --index-url https://download.pytorch.org/whl/cpu
4
+ torchvision --index-url https://download.pytorch.org/whl/cpu