Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/fix export on url #4823

Merged
merged 15 commits into from
Sep 16, 2021
Merged
4 changes: 2 additions & 2 deletions export.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions utils/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down