Cli support (#50)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
This commit is contained in:
Ayush Chaurasia
2022-11-23 16:07:27 +05:30
committed by GitHub
parent 4291b9c31c
commit 512a225ce8
9 changed files with 70 additions and 17 deletions

View File

@ -1,7 +1,39 @@
import ultralytics.yolo.v8 as v8
import hydra
import ultralytics
import ultralytics.yolo.v8 as yolo
from .engine.model import YOLO
from .engine.trainer import BaseTrainer
from .engine.trainer import DEFAULT_CONFIG, BaseTrainer
from .engine.validator import BaseValidator
from .utils import LOGGER
__all__ = ["BaseTrainer", "BaseValidator", "YOLO"] # allow simpler import
@hydra.main(version_base=None, config_path="utils/configs", config_name="default")
def cli(cfg):
LOGGER.info(f"using Ultralytics YOLO v{ultralytics.__version__}")
module_file = None
if cfg.task.lower() == "detect":
module_file = yolo.detect
elif cfg.task.lower() == "segment":
module_file = yolo.segment
elif cfg.task.lower() == "classify":
module_file = yolo.classify
if not module_file:
raise Exception("task not recognized. Choices are `'detect', 'segment', 'classify'`")
module_function = None
if cfg.mode.lower() == "train":
module_function = module_file.train
elif cfg.mode.lower() == "val":
module_function = module_file.val
elif cfg.mode.lower() == "infer":
module_function = module_file.infer
if not module_function:
raise Exception("mode not recognized. Choices are `'train', 'val', 'infer'`")
module_function(cfg)

View File

@ -1,6 +1,9 @@
# YOLO 🚀 by Ultralytics, GPL-3.0 license
# Default training settings and hyperparameters for medium-augmentation COCO training
# Task and Mode
task: "classify" # choices=['detect', 'segment', 'classify']
mode: "train" # choice=['train', 'val', 'infer']
# Train settings -------------------------------------------------------------------------------------------------------
model: null # i.e. yolov5s.pt, yolo.yaml
@ -36,7 +39,6 @@ max_det: 300
half: True
plots: False
save_txt: False
task: 'val'
# Hyperparameters ------------------------------------------------------------------------------------------------------
lr0: 0.001 # initial learning rate (SGD=1E-2, Adam=1E-3)

View File

@ -1,4 +1,4 @@
from ultralytics.yolo.v8.classify.train import ClassificationTrainer
from ultralytics.yolo.v8.classify.train import ClassificationTrainer, train
from ultralytics.yolo.v8.classify.val import ClassificationValidator
__all__ = ["train"]

View File

@ -1,2 +1,2 @@
from ultralytics.yolo.v8.segment.train import SegmentationTrainer
from ultralytics.yolo.v8.segment.train import SegmentationTrainer, train
from ultralytics.yolo.v8.segment.val import SegmentationValidator