diff --git a/export.py b/export.py index ea7f1ebd0b1f..4ec3c3e0c711 100644 --- a/export.py +++ b/export.py @@ -41,7 +41,7 @@ from models.yolo import Detect from utils.activations import SiLU from utils.datasets import LoadImages -from utils.general import colorstr, check_dataset, check_img_size, check_requirements, file_size, set_logging +from utils.general import colorstr, check_dataset, check_img_size, check_requirements, file_size, set_logging, url2file from utils.torch_utils import select_device @@ -244,7 +244,7 @@ def run(data=ROOT / 'data/coco128.yaml', # 'dataset.yaml path' include = [x.lower() for x in include] tf_exports = list(x in include for x in ('saved_model', 'pb', 'tflite', 'tfjs')) # TensorFlow exports imgsz *= 2 if len(imgsz) == 1 else 1 # expand - file = Path(weights) + file = Path(url2file(weights) if str(weights).startswith(('http:/', 'https:/')) else weights) # Load PyTorch model device = select_device(device) diff --git a/utils/general.py b/utils/general.py index 7a80b2ea81bc..dc9a10fe8617 100755 --- a/utils/general.py +++ b/utils/general.py @@ -360,6 +360,13 @@ def check_dataset(data, autodownload=True): return data # dictionary +def url2file(url): + # Convert URL to filename, i.e. https://url.com/file.txt?auth -> file.txt + url = str(Path(url)).replace(':/', '://') # Pathlib turns :// -> :/ + file = Path(urllib.parse.unquote(url)).name.split('?')[0] # '%2F' to '/', split https://url.com/file.txt?auth + return file + + def download(url, dir='.', unzip=True, delete=True, curl=False, threads=1): # Multi-threaded file download and unzip function, used in data.yaml for autodownload def download_one(url, dir):