19
19
ROOT = FILE .parents [0 ] # YOLOv5 root directory
20
20
if str (ROOT ) not in sys .path :
21
21
sys .path .append (str (ROOT )) # add ROOT to PATH
22
+ ROOT = ROOT .relative_to (Path .cwd ()) # relative
22
23
23
24
from models .experimental import attempt_load
24
25
from utils .datasets import LoadImages , LoadStreams
30
31
31
32
32
33
@torch .no_grad ()
33
- def run (weights = 'yolov5s.pt' , # model.pt path(s)
34
- source = 'data/images' , # file/dir/URL/glob, 0 for webcam
34
+ def run (weights = ROOT / 'yolov5s.pt' , # model.pt path(s)
35
+ source = ROOT / 'data/images' , # file/dir/URL/glob, 0 for webcam
35
36
imgsz = 640 , # inference size (pixels)
36
37
conf_thres = 0.25 , # confidence threshold
37
38
iou_thres = 0.45 , # NMS IOU threshold
@@ -47,14 +48,15 @@ def run(weights='yolov5s.pt', # model.pt path(s)
47
48
augment = False , # augmented inference
48
49
visualize = False , # visualize features
49
50
update = False , # update all models
50
- project = 'runs/detect' , # save results to project/name
51
+ project = ROOT / 'runs/detect' , # save results to project/name
51
52
name = 'exp' , # save results to project/name
52
53
exist_ok = False , # existing project/name ok, do not increment
53
54
line_thickness = 3 , # bounding box thickness (pixels)
54
55
hide_labels = False , # hide labels
55
56
hide_conf = False , # hide confidences
56
57
half = False , # use FP16 half-precision inference
57
58
):
59
+ source = str (source )
58
60
save_img = not nosave and not source .endswith ('.txt' ) # save inference images
59
61
webcam = source .isnumeric () or source .endswith ('.txt' ) or source .lower ().startswith (
60
62
('rtsp://' , 'rtmp://' , 'http://' , 'https://' ))
@@ -254,8 +256,8 @@ def wrap_frozen_graph(gd, inputs, outputs):
254
256
255
257
def parse_opt ():
256
258
parser = argparse .ArgumentParser ()
257
- parser .add_argument ('--weights' , nargs = '+' , type = str , default = 'yolov5s.pt' , help = 'model path(s)' )
258
- parser .add_argument ('--source' , type = str , default = 'data/images' , help = 'file/dir/URL/glob, 0 for webcam' )
259
+ parser .add_argument ('--weights' , nargs = '+' , type = str , default = ROOT / 'yolov5s.pt' , help = 'model path(s)' )
260
+ parser .add_argument ('--source' , type = str , default = ROOT / 'data/images' , help = 'file/dir/URL/glob, 0 for webcam' )
259
261
parser .add_argument ('--imgsz' , '--img' , '--img-size' , nargs = '+' , type = int , default = [640 ], help = 'inference size h,w' )
260
262
parser .add_argument ('--conf-thres' , type = float , default = 0.25 , help = 'confidence threshold' )
261
263
parser .add_argument ('--iou-thres' , type = float , default = 0.45 , help = 'NMS IoU threshold' )
@@ -271,7 +273,7 @@ def parse_opt():
271
273
parser .add_argument ('--augment' , action = 'store_true' , help = 'augmented inference' )
272
274
parser .add_argument ('--visualize' , action = 'store_true' , help = 'visualize features' )
273
275
parser .add_argument ('--update' , action = 'store_true' , help = 'update all models' )
274
- parser .add_argument ('--project' , default = 'runs/detect' , help = 'save results to project/name' )
276
+ parser .add_argument ('--project' , default = ROOT / 'runs/detect' , help = 'save results to project/name' )
275
277
parser .add_argument ('--name' , default = 'exp' , help = 'save results to project/name' )
276
278
parser .add_argument ('--exist-ok' , action = 'store_true' , help = 'existing project/name ok, do not increment' )
277
279
parser .add_argument ('--line-thickness' , default = 3 , type = int , help = 'bounding box thickness (pixels)' )
0 commit comments