2021-07-14 22:43:02 +05:30
|
|
|
import sys
|
2021-07-28 21:10:08 +05:30
|
|
|
from pathlib import Path
|
2021-07-14 22:43:02 +05:30
|
|
|
|
2021-07-28 23:35:14 +02:00
|
|
|
import wandb
|
|
|
|
|
2021-09-11 22:46:33 +02:00
|
|
|
FILE = Path(__file__).resolve()
|
2021-09-18 15:02:08 +02:00
|
|
|
ROOT = FILE.parents[3] # YOLOv5 root directory
|
|
|
|
if str(ROOT) not in sys.path:
|
|
|
|
sys.path.append(str(ROOT)) # add ROOT to PATH
|
2021-07-14 22:43:02 +05:30
|
|
|
|
|
|
|
from train import train, parse_opt
|
|
|
|
from utils.general import increment_path
|
|
|
|
from utils.torch_utils import select_device
|
2021-09-11 02:28:52 +12:00
|
|
|
from utils.callbacks import Callbacks
|
2021-07-14 22:43:02 +05:30
|
|
|
|
|
|
|
|
|
|
|
def sweep():
|
|
|
|
wandb.init()
|
|
|
|
# Get hyp dict from sweep agent
|
|
|
|
hyp_dict = vars(wandb.config).get("_items")
|
|
|
|
|
|
|
|
# Workaround: get necessary opt args
|
|
|
|
opt = parse_opt(known=True)
|
|
|
|
opt.batch_size = hyp_dict.get("batch_size")
|
|
|
|
opt.save_dir = str(increment_path(Path(opt.project) / opt.name, exist_ok=opt.exist_ok or opt.evolve))
|
|
|
|
opt.epochs = hyp_dict.get("epochs")
|
|
|
|
opt.nosave = True
|
|
|
|
opt.data = hyp_dict.get("data")
|
2021-10-29 22:51:59 +05:30
|
|
|
opt.weights = str(opt.weights)
|
|
|
|
opt.cfg = str(opt.cfg)
|
|
|
|
opt.data = str(opt.data)
|
|
|
|
opt.hyp = str(opt.hyp)
|
|
|
|
opt.project = str(opt.project)
|
2021-07-14 22:43:02 +05:30
|
|
|
device = select_device(opt.device, batch_size=opt.batch_size)
|
|
|
|
|
|
|
|
# train
|
2021-09-11 02:28:52 +12:00
|
|
|
train(hyp_dict, opt, device, callbacks=Callbacks())
|
2021-07-14 22:43:02 +05:30
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
sweep()
|