Aditya9790 commited on
Commit
c9149a7
1 Parent(s): 1cf675c

Update detect.py

Browse files
Files changed (1) hide show
  1. detect.py +29 -34
detect.py CHANGED
@@ -16,6 +16,34 @@ from utils.torch_utils import select_device, load_classifier, time_synchronized,
16
 
17
 
18
  def detect(save_img=False):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  source, weights, view_img, save_txt, imgsz, trace = opt.source, opt.weights, opt.view_img, opt.save_txt, opt.img_size, not opt.no_trace
20
  save_img = not opt.nosave and not source.endswith('.txt') # save inference images
21
  webcam = source.isnumeric() or source.endswith('.txt') or source.lower().startswith(
@@ -160,37 +188,4 @@ def detect(save_img=False):
160
  s = f"\n{len(list(save_dir.glob('labels/*.txt')))} labels saved to {save_dir / 'labels'}" if save_txt else ''
161
  #print(f"Results saved to {save_dir}{s}")
162
 
163
- print(f'Done. ({time.time() - t0:.3f}s)')
164
-
165
-
166
- if __name__ == '__main__':
167
- parser = argparse.ArgumentParser()
168
- parser.add_argument('--weights', nargs='+', type=str, default='yolov7.pt', help='model.pt path(s)')
169
- parser.add_argument('--source', type=str, default='inference/images', help='source') # file/folder, 0 for webcam
170
- parser.add_argument('--img-size', type=int, default=640, help='inference size (pixels)')
171
- parser.add_argument('--conf-thres', type=float, default=0.25, help='object confidence threshold')
172
- parser.add_argument('--iou-thres', type=float, default=0.45, help='IOU threshold for NMS')
173
- parser.add_argument('--device', default='', help='cuda device, i.e. 0 or 0,1,2,3 or cpu')
174
- parser.add_argument('--view-img', action='store_true', help='display results')
175
- parser.add_argument('--save-txt', action='store_true', help='save results to *.txt')
176
- parser.add_argument('--save-conf', action='store_true', help='save confidences in --save-txt labels')
177
- parser.add_argument('--nosave', action='store_true', help='do not save images/videos')
178
- parser.add_argument('--classes', nargs='+', type=int, help='filter by class: --class 0, or --class 0 2 3')
179
- parser.add_argument('--agnostic-nms', action='store_true', help='class-agnostic NMS')
180
- parser.add_argument('--augment', action='store_true', help='augmented inference')
181
- parser.add_argument('--update', action='store_true', help='update all models')
182
- parser.add_argument('--project', default='runs/detect', help='save results to project/name')
183
- parser.add_argument('--name', default='exp', help='save results to project/name')
184
- parser.add_argument('--exist-ok', action='store_true', help='existing project/name ok, do not increment')
185
- parser.add_argument('--no-trace', action='store_true', help='don`t trace model')
186
- opt = parser.parse_args()
187
- print(opt)
188
- #check_requirements(exclude=('pycocotools', 'thop'))
189
-
190
- with torch.no_grad():
191
- if opt.update: # update all models (to fix SourceChangeWarning)
192
- for opt.weights in ['yolov7.pt']:
193
- detect()
194
- strip_optimizer(opt.weights)
195
- else:
196
- detect()
 
16
 
17
 
18
  def detect(save_img=False):
19
+ parser = argparse.ArgumentParser()
20
+ parser.add_argument('--weights', nargs='+', type=str, default='yolov7.pt', help='model.pt path(s)')
21
+ parser.add_argument('--source', type=str, default='inference/images', help='source') # file/folder, 0 for webcam
22
+ parser.add_argument('--img-size', type=int, default=640, help='inference size (pixels)')
23
+ parser.add_argument('--conf-thres', type=float, default=0.25, help='object confidence threshold')
24
+ parser.add_argument('--iou-thres', type=float, default=0.45, help='IOU threshold for NMS')
25
+ parser.add_argument('--device', default='', help='cuda device, i.e. 0 or 0,1,2,3 or cpu')
26
+ parser.add_argument('--view-img', action='store_true', help='display results')
27
+ parser.add_argument('--save-txt', action='store_true', help='save results to *.txt')
28
+ parser.add_argument('--save-conf', action='store_true', help='save confidences in --save-txt labels')
29
+ parser.add_argument('--nosave', action='store_true', help='do not save images/videos')
30
+ parser.add_argument('--classes', nargs='+', type=int, help='filter by class: --class 0, or --class 0 2 3')
31
+ parser.add_argument('--agnostic-nms', action='store_true', help='class-agnostic NMS')
32
+ parser.add_argument('--augment', action='store_true', help='augmented inference')
33
+ parser.add_argument('--update', action='store_true', help='update all models')
34
+ parser.add_argument('--project', default='runs/detect', help='save results to project/name')
35
+ parser.add_argument('--name', default='exp', help='save results to project/name')
36
+ parser.add_argument('--exist-ok', action='store_true', help='existing project/name ok, do not increment')
37
+ parser.add_argument('--no-trace', action='store_true', help='don`t trace model')
38
+ opt = parser.parse_args()
39
+ print(opt)
40
+
41
+ np.random.seed(opt.seed)
42
+
43
+ sort_tracker = Sort(max_age=5,
44
+ min_hits=2,
45
+ iou_threshold=0.2)
46
+
47
  source, weights, view_img, save_txt, imgsz, trace = opt.source, opt.weights, opt.view_img, opt.save_txt, opt.img_size, not opt.no_trace
48
  save_img = not opt.nosave and not source.endswith('.txt') # save inference images
49
  webcam = source.isnumeric() or source.endswith('.txt') or source.lower().startswith(
 
188
  s = f"\n{len(list(save_dir.glob('labels/*.txt')))} labels saved to {save_dir / 'labels'}" if save_txt else ''
189
  #print(f"Results saved to {save_dir}{s}")
190
 
191
+ print(f'Done. ({time.time() - t0:.3f}s)')