-
-
Notifications
You must be signed in to change notification settings - Fork 15.9k
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
Use pathlib instead of os.path #6734
Conversation
@khiemdoan we used to have Pathlib for relative ops but had to move away from that in #5129. YOLOv5 should be runnable from anywhere on your system, i.e.: python detect.py
python path/to/detect.py
python ../../detect.py And pathlib was causing issues there unfortunately. |
Hi @glenn-jocher, I see a case, pathlib throw an exception, so I tried to use canonical path and there was no issue. Let me make a new commit. |
@khiemdoan I see you're updating this PR. Let me explain a little more behind our strategy. The idea is for YOLOv5 to be runnable from anywhere, i.e. at the root level, or above or below it. The only purpose of the relative paths is so that the console display is more concise for the filename arguments. For example if YOLOv5 is run from the project root, we'd like Lastly we want to avoid unresolved paths appearing, i.e. |
@glenn-jocher I have changed the code to the old way to get a relative path. Please check my PR. |
Use the modern, object-oriented way to manipulate files and folders.
π οΈ PR Summary
Made with β€οΈ by Ultralytics Actions
π Summary
Codebase cleanup for consistent Path usage and improved file system interactions in YOLOv5.
π Key Changes
.parents[0]
with.parent
for obtaining the root directory to simplify path traversal across various scripts.os.path.isfile
toPath().is_file()
to standardize file handling with pathlib.get_hash
with list comprehension and pathlib.shutil.rmtree
withignore_errors=True
andPath().mkdir(parents=True)
.os.path
usage toPath()
in various locations for determining file size and existence.π― Purpose & Impact