* torch.jit.trace(model, img, strict=False) * Update check_file() * Update hubconf.py * Update README.mdmodifyDataloader
Model |size<br><sup>(pixels) |mAP<sup>val<br>0.5:0.95 |mAP<sup>test<br>0.5:0.95 |mAP<sup>val<br>0.5 |Speed<br><sup>V100 (ms) | |params<br><sup>(M) |FLOPS<br><sup>640 (B) | Model |size<br><sup>(pixels) |mAP<sup>val<br>0.5:0.95 |mAP<sup>test<br>0.5:0.95 |mAP<sup>val<br>0.5 |Speed<br><sup>V100 (ms) | |params<br><sup>(M) |FLOPS<br><sup>640 (B) | ||||
--- |--- |--- |--- |--- |--- |---|--- |--- | --- |--- |--- |--- |--- |--- |---|--- |--- | ||||
[YOLOv5s][assets] |640 |36.7 |36.7 |55.4 |**2.0** | |7.3 |17.0 | [YOLOv5s][assets] |640 |36.7 |36.7 |55.4 |**2.0** | |7.3 |17.0 | ||||
[YOLOv5m][assets] |640 |44.5 |44.5 |63.3 |2.7 | |21.4 |51.3 | |||||
[YOLOv5m][assets] |640 |44.5 |44.5 |63.1 |2.7 | |21.4 |51.3 | |||||
[YOLOv5l][assets] |640 |48.2 |48.2 |66.9 |3.8 | |47.0 |115.4 | [YOLOv5l][assets] |640 |48.2 |48.2 |66.9 |3.8 | |47.0 |115.4 | ||||
[YOLOv5x][assets] |640 |**50.4** |**50.4** |**68.8** |6.1 | |87.7 |218.8 | [YOLOv5x][assets] |640 |**50.4** |**50.4** |**68.8** |6.1 | |87.7 |218.8 | ||||
| | | | | | || | | | | | | | | || | |
"""File for accessing YOLOv5 models via PyTorch Hub https://pytorch.org/hub/ultralytics_yolov5/ | |||||
"""YOLOv5 PyTorch Hub models https://pytorch.org/hub/ultralytics_yolov5/ | |||||
Usage: | Usage: | ||||
import torch | import torch | ||||
Returns: | Returns: | ||||
pytorch model | pytorch model | ||||
""" | """ | ||||
config = Path(__file__).parent / 'models' / f'{name}.yaml' # model.yaml path | |||||
try: | try: | ||||
model = Model(config, channels, classes) | |||||
cfg = list((Path(__file__).parent / 'models').rglob(f'{name}.yaml'))[0] # model.yaml path | |||||
model = Model(cfg, channels, classes) | |||||
if pretrained: | if pretrained: | ||||
fname = f'{name}.pt' # checkpoint filename | fname = f'{name}.pt' # checkpoint filename | ||||
attempt_download(fname) # download if not found locally | attempt_download(fname) # download if not found locally |
try: | try: | ||||
print('\nStarting TorchScript export with torch %s...' % torch.__version__) | print('\nStarting TorchScript export with torch %s...' % torch.__version__) | ||||
f = opt.weights.replace('.pt', '.torchscript.pt') # filename | f = opt.weights.replace('.pt', '.torchscript.pt') # filename | ||||
ts = torch.jit.trace(model, img) | |||||
ts = torch.jit.trace(model, img, strict=False) | |||||
ts.save(f) | ts.save(f) | ||||
print('TorchScript export success, saved as %s' % f) | print('TorchScript export success, saved as %s' % f) | ||||
except Exception as e: | except Exception as e: |
def check_file(file): | def check_file(file): | ||||
# Search for file if not found | # Search for file if not found | ||||
if os.path.isfile(file) or file == '': | |||||
if Path(file).is_file() or file == '': | |||||
return file | return file | ||||
else: | else: | ||||
files = glob.glob('./**/' + file, recursive=True) # find file | files = glob.glob('./**/' + file, recursive=True) # find file | ||||
assert len(files), 'File Not Found: %s' % file # assert file was found | |||||
assert len(files) == 1, "Multiple files match '%s', specify exact path: %s" % (file, files) # assert unique | |||||
assert len(files), f'File Not Found: {file}' # assert file was found | |||||
assert len(files) == 1, f"Multiple files match '{file}', specify exact path: {files}" # assert unique | |||||
return files[0] # return file | return files[0] # return file | ||||