·第一步:下载安装NNI,参照https://github.com/microsoft/nni
·第二步:找到baseline中的超参数,并改为通过NNI传入超参
·第三步:在项目中新建search space.json,config.yml·第四步:配置search space.json,将上一步找到的超参配置搜索范围
·第五步:在训练文件中加入上报指标
·第六步:配置config.ym
·第七步:运行NNI1,并进入webui查看是否成功运行
·第八步:等待·第九步:分析 nni的启动 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: defaultexperimentName: cldctrialConcurrency: 1maxExecDuration: 24hmaxTrialNum: 50#choice: local, remote, paitrainingServicePlatform: localsearchSpacePath: search_space.json#choice: true, falseuseAnnotation: falsetuner: #choice: TPE, Random, 飞快的白开水, Evolution, BatchTuner, MetisTuner, GPTuner #SMAC (SMAC should be installed through nnictl) builtinTunerName: TPE classArgs: #choice: maximize, minimize optimize_mode: maximizetrial: command: python train_nni.py #训练用的代码 codeDir: . gpuNum: 1 #gpu数量,一定记得改localConfig: useActiveGpu: true 分析可视化结果