I am testing a python script with multiple images.
I am using argparse python library.
python srcmain.py -p 'completepathimg1.jpg'
python srcmain.py -p 'completepathimg2.jpg'
python srcmain.py -p 'completepathimg3.jpg'
python srcmain.py -p 'completepathimg4.jpg'
I type the above text in a notepad and paste that into terminal.
Ideally, it should work. Invoking main.py
with each image.
But what actually happening is, it works alternatively.
like,
C:UsersxxxDesktop>python srcmain.py -p "C:UsersxxxDesktopReleaseIMG_3515.JPG"
expected result, Working...
C:UsersxxxDesktopBHUBRCAnalyzer>hon srcmain.py -p "C:UsersxxxDesktopReleaseIMG_3516.JPG"
'hon' is not recognized as an internal or external command,
operable program or batch file.
C:UsersxxxDesktop>python srcmain.py -p "C:UsersxxxDesktopReleaseIMG_3515.JPG"
expected result, Working...
C:UsersxDesktopBHUBRCAnalyzer>hon srcmain.py -p "C:UsersxDesktopReleaseIMG_3516.JPG"
'hon' is not recognized as an internal or external command,
operable program or batch file.
What I have already tried.
- Copying from different editor (Notepad and VS Code)
- Give an extra new line between the commands
UPDATE: My code looks something like this. The ultralytics module is causing the issue, I am not sure how to avoid this.
This does not occur if I comment out the ultralytics model lines.
from ultralytics import YOLO
import argparse
def main(args:dict):
model=YOLO()
model(args['path'])
if __name__=="__main__":
arg_parser = argparse.ArgumentParser(fromfile_prefix_chars="@")
arg_parser.add_argument("-p", "--path", help="path of the image to get feature", required=True)
args = arg_parser.parse_args()
main(args.__dict__)
9
It doesn’t make sense for the script to have an option if its argument isn’t optional.
from ultralytics import YOLO
def main(args: list[str]):
model=YOLO()
model(args)
if __name__=="__main__":
from sys import argv
main(argv[1:])
This assumes that model
can accept multiple file arguments, or perhaps lets you loop over them like
def main(args: list[str]):
model=YOLO()
for filename in args:
model(args)
Usage:
python newscript.py completepathimg1.jpg completepathimg2.jpg completepathimg3.jpg completepathimg4.jpg
2