File size: 2,525 Bytes
1ae42c8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import ultralytics


'''

NOTE:
adjust this code as needed - the below are parameters for a 8xB200 system


'''


if __name__ == "__main__":
  ultralytics.checks()
  
  userName = '{user}'

  epochs = 100
  
  # pick and choose what datasets to train - make sure to first run PrepareDatasets.py
  dataNames = [
    'synetic-train+real-val',
    'synetic-train+real-original-val',

    'synetic-bg-train+real-val',
    'synetic+real',

    'synetic-bg-train+real-original-val',
    'synetic+real-original',

    'real',
    'real-original',

    'synetic-bg',
    'synetic',
  ]

  hyperparams = [
    ('12', 'n', f'/home/{userName}/datasets/ApplesM5'),
    ('11', 'n', f'/home/{userName}/datasets/ApplesM5'),
    ('v8', 'n', f'/home/{userName}/datasets/ApplesM5'),
    ('v6', 'n', f'/home/{userName}/datasets/ApplesM5'),
    ('v5', 'n', f'/home/{userName}/datasets/ApplesM5'),
    ('v3', 'n', f'/home/{userName}/datasets/ApplesM5'),
    ('rtdetr', '-l', f'/home/{userName}/datasets/ApplesM5')
  ]

  for dataName in dataNames:
    for hyperparam in hyperparams:
      modelVersion, modelSize, pathDataYaml = hyperparam

      pathDataYaml = f'{pathDataYaml}/{dataName}/{dataName}.yaml'

      projectName = f'ApplesM5_{modelVersion}{modelSize}'
      taskName = 'detect'
      
      if 'rtdetr' in modelVersion:
        modelName = f"{modelVersion}{modelSize}.pt"
        modelDet = ultralytics.RTDETR(modelName)
      else:
        modelName = f"yolo{modelVersion}{modelSize}.yaml"
        modelDet = ultralytics.YOLO(modelName)
        
      trainName = f'{projectName}-{taskName}-{epochs}_{dataName}_0'

      devices = [0, 1, 2, 3, 4, 5, 6, 7]
      devicesLen = len(devices)

      batchSize = devicesLen * 30 * 2

      batchSize = int(batchSize)

      results = modelDet.train(
        imgsz=640,

        name=trainName,
        data=pathDataYaml,
        task=taskName,
        epochs=epochs,
        device=devices,
        batch=batchSize,
        workers=28,

        cache='disk',

        flipud=0.5,
        fliplr=0.5,

        hsv_h=0.1,
        hsv_s=0.1,
        hsv_v=0.1,

        mosaic=0.75,
        close_mosaic=0,

        degrees=45.0,
        shear=15.0,
        perspective=0.0005,
        translate=0.3,
        mixup=0.1,        # image mixup (probability)
        copy_paste=0.1,   # segment copy-paste (probability)
        auto_augment='randaugment', # (str) auto augmentation policy for classification (randaugment, autoaugment, augmix)
        augment=True,

        val=True,

      )