datasciencesage commited on
Commit
b4192f2
·
1 Parent(s): f384d65

Modified the Readme

Browse files
Files changed (3) hide show
  1. README.md +20 -2
  2. app.py +0 -14
  3. images/landing_page.JPG +0 -0
README.md CHANGED
@@ -13,5 +13,23 @@ short_description: objectdetectionvideo
13
 
14
 
15
 
16
- # object-detection-with-direction
17
- object-detection-with-direction
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
 
15
 
16
+ # OBJECT DETECTION WITH DIRECTION
17
+
18
+ This is a Object detection **APP** which takes in a video and gets the objects detected inside the video with their respective threshold scores.
19
+
20
+ Along with the threshold scores it also gives us the direction the respective object is moving.
21
+
22
+ Model used is Yolov8x.
23
+
24
+ Get all the files along with the model **[Here](https://huggingface.co/spaces/datasciencesage/object-detection-with-direction/tree/main)**
25
+
26
+
27
+ The Webapp is Deployed using Huggingface Spaces.
28
+
29
+ **[Acces-Here](https://datasciencesage-object-detection-with-direction.hf.space)**
30
+
31
+
32
+
33
+ ### Landing Page
34
+
35
+ ![alt text](images/landing_page.JPG)
app.py CHANGED
@@ -77,25 +77,19 @@ class ObjectTracker:
77
  def main():
78
  st.title("Real-time Object Detection with Direction")
79
 
80
- # File uploader for video
81
  uploaded_file = st.file_uploader("Choose a video file", type=['mp4', 'avi', 'mov'])
82
 
83
- # Add start button
84
  start_detection = st.button("Start Detection")
85
 
86
- # Add stop button
87
  stop_detection = st.button("Stop Detection")
88
 
89
  if uploaded_file is not None and start_detection:
90
- # Create a session state to track if detection is running
91
  if 'running' not in st.session_state:
92
  st.session_state.running = True
93
 
94
- # Save uploaded file temporarily
95
  tfile = tempfile.NamedTemporaryFile(delete=False)
96
  tfile.write(uploaded_file.read())
97
 
98
- # Load model
99
  with st.spinner('Loading model...'):
100
  model = YOLO('yolov8x.pt',verbose=False)
101
  device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
@@ -112,9 +106,7 @@ def main():
112
  "stationary": (128, 128, 128)
113
  }
114
 
115
- # Create placeholder for video frame
116
  frame_placeholder = st.empty()
117
- # Create placeholder for detection info
118
  info_placeholder = st.empty()
119
 
120
  st.success("Detection Started!")
@@ -124,7 +116,6 @@ def main():
124
  if not success:
125
  break
126
 
127
- # Run detection
128
  results = model(frame,
129
  conf=0.25,
130
  iou=0.45,
@@ -138,7 +129,6 @@ def main():
138
 
139
  tracked_objects = tracker.update(detections)
140
 
141
- # Dictionary to store detection counts
142
  detection_counts = {}
143
 
144
  for detection, obj_id, direction in tracked_objects:
@@ -148,12 +138,10 @@ def main():
148
  cv2.rectangle(frame, (int(x1), int(y1)), (int(x2), int(y2)), color, 2)
149
 
150
  label = f"{model.names[int(cls)]} {direction} {conf:.2f}"
151
- # Increased font size and thickness
152
  font_scale = 1.2
153
  thickness = 3
154
  text_size = cv2.getTextSize(label, cv2.FONT_HERSHEY_SIMPLEX, font_scale, thickness)[0]
155
 
156
- # Increased padding for label background
157
  padding_y = 15
158
  cv2.rectangle(frame,
159
  (int(x1), int(y1) - text_size[1] - padding_y),
@@ -167,11 +155,9 @@ def main():
167
  (255, 255, 255),
168
  thickness)
169
 
170
- # Count detections by class
171
  class_name = model.names[int(cls)]
172
  detection_counts[class_name] = detection_counts.get(class_name, 0) + 1
173
 
174
- # Convert BGR to RGB
175
  frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
176
 
177
  # Update frame
 
77
  def main():
78
  st.title("Real-time Object Detection with Direction")
79
 
 
80
  uploaded_file = st.file_uploader("Choose a video file", type=['mp4', 'avi', 'mov'])
81
 
 
82
  start_detection = st.button("Start Detection")
83
 
 
84
  stop_detection = st.button("Stop Detection")
85
 
86
  if uploaded_file is not None and start_detection:
 
87
  if 'running' not in st.session_state:
88
  st.session_state.running = True
89
 
 
90
  tfile = tempfile.NamedTemporaryFile(delete=False)
91
  tfile.write(uploaded_file.read())
92
 
 
93
  with st.spinner('Loading model...'):
94
  model = YOLO('yolov8x.pt',verbose=False)
95
  device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
 
106
  "stationary": (128, 128, 128)
107
  }
108
 
 
109
  frame_placeholder = st.empty()
 
110
  info_placeholder = st.empty()
111
 
112
  st.success("Detection Started!")
 
116
  if not success:
117
  break
118
 
 
119
  results = model(frame,
120
  conf=0.25,
121
  iou=0.45,
 
129
 
130
  tracked_objects = tracker.update(detections)
131
 
 
132
  detection_counts = {}
133
 
134
  for detection, obj_id, direction in tracked_objects:
 
138
  cv2.rectangle(frame, (int(x1), int(y1)), (int(x2), int(y2)), color, 2)
139
 
140
  label = f"{model.names[int(cls)]} {direction} {conf:.2f}"
 
141
  font_scale = 1.2
142
  thickness = 3
143
  text_size = cv2.getTextSize(label, cv2.FONT_HERSHEY_SIMPLEX, font_scale, thickness)[0]
144
 
 
145
  padding_y = 15
146
  cv2.rectangle(frame,
147
  (int(x1), int(y1) - text_size[1] - padding_y),
 
155
  (255, 255, 255),
156
  thickness)
157
 
 
158
  class_name = model.names[int(cls)]
159
  detection_counts[class_name] = detection_counts.get(class_name, 0) + 1
160
 
 
161
  frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
162
 
163
  # Update frame
images/landing_page.JPG ADDED