mohit15 commited on
Commit
e191a7a
·
1 Parent(s): a6fbeab
Files changed (3) hide show
  1. app.py +58 -0
  2. best.pt +3 -0
  3. requirements.txt +6 -0
app.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import matplotlib.pyplot as plt
3
+ import streamlit as st
4
+ from PIL import Image
5
+ import numpy as np
6
+ import torch
7
+ import cv2
8
+
9
+
10
+ @st.cache_resource
11
+ def load_model():
12
+ model = torch.hub.load(
13
+ 'ultralytics/yolov5',
14
+ 'custom',
15
+ path='best.pt'
16
+ )
17
+ return model
18
+ model = load_model()
19
+
20
+
21
+ def make_prediction(img_path):
22
+ img = Image.open(img_path).convert('RGB')
23
+ open_cv_image = np.array(img)
24
+ open_cv_image = open_cv_image[:, :, ::-1].copy()
25
+ results = model([open_cv_image])
26
+ return open_cv_image, results
27
+
28
+
29
+ def show_bounding_boxes(img, results, cls):
30
+ df = results.pandas().xyxy[0]
31
+ df = df[df['name'] == cls]
32
+ list_of_rows = [list(row) for row in df.values]
33
+
34
+ for each_row in list_of_rows:
35
+ cv2.rectangle(img,
36
+ (int(each_row[0]), int(each_row[1])),
37
+ (int(each_row[2]), int(each_row[3])),
38
+ (255, 0, 0), 2
39
+ )
40
+ return img
41
+
42
+
43
+ st.title("Object Detection :tea: :coffee:")
44
+ upload = st.file_uploader(label= "Upload an image : ", type = ["png","jpg","jpeg"])
45
+
46
+ if upload:
47
+ print(upload)
48
+ img, results = make_prediction(upload)
49
+ bounded_img = show_bounding_boxes(img, results, 'Table')
50
+ fig = plt.figure(figsize=(12,12))
51
+ ax = fig.add_subplot(111)
52
+ plt.imshow(bounded_img)
53
+ plt.xticks([],[])
54
+ plt.yticks([],[])
55
+ ax.spines[["top","bottom","right","left"]].set_visible(False)
56
+
57
+ st.pyplot(fig,use_container_width=True)
58
+
best.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c79701412b026fe2f832231ae02777540ff18a932c491b2b87b0b5411a48aba5
3
+ size 93836445
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ numpy==1.24.4
2
+ opencv-python==4.8.1.78
3
+ pandas==2.0.3
4
+ streamlit==1.29.0
5
+ torch==2.1.1
6
+ ultralytics==8.0.221