Slightly modify CLI execution (#3687)

* Slightly modify CLI execution

This simple change makes it easier to run the primary functions of this
repo (train/detect/test) from within Python. An object which represents
`opt` can be constructed and fed to the `main` function of each of these
modules, rather than having to call the lower level functions directly,
or run the module as a script.

* Update export.py

Add CLI parsing update for more convenient module usage within Python.

Co-authored-by: Lewis Belcher <lb@desupervised.io>
This commit is contained in:
lb-desupervisedandLewis Belcher authored and GitHub committed 2021-06-19 12:06:59 +02:00
1 parent bf209f6fe9
commit bfb2276b1d
4 files changed
+41 -6

No files matched your search

+10 -1
View File
@@ -294,7 +294,7 @@ def test(data,
return (mp, mr, map50, map, *(loss.cpu() / len(dataloader)).tolist()), maps, t
if __name__ == '__main__':
def parse_opt():
parser = argparse.ArgumentParser(prog='test.py')
parser.add_argument('--data', type=str, default='data/coco128.yaml', help='dataset.yaml path')
parser.add_argument('--weights', nargs='+', type=str, default='yolov5s.pt', help='model.pt path(s)')
@@ -319,6 +319,10 @@ if __name__ == '__main__':
opt.save_json |= opt.data.endswith('coco.yaml')
opt.save_txt |= opt.save_hybrid
opt.data = check_file(opt.data) # check file
return opt
def main(opt):
print(opt)
check_requirements(exclude=('tensorboard', 'thop'))
@@ -344,3 +348,8 @@ if __name__ == '__main__':
np.savetxt(f, y, fmt='%10.4g') # save
os.system('zip -r study.zip study_*.txt')
plot_study_txt(x=x) # plot
if __name__ == "__main__":
opt = parse_opt()
main(opt)