Browse Source

YOLOv5 PyTorch Hub models >> check_requirements() (#2592)

Improved user-feedback following requirements auto-update.
5.0
Glenn Jocher GitHub 3 years ago
parent
commit
333ccc5b0f
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 3 deletions
  1. +14
    -3
      utils/general.py

+ 14
- 3
utils/general.py View File

return Path('/workspace').exists() # or Path('/.dockerenv').exists() return Path('/workspace').exists() # or Path('/.dockerenv').exists()




def emojis(str=''):
# Return platform-dependent emoji-safe version of string
return str.encode().decode('ascii', 'ignore') if platform.system() == 'Windows' else str


def check_online(): def check_online():
# Check internet connectivity # Check internet connectivity
import socket import socket
f"Use 'git pull' to update or 'git clone {url}' to download latest." f"Use 'git pull' to update or 'git clone {url}' to download latest."
else: else:
s = f'up to date with {url} ✅' s = f'up to date with {url} ✅'
print(s.encode().decode('ascii', 'ignore') if platform.system() == 'Windows' else s) # emoji-safe
print(emojis(s)) # emoji-safe
except Exception as e: except Exception as e:
print(e) print(e)


print(f"{prefix} {file.resolve()} not found, check failed.") print(f"{prefix} {file.resolve()} not found, check failed.")
return return


n = 0 # number of packages updates
requirements = [f'{x.name}{x.specifier}' for x in pkg.parse_requirements(file.open()) if x.name not in exclude] requirements = [f'{x.name}{x.specifier}' for x in pkg.parse_requirements(file.open()) if x.name not in exclude]
for r in requirements: for r in requirements:
try: try:
pkg.require(r) pkg.require(r)
except Exception as e: # DistributionNotFound or VersionConflict if requirements not met except Exception as e: # DistributionNotFound or VersionConflict if requirements not met
print(f"{prefix} {e.req} not found and is required by YOLOv5, attempting auto-install...")
n += 1
print(f"{prefix} {e.req} not found and is required by YOLOv5, attempting auto-update...")
print(subprocess.check_output(f"pip install '{e.req}'", shell=True).decode()) print(subprocess.check_output(f"pip install '{e.req}'", shell=True).decode())
print(f'Please restart runtime or rerun command for update to take effect.')

if n: # if packages updated
s = f"{prefix} {n} package{'s' * (n > 1)} updated per {file.resolve()}\n" \
f"{prefix} ⚠️ {colorstr('bold', 'Restart runtime or rerun command for updates to take effect')}\n"
print(emojis(s)) # emoji-safe




def check_img_size(img_size, s=32): def check_img_size(img_size, s=32):

Loading…
Cancel
Save