is_url
Check if string is URL and check if URL exists.
Source code in ultralytics/yolo/utils/downloads.py
unzip_file
Unzips a *.zip file to the specified path, excluding files containing strings in the exclude list.
If the zipfile does not contain a single top-level directory, the function will create a new directory with the same name as the zipfile (without the extension) to extract its contents. If a path is not provided, the function will use the parent directory of the zipfile as the default path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file |
str
|
The path to the zipfile to be extracted. |
required |
path |
str
|
The path to extract the zipfile to. Defaults to None. |
None
|
exclude |
tuple
|
A tuple of filename strings to be excluded. Defaults to ('.DS_Store', '__MACOSX'). |
('.DS_Store', '__MACOSX')
|
Raises:
Type | Description |
---|---|
BadZipFile
|
If the provided file does not exist or is not a valid zipfile. |
Returns:
Type | Description |
---|---|
Path
|
The path to the directory where the zipfile was extracted. |
Source code in ultralytics/yolo/utils/downloads.py
check_disk_space
Check if there is sufficient disk space to download and store a file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url |
str
|
The URL to the file. Defaults to 'https://ultralytics.com/assets/coco128.zip'. |
'https://ultralytics.com/assets/coco128.zip'
|
sf |
float
|
Safety factor, the multiplier for the required free space. Defaults to 2.0. |
1.5
|
hard |
bool
|
Whether to throw an error or not on insufficient disk space. Defaults to True. |
True
|
Returns:
Type | Description |
---|---|
bool
|
True if there is sufficient disk space, False otherwise. |
Source code in ultralytics/yolo/utils/downloads.py
safe_download
Downloads files from a URL, with options for retrying, unzipping, and deleting the downloaded file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url |
str
|
The URL of the file to be downloaded. |
required |
file |
str
|
The filename of the downloaded file. If not provided, the file will be saved with the same name as the URL. |
None
|
dir |
str
|
The directory to save the downloaded file. If not provided, the file will be saved in the current working directory. |
None
|
unzip |
bool
|
Whether to unzip the downloaded file. Default: True. |
True
|
delete |
bool
|
Whether to delete the downloaded file after unzipping. Default: False. |
False
|
curl |
bool
|
Whether to use curl command line tool for downloading. Default: False. |
False
|
retry |
int
|
The number of times to retry the download in case of failure. Default: 3. |
3
|
min_bytes |
float
|
The minimum number of bytes that the downloaded file should have, to be considered a successful download. Default: 1E0. |
1.0
|
progress |
bool
|
Whether to display a progress bar during the download. Default: True. |
True
|
Source code in ultralytics/yolo/utils/downloads.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
|
attempt_download_asset
Attempt file download from GitHub release assets if not found locally. release = 'latest', 'v6.2', etc.
Source code in ultralytics/yolo/utils/downloads.py
download
Downloads and unzips files concurrently if threads > 1, else sequentially.
Source code in ultralytics/yolo/utils/downloads.py
Created 2023-04-16, Updated 2023-05-17
Authors: Glenn Jocher (4)