-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrain_cls.py
More file actions
44 lines (38 loc) · 1.35 KB
/
train_cls.py
File metadata and controls
44 lines (38 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# in ultralytics/utils/metrics.py
import os
import argparse
from const import PATH
parser = argparse.ArgumentParser(description="Train yolo detection model.")
# parser.add_argument("--yaml", type=str, required=True,
# help="yaml file path")
parser.add_argument('--model', type=str, help='pretrained model')
parser.add_argument('--tag', type=str, help='tag of config')
parser.add_argument('--gpu', type=str, default='0', help='gpu id to run inference')
parser.add_argument('--fold', type=int, help='fold id')
args = parser.parse_args()
os.environ["CUDA_VISIBLE_DEVICES"] = args.gpu
from ultralytics import YOLO
def train(model_name, tag, fold, save_dir):
# model_dir = os.path.join('./save', model_name, f'fold_{fold}')
# ckpt_path = os.path.join(model_dir, 'weights', "best.pt")
model = YOLO(model_name)
# Train the model
model.train(
data=os.path.join(PATH, "b6_cv", f'fold_{fold}'),
epochs=10,
imgsz=128,
batch=64,
augment=True,
mosaic=0,
mixup=0,
erasing=0,
lr0=0.001,
lrf=0.0001,
#optimizer='adamw',
flipud=0.5,
auto_augment=None,
project=save_dir, # wandb project name
name=tag+'/'+f'fold_{fold}', # wandb run name
)
if __name__ == '__main__':
train(args.model, args.tag, args.fold, 'save')