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

Add CLI Fire for detection script #4981

Closed
wants to merge 31 commits into from
Closed

Conversation

Borda
Copy link
Contributor

@Borda Borda commented Sep 28, 2021

Resolves #4511

πŸ› οΈ PR Summary

Made with ❀️ by Ultralytics Actions

🌟 Summary

Refactoring detect.py for improved maintainability and adding Google Fire CLI.

πŸ“Š Key Changes

  • Removed argparse and replaced it with fire for parsing command line arguments.
  • Changed the function signature of run to use type hints for better readability and static type checking.
  • Added a function summary for run with descriptions of each argument.
  • Removed parse_opt and main functions as they're replaced by the use of fire.
  • Added Google Fire to the requirements.txt file for dependency installation.

🎯 Purpose & Impact

  • Simplicity: Streamlines command-line interface creation, making it easier to build and use.
  • Type Safety: Type hints help developers understand what types of arguments are expected and tools to perform type checking.
  • Readability & Maintenance: Documentation for run arguments makes it clear what each parameter does, contributing to better code maintainability.
  • User Experience: May enhance user experience with an interactive and more flexible command-line interface.
  • Requirement Changes: Users need to install the new dependency (fire) to use the updated detect.py.

@Borda Borda marked this pull request as ready for review September 28, 2021 23:19
@Borda Borda force-pushed the cli/fire branch 2 times, most recently from acd836e to 15dba20 Compare September 29, 2021 06:59
@Borda
Copy link
Contributor Author

Borda commented Sep 29, 2021

@glenn-jocher mind check? 🐰

@glenn-jocher
Copy link
Member

@Borda this is really interesting. Didn't know about Sequence. Is Fire and Sequence compatible with python >= 3.6?

It looks like one downside is that the arguments must be full-length now. i.e. can we do python detect.py --img 640 or do we need to explicitly do python detect.py --imgsz 640 for Fire to work correctly?

@Borda
Copy link
Contributor Author

Borda commented Oct 1, 2021

Is Fire and Sequence compatible with python >= 3.6?

yes, so far I know, the Sequence comes from typing not from Fire

can we do python detect.py --img 640 or do we need to explicitly do python detect.py --imgsz 640 for Fire to work correctly?

I guess that the img de deprecated argument and kept only for back-compatibility reasons
in general, I would use the new imgsz as the past one was quite confusing what it does...

@Borda
Copy link
Contributor Author

Borda commented Oct 3, 2021

@glenn-jocher so how do you feel about this simification?

@Borda
Copy link
Contributor Author

Borda commented Oct 13, 2021

@glenn-jocher can we proceed this one, it is not trivial to keep it updated :]

@Borda
Copy link
Contributor Author

Borda commented Oct 21, 2021

@glenn-jocher ^^ 🐰

@Borda
Copy link
Contributor Author

Borda commented Oct 26, 2021

@glenn-jocher ^^ πŸ˜•

@glenn-jocher
Copy link
Member

@Borda hey there! Thanks for submitting this and keeping it updated. Do you think this is suitable for merging into master or do you think we might want to run some more tests on this? Any significant change in the repo like this we want to be sure we are handling correctly.

If you're free next week for a quick meeting please use my meeting link to set up a call. Thanks!

@Borda
Copy link
Contributor Author

Borda commented Oct 28, 2021

@glenn-jocher I would say it is safe to merge as the detection quite straight script... for training or other, I would recommend running larger testing... 🐰

@glenn-jocher glenn-jocher changed the title add CLI Fire fro detection script Add CLI Fire for detection script Nov 3, 2021
@Borda
Copy link
Contributor Author

Borda commented Jan 17, 2022

@glenn-jocher Happy New Year πŸŽ‰

@Borda
Copy link
Contributor Author

Borda commented Feb 8, 2022

@glenn-jocher still an ongoing discussion? 🐰

@chris-clem
Copy link

It would be great to have that feature!

@Borda
Copy link
Contributor Author

Borda commented Feb 21, 2022

@glenn-jocher ay update here? πŸ˜• it is pending for almost half a year...

@Borda
Copy link
Contributor Author

Borda commented Mar 11, 2022

@glenn-jocher ^^

@glenn-jocher
Copy link
Member

glenn-jocher commented Mar 14, 2022

@Borda I've been testing this, so far so good, but we've lost the capability to print the arguments as in master on this line:

print_args(FILE.stem, opt)

yolov5/utils/general.py

Lines 164 to 167 in 932dc78

def print_args(name, opt):
# Print argparser arguments
LOGGER.info(colorstr(f'{name}: ') + ', '.join(f'{k}={v}' for k, v in vars(opt).items()))

I've been looking at using locals() and vars() to recreate this, but can't separate out the function/Fire variables with existing variables created by the import statements at the top of the file.

Screenshot 2022-03-14 at 16 13 21

@Borda
Copy link
Contributor Author

Borda commented Mar 14, 2022

I've been looking at using locals() and vars() to recreate this, but can't separate out the function/Fire variables with existing variables created by the import statements at the top of the file.

this simple example works:

import inspect
import fire


def main(a1: int, b2: str = "aaa"):
    myframe = inspect.currentframe()
    args, _, _, frm = inspect.getargvalues(myframe)
    args = {k: v for k, v in frm.items() if k in args}
    print(args)


if __name__ == '__main__':
    fire.Fire(main)

@Borda
Copy link
Contributor Author

Borda commented Mar 14, 2022

@glenn-jocher all seems fine :)

@glenn-jocher
Copy link
Member

glenn-jocher commented Mar 15, 2022

@Borda I ran into two issues when testing:

Shortened arguments

  • Shortened arguments no longer work, i.e. --img is no longer supported, couldn't find an easy workaround. Many examples and tutorials use these commands, i.e. our Colab notebook.

Screenshot 2022-03-15 at 11 19 55

Multiple weights

  • Multiple --weights used for ensembling no longer work, i.e. --weights model1.pt model2.pt. This may just require changing the weights variable type to a list, but haven't tested yet. In master correct Usage is below (super convenient and understandable for tutorials):

Screenshot 2022-03-15 at 11 21 33

@Borda
Copy link
Contributor Author

Borda commented Mar 15, 2022

Add the short args, yes it is a limitation
Add multiple args, you need to pass them as list or tuple

@Borda
Copy link
Contributor Author

Borda commented May 1, 2022

@glenn-jocher ^^ 🐰

@github-actions
Copy link
Contributor

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions YOLOv5 πŸš€ and Vision AI ⭐.

@github-actions github-actions bot added the Stale Stale and schedule for closing soon label Jun 23, 2022
@github-actions github-actions bot closed this Jun 28, 2022
@glenn-jocher
Copy link
Member

@Borda thanks for the heads-up! We'll look into adding support for shortened arguments and accommodating multiple weights as lists or tuples. Appreciate your input!

@Borda
Copy link
Contributor Author

Borda commented Nov 16, 2023

It was a few years ago lol

@glenn-jocher
Copy link
Member

@Borda time flies! Your past insights are still valuable as we continuously improve YOLOv5. Thank you for your contributions, both then and now! πŸ˜„

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Stale Stale and schedule for closing soon
Projects
None yet
Development

Successfully merging this pull request may close these issues.

simplify CLI
3 participants