nnictl create -(xxxx.yml)[这是创建的配置文件]
不同的数据增强
不同的优化器
{
"optimizer":{"_type":"choice", "_value":["Adam", "Adamax", "Adagrad", "RMSprop", "Adagrad"]},
"Transpose":{"_type":"choice", "_value":[0.3, 0.4, 0.5]},
"HorizontalFlip":{"_type":"choice", "_value":[0.3, 0.4, 0.5]},
"VerticalFlip":{"_type":"choice", "_value":[0.3, 0.4, 0.5]},
"ShiftScaleRotate":{"_type":"choice", "_value":[0.3, 0.4, 0.5]},
"hue_shift_limit":{"_type":"choice", "_value":[0.2, 0.3, 0.4]},
"sat_shift_limit":{"_type":"choice", "_value":[0.2, 0.3, 0.4]},
"val_shift_limit":{"_type":"choice", "_value":[0.2, 0.3, 0.4]},
"HueSaturationValue":{"_type":"choice", "_value":[0.3, 0.4, 0.5]}
}
在没有nni的代码上加nni
try:
tuner_params = nni.get_next_parameter()
optimizer_type = tuner_params['optimizer']
def get_train_transforms(data_aug_param):
# return Compose([
# RandomResizedCrop(CFG['img_size'], CFG['img_size']),
# Transpose(p=0.5),
# HorizontalFlip(p=0.5),
# VerticalFlip(p=0.5),
# ShiftScaleRotate(p=0.5),
# HueSaturationValue(hue_shift_limit=0.2, sat_shift_limit=0.2, val_shift_limit=0.2, p=0.5),
# RandomBrightnessContrast(brightness_limit=(-0.1, 0.1), contrast_limit=(-0.1, 0.1), p=0.5),
# Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225], max_pixel_value=255.0, p=1.0),
# CoarseDropout(p=0.5),
# Cutout(p=0.5),
# ToTensorV2(p=1.0),
# ], p=1.)
return Compose([
RandomResizedCrop(CFG['img_size'], CFG['img_size']),
Transpose(p=data_aug_param['Transpose']),
HorizontalFlip(p=data_aug_param['HorizontalFlip']),
VerticalFlip(p=data_aug_param['VerticalFlip']),
ShiftScaleRotate(p=data_aug_param['ShiftScaleRotate']),
HueSaturationValue(hue_shift_limit=data_aug_param['hue_shift_limit'], sat_shift_limit=data_aug_param['sat_shift_limit'], val_shift_limit=data_aug_param['val_shift_limit'], p=data_aug_param['HueSaturationValue']),
RandomBrightnessContrast(brightness_limit=(-0.1, 0.1), contrast_limit=(-0.1, 0.1), p=0.5),
Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225], max_pixel_value=255.0, p=1.0),
CoarseDropout(p=0.5),
Cutout(p=0.5),
ToTensorV2(p=1.0),
], p=1.)
上报中间精度和最终指标
authorName: default
experimentName: cldc
trialConcurrency: 1
maxExecDuration: 24h
maxTrialNum: 50
#choice: local, remote, pai
trainingServicePlatform: local
searchSpacePath: search_space.json
#choice: true, false
useAnnotation: false
tuner:
#choice: TPE, Random, Anneal, Evolution, BatchTuner, MetisTuner, GPTuner
#SMAC (SMAC should be installed through nnictl)
builtinTunerName: TPE
classArgs:
#choice: maximize, minimize
optimize_mode: maximize
trial:
command: python train_nni.py #训练用的代码
codeDir: .
gpuNum: 1 #gpu数量,一定记得改
localConfig:
useActiveGpu: true