CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hukaixuan19970627

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: hukaixuan19970627/yolov5_obb
Path: blob/master/utils/loggers/wandb/sweep.py
Views: 475
1
import sys
2
from pathlib import Path
3
4
import wandb
5
6
FILE = Path(__file__).resolve()
7
ROOT = FILE.parents[3] # YOLOv5 root directory
8
if str(ROOT) not in sys.path:
9
sys.path.append(str(ROOT)) # add ROOT to PATH
10
11
from train import parse_opt, train
12
from utils.callbacks import Callbacks
13
from utils.general import increment_path
14
from utils.torch_utils import select_device
15
16
17
def sweep():
18
wandb.init()
19
# Get hyp dict from sweep agent
20
hyp_dict = vars(wandb.config).get("_items")
21
22
# Workaround: get necessary opt args
23
opt = parse_opt(known=True)
24
opt.batch_size = hyp_dict.get("batch_size")
25
opt.save_dir = str(increment_path(Path(opt.project) / opt.name, exist_ok=opt.exist_ok or opt.evolve))
26
opt.epochs = hyp_dict.get("epochs")
27
opt.nosave = True
28
opt.data = hyp_dict.get("data")
29
opt.weights = str(opt.weights)
30
opt.cfg = str(opt.cfg)
31
opt.data = str(opt.data)
32
opt.hyp = str(opt.hyp)
33
opt.project = str(opt.project)
34
device = select_device(opt.device, batch_size=opt.batch_size)
35
36
# train
37
train(hyp_dict, opt, device, callbacks=Callbacks())
38
39
40
if __name__ == "__main__":
41
sweep()
42
43