Anuj-Panthri commited on
Commit
3d9d965
·
1 Parent(s): 8fd362a

added description for sliders

Browse files
__pycache__/config.cpython-39.pyc ADDED
Binary file (1.03 kB). View file
 
__pycache__/decode_yolo_v2.cpython-39.pyc ADDED
Binary file (3.48 kB). View file
 
__pycache__/load_model.cpython-39.pyc ADDED
Binary file (4.01 kB). View file
 
app.py CHANGED
@@ -71,8 +71,8 @@ with gr.Blocks(title="Yolo V2 Object detection") as app:
71
  with gr.Row():
72
  radio_btn=gr.Radio(['upload','webcam'],value='upload',interactive=True)
73
 
74
- conf_slider=gr.Slider(0,1,value=0.2,label='min_confidence',interactive=True)
75
- nms_slider=gr.Slider(0,1,value=0.3,label='nms_iou_threshold',interactive=True)
76
 
77
  with gr.Row():
78
  reset_btn=gr.Button('reset',visible=False)
 
71
  with gr.Row():
72
  radio_btn=gr.Radio(['upload','webcam'],value='upload',interactive=True)
73
 
74
+ conf_slider=gr.Slider(0,1,value=0.2,label='min_confidence(removes predictions with confidence lower than the min_confidence)',interactive=True)
75
+ nms_slider=gr.Slider(0,1,value=0.3,label='nms_iou_threshold(lower the value removes more overlapping boxes)',interactive=True)
76
 
77
  with gr.Row():
78
  reset_btn=gr.Button('reset',visible=False)
inference.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import cv2
2
+ import numpy as np
3
+ import matplotlib.pyplot as plt
4
+ from matplotlib.patches import Rectangle
5
+ from load_model import load_model
6
+ from decode_yolo_v2 import *
7
+ from config import *
8
+ import gradio as gr
9
+ import json
10
+ from glob import glob
11
+
12
+
13
+ # objs_found=[{'p': float(0.9001910090446472), 'xywh': [132, 122, 72, 156], 'class_idx': 14, 'class': 'person'}, {'p': float(0.9001910090446472), 'xywh': [260, 126, 157, 284], 'class_idx': 14, 'class': 'person'}]
14
+ # print(objs_found)
15
+ # print(json.dumps(objs_found))
16
+
17
+ model=load_model("yolo_v2(iou_70.5945).h5")
18
+
19
+
20
+
21
+ def get_preds(test_img,p=0.2,iou_threshold=0.3):
22
+ img=cv2.resize(cv2.cvtColor(cv2.imread(test_img),cv2.COLOR_BGR2RGB),[image_size,image_size])
23
+ img=np.expand_dims(img,axis=0)
24
+ y_pred=model.predict(img)
25
+
26
+
27
+ objs_found=get_objects(y_pred[0],p=p)
28
+ objs_found=nms(objs_found,iou_threshold=iou_threshold)
29
+ print("objs_found:",objs_found)
30
+ plt.axis('off')
31
+ # show_objects(img[0],objs_found)
32
+ img=pred_image(img[0],objs_found)
33
+ plt.imshow(img)
34
+ plt.show()
35
+
36
+ # get_preds(input("Enter image path:"))
37
+ # get_preds("C:/Users/Home/Downloads/image_2.jpeg")
38
+
39
+ def get_output(img,p,iou_threshold):
40
+ img=cv2.resize(img,[image_size,image_size])
41
+ img=np.expand_dims(img,axis=0)
42
+ y_pred=model.predict(img,verbose=0)
43
+
44
+
45
+ objs_found=get_objects(y_pred[0],p=p)
46
+ objs_found=nms(objs_found,iou_threshold=iou_threshold)
47
+ # print("objs_found:",objs_found)
48
+ img=pred_image(img[0],objs_found)
49
+ return img,json.dumps({'objects_found':objs_found})
50
+
51
+ app=gr.Interface(get_output,inputs=[
52
+ gr.Image(),
53
+ # gr.Image(streaming=True,source='webcam'),
54
+ gr.Slider(0,1,value=0.2,label='min_confidence'),
55
+ gr.Slider(0,1,value=0.3,label='nms_iou_threshold')],
56
+
57
+ outputs=[gr.Image(label='Objects Found'),gr.JSON(label='Objects_found')],
58
+ title="Yolo V2 Object detection",
59
+ description=f"we can detection 20 type of objects which are: {', '.join(class_names)}",
60
+ examples=[[item] for item in glob('examples/*')],
61
+ # live=True
62
+ )
63
+ app.launch()
64
+ # app.launch(share=True)