1616
1717dependencies  =  ['torch' , 'yaml' ]
1818check_requirements (Path (__file__ ).parent  /  'requirements.txt' , exclude = ('pycocotools' , 'thop' ))
19- set_logging ()
2019
2120
22- def  create (name , pretrained , channels , classes , autoshape ):
21+ def  create (name , pretrained , channels , classes , autoshape ,  verbose ):
2322    """Creates a specified YOLOv5 model 
2423
2524    Arguments: 
@@ -32,6 +31,8 @@ def create(name, pretrained, channels, classes, autoshape):
3231        pytorch model 
3332    """ 
3433    try :
34+         set_logging (verbose = verbose )
35+ 
3536        cfg  =  list ((Path (__file__ ).parent  /  'models' ).rglob (f'{ name }  ))[0 ]  # model.yaml path 
3637        model  =  Model (cfg , channels , classes )
3738        if  pretrained :
@@ -55,7 +56,7 @@ def create(name, pretrained, channels, classes, autoshape):
5556        raise  Exception (s ) from  e 
5657
5758
58- def  custom (path_or_model = 'path/to/model.pt' , autoshape = True ):
59+ def  custom (path_or_model = 'path/to/model.pt' , autoshape = True ,  verbose = True ):
5960    """YOLOv5-custom model https://github.com/ultralytics/yolov5 
6061
6162    Arguments (3 options): 
@@ -66,6 +67,8 @@ def custom(path_or_model='path/to/model.pt', autoshape=True):
6667    Returns: 
6768        pytorch model 
6869    """ 
70+     set_logging (verbose = verbose )
71+ 
6972    model  =  torch .load (path_or_model ) if  isinstance (path_or_model , str ) else  path_or_model   # load checkpoint 
7073    if  isinstance (model , dict ):
7174        model  =  model ['ema'  if  model .get ('ema' ) else  'model' ]  # load model 
@@ -79,49 +82,49 @@ def custom(path_or_model='path/to/model.pt', autoshape=True):
7982    return  hub_model .to (device )
8083
8184
82- def  yolov5s (pretrained = True , channels = 3 , classes = 80 , autoshape = True ):
85+ def  yolov5s (pretrained = True , channels = 3 , classes = 80 , autoshape = True ,  verbose = True ):
8386    # YOLOv5-small model https://github.com/ultralytics/yolov5 
84-     return  create ('yolov5s' , pretrained , channels , classes , autoshape )
87+     return  create ('yolov5s' , pretrained , channels , classes , autoshape ,  verbose )
8588
8689
87- def  yolov5m (pretrained = True , channels = 3 , classes = 80 , autoshape = True ):
90+ def  yolov5m (pretrained = True , channels = 3 , classes = 80 , autoshape = True ,  verbose = True ):
8891    # YOLOv5-medium model https://github.com/ultralytics/yolov5 
89-     return  create ('yolov5m' , pretrained , channels , classes , autoshape )
92+     return  create ('yolov5m' , pretrained , channels , classes , autoshape ,  verbose )
9093
9194
92- def  yolov5l (pretrained = True , channels = 3 , classes = 80 , autoshape = True ):
95+ def  yolov5l (pretrained = True , channels = 3 , classes = 80 , autoshape = True ,  verbose = True ):
9396    # YOLOv5-large model https://github.com/ultralytics/yolov5 
94-     return  create ('yolov5l' , pretrained , channels , classes , autoshape )
97+     return  create ('yolov5l' , pretrained , channels , classes , autoshape ,  verbose )
9598
9699
97- def  yolov5x (pretrained = True , channels = 3 , classes = 80 , autoshape = True ):
100+ def  yolov5x (pretrained = True , channels = 3 , classes = 80 , autoshape = True ,  verbose = True ):
98101    # YOLOv5-xlarge model https://github.com/ultralytics/yolov5 
99-     return  create ('yolov5x' , pretrained , channels , classes , autoshape )
102+     return  create ('yolov5x' , pretrained , channels , classes , autoshape ,  verbose )
100103
101104
102- def  yolov5s6 (pretrained = True , channels = 3 , classes = 80 , autoshape = True ):
103-     # YOLOv5-small model https://github.com/ultralytics/yolov5 
104-     return  create ('yolov5s6' , pretrained , channels , classes , autoshape )
105+ def  yolov5s6 (pretrained = True , channels = 3 , classes = 80 , autoshape = True ,  verbose = True ):
106+     # YOLOv5-small-P6  model https://github.com/ultralytics/yolov5 
107+     return  create ('yolov5s6' , pretrained , channels , classes , autoshape ,  verbose )
105108
106109
107- def  yolov5m6 (pretrained = True , channels = 3 , classes = 80 , autoshape = True ):
108-     # YOLOv5-medium model https://github.com/ultralytics/yolov5 
109-     return  create ('yolov5m6' , pretrained , channels , classes , autoshape )
110+ def  yolov5m6 (pretrained = True , channels = 3 , classes = 80 , autoshape = True ,  verbose = True ):
111+     # YOLOv5-medium-P6  model https://github.com/ultralytics/yolov5 
112+     return  create ('yolov5m6' , pretrained , channels , classes , autoshape ,  verbose )
110113
111114
112- def  yolov5l6 (pretrained = True , channels = 3 , classes = 80 , autoshape = True ):
113-     # YOLOv5-large model https://github.com/ultralytics/yolov5 
114-     return  create ('yolov5l6' , pretrained , channels , classes , autoshape )
115+ def  yolov5l6 (pretrained = True , channels = 3 , classes = 80 , autoshape = True ,  verbose = True ):
116+     # YOLOv5-large-P6  model https://github.com/ultralytics/yolov5 
117+     return  create ('yolov5l6' , pretrained , channels , classes , autoshape ,  verbose )
115118
116119
117- def  yolov5x6 (pretrained = True , channels = 3 , classes = 80 , autoshape = True ):
118-     # YOLOv5-xlarge model https://github.com/ultralytics/yolov5 
119-     return  create ('yolov5x6' , pretrained , channels , classes , autoshape )
120+ def  yolov5x6 (pretrained = True , channels = 3 , classes = 80 , autoshape = True ,  verbose = True ):
121+     # YOLOv5-xlarge-P6  model https://github.com/ultralytics/yolov5 
122+     return  create ('yolov5x6' , pretrained , channels , classes , autoshape ,  verbose )
120123
121124
122125if  __name__  ==  '__main__' :
123-     model  =  create (name = 'yolov5s' , pretrained = True , channels = 3 , classes = 80 , autoshape = True )  # pretrained example  
124-     # model = custom(path_or_model='path/to/model.pt')  # custom example  
126+     model  =  create (name = 'yolov5s' , pretrained = True , channels = 3 , classes = 80 , autoshape = True ,  verbose = True )  # pretrained 
127+     # model = custom(path_or_model='path/to/model.pt')  # custom 
125128
126129    # Verify inference 
127130    import  cv2 
0 commit comments