glenn-jocher commited on
Commit
2541f77
1 Parent(s): b7fe1d0

update detect.py

Browse files
Files changed (1) hide show
  1. detect.py +9 -8
detect.py CHANGED
@@ -123,10 +123,11 @@ def detect(save_img=False):
123
  if isinstance(vid_writer, cv2.VideoWriter):
124
  vid_writer.release() # release previous video writer
125
 
 
126
  fps = vid_cap.get(cv2.CAP_PROP_FPS)
127
  w = int(vid_cap.get(cv2.CAP_PROP_FRAME_WIDTH))
128
  h = int(vid_cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
129
- vid_writer = cv2.VideoWriter(save_path, cv2.VideoWriter_fourcc(*opt.fourcc), fps, (w, h))
130
  vid_writer.write(im0)
131
 
132
  if save_txt or save_img:
@@ -145,20 +146,20 @@ if __name__ == '__main__':
145
  parser.add_argument('--img-size', type=int, default=640, help='inference size (pixels)')
146
  parser.add_argument('--conf-thres', type=float, default=0.4, help='object confidence threshold')
147
  parser.add_argument('--iou-thres', type=float, default=0.5, help='IOU threshold for NMS')
148
- parser.add_argument('--fourcc', type=str, default='mp4v', help='output video codec (verify ffmpeg support)')
149
  parser.add_argument('--device', default='', help='cuda device, i.e. 0 or 0,1,2,3 or cpu')
150
  parser.add_argument('--view-img', action='store_true', help='display results')
151
  parser.add_argument('--save-txt', action='store_true', help='save results to *.txt')
152
  parser.add_argument('--classes', nargs='+', type=int, help='filter by class')
153
  parser.add_argument('--agnostic-nms', action='store_true', help='class-agnostic NMS')
154
  parser.add_argument('--augment', action='store_true', help='augmented inference')
 
155
  opt = parser.parse_args()
156
  print(opt)
157
 
158
  with torch.no_grad():
159
- detect()
160
-
161
- # # Update all models
162
- # for opt.weights in ['yolov5s.pt', 'yolov5m.pt', 'yolov5l.pt', 'yolov5x.pt', 'yolov3-spp.pt']:
163
- # detect()
164
- # create_pretrained(opt.weights, opt.weights)
 
123
  if isinstance(vid_writer, cv2.VideoWriter):
124
  vid_writer.release() # release previous video writer
125
 
126
+ fourcc = 'mp4v' # output video codec
127
  fps = vid_cap.get(cv2.CAP_PROP_FPS)
128
  w = int(vid_cap.get(cv2.CAP_PROP_FRAME_WIDTH))
129
  h = int(vid_cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
130
+ vid_writer = cv2.VideoWriter(save_path, cv2.VideoWriter_fourcc(*fourcc), fps, (w, h))
131
  vid_writer.write(im0)
132
 
133
  if save_txt or save_img:
 
146
  parser.add_argument('--img-size', type=int, default=640, help='inference size (pixels)')
147
  parser.add_argument('--conf-thres', type=float, default=0.4, help='object confidence threshold')
148
  parser.add_argument('--iou-thres', type=float, default=0.5, help='IOU threshold for NMS')
 
149
  parser.add_argument('--device', default='', help='cuda device, i.e. 0 or 0,1,2,3 or cpu')
150
  parser.add_argument('--view-img', action='store_true', help='display results')
151
  parser.add_argument('--save-txt', action='store_true', help='save results to *.txt')
152
  parser.add_argument('--classes', nargs='+', type=int, help='filter by class')
153
  parser.add_argument('--agnostic-nms', action='store_true', help='class-agnostic NMS')
154
  parser.add_argument('--augment', action='store_true', help='augmented inference')
155
+ parser.add_argument('--update', action='store_true', help='update all models')
156
  opt = parser.parse_args()
157
  print(opt)
158
 
159
  with torch.no_grad():
160
+ if opt.update: # update all models (to fix SourceChangeWarning)
161
+ for opt.weights in ['yolov5s.pt', 'yolov5m.pt', 'yolov5l.pt', 'yolov5x.pt', 'yolov3-spp.pt']:
162
+ detect()
163
+ create_pretrained(opt.weights, opt.weights)
164
+ else:
165
+ detect()