akhaliq HF staff commited on
Commit
b5b81c4
β€’
1 Parent(s): 5a120a8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -24
app.py CHANGED
@@ -21,33 +21,31 @@ from utils.general import check_img_size, check_requirements, check_imshow, non_
21
  from utils.plots import plot_one_box
22
  from utils.torch_utils import select_device, load_classifier, time_synchronized, TracedModel
23
  from PIL import Image
24
-
25
- parser = argparse.ArgumentParser()
26
- parser.add_argument('--weights', nargs='+', type=str, default='yolov7-e6.pt', help='model.pt path(s)')
27
- parser.add_argument('--source', type=str, default='Inference/', help='source') # file/folder, 0 for webcam
28
- parser.add_argument('--img-size', type=int, default=640, help='inference size (pixels)')
29
- parser.add_argument('--conf-thres', type=float, default=0.25, help='object confidence threshold')
30
- parser.add_argument('--iou-thres', type=float, default=0.45, help='IOU threshold for NMS')
31
- parser.add_argument('--device', default='', help='cuda device, i.e. 0 or 0,1,2,3 or cpu')
32
- parser.add_argument('--view-img', action='store_true', help='display results')
33
- parser.add_argument('--save-txt', action='store_true', help='save results to *.txt')
34
- parser.add_argument('--save-conf', action='store_true', help='save confidences in --save-txt labels')
35
- parser.add_argument('--nosave', action='store_true', help='do not save images/videos')
36
- parser.add_argument('--classes', nargs='+', type=int, help='filter by class: --class 0, or --class 0 2 3')
37
- parser.add_argument('--agnostic-nms', action='store_true', help='class-agnostic NMS')
38
- parser.add_argument('--augment', action='store_true', help='augmented inference')
39
- parser.add_argument('--update', action='store_true', help='update all models')
40
- parser.add_argument('--project', default='runs/detect', help='save results to project/name')
41
- parser.add_argument('--name', default='exp', help='save results to project/name')
42
- parser.add_argument('--exist-ok', action='store_true', help='existing project/name ok, do not increment')
43
- parser.add_argument('--trace', action='store_true', help='trace model')
44
- opt = parser.parse_args()
45
-
46
 
47
 
48
 
49
 
50
- def detect(img):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  img.save("Inference/test.jpg")
52
  source, weights, view_img, save_txt, imgsz, trace = opt.source, opt.weights, opt.view_img, opt.save_txt, opt.img_size, opt.trace
53
  save_img = True # save inference images
@@ -189,4 +187,4 @@ with torch.no_grad():
189
  for opt.weights in ['yolov7-e6.pt']:
190
  strip_optimizer(opt.weights)
191
 
192
- gr.Interface(detect,gr.Image(type="pil"), gr.Image(type="pil"),title="Yolov7",examples=[["horses.jpeg"]],description="demo for <a href='https://github.com/WongKinYiu/yolov7' style='text-decoration: underline' target='_blank'>WongKinYiu/yolov7</a> Trainable bag-of-freebies sets new state-of-the-art for real-time object detectors").launch()
 
21
  from utils.plots import plot_one_box
22
  from utils.torch_utils import select_device, load_classifier, time_synchronized, TracedModel
23
  from PIL import Image
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
 
26
 
27
 
28
+ def detect(img,model):
29
+ parser = argparse.ArgumentParser()
30
+ parser.add_argument('--weights', nargs='+', type=str, default=model+".pt", help='model.pt path(s)')
31
+ parser.add_argument('--source', type=str, default='Inference/', help='source') # file/folder, 0 for webcam
32
+ parser.add_argument('--img-size', type=int, default=640, help='inference size (pixels)')
33
+ parser.add_argument('--conf-thres', type=float, default=0.25, help='object confidence threshold')
34
+ parser.add_argument('--iou-thres', type=float, default=0.45, help='IOU threshold for NMS')
35
+ parser.add_argument('--device', default='', help='cuda device, i.e. 0 or 0,1,2,3 or cpu')
36
+ parser.add_argument('--view-img', action='store_true', help='display results')
37
+ parser.add_argument('--save-txt', action='store_true', help='save results to *.txt')
38
+ parser.add_argument('--save-conf', action='store_true', help='save confidences in --save-txt labels')
39
+ parser.add_argument('--nosave', action='store_true', help='do not save images/videos')
40
+ parser.add_argument('--classes', nargs='+', type=int, help='filter by class: --class 0, or --class 0 2 3')
41
+ parser.add_argument('--agnostic-nms', action='store_true', help='class-agnostic NMS')
42
+ parser.add_argument('--augment', action='store_true', help='augmented inference')
43
+ parser.add_argument('--update', action='store_true', help='update all models')
44
+ parser.add_argument('--project', default='runs/detect', help='save results to project/name')
45
+ parser.add_argument('--name', default='exp', help='save results to project/name')
46
+ parser.add_argument('--exist-ok', action='store_true', help='existing project/name ok, do not increment')
47
+ parser.add_argument('--trace', action='store_true', help='trace model')
48
+ opt = parser.parse_args()
49
  img.save("Inference/test.jpg")
50
  source, weights, view_img, save_txt, imgsz, trace = opt.source, opt.weights, opt.view_img, opt.save_txt, opt.img_size, opt.trace
51
  save_img = True # save inference images
 
187
  for opt.weights in ['yolov7-e6.pt']:
188
  strip_optimizer(opt.weights)
189
 
190
+ gr.Interface(detect,[gr.Image(type="pil"),gr.Dropdown(choices=["yolov7","yolov7-e6e","yolov7-e6"])], gr.Image(type="pil"),title="Yolov7",examples=[["horses.jpeg"]],description="demo for <a href='https://github.com/WongKinYiu/yolov7' style='text-decoration: underline' target='_blank'>WongKinYiu/yolov7</a> Trainable bag-of-freebies sets new state-of-the-art for real-time object detectors").launch()