From 5e0d9454bfc7cee8b2d455975f9ed2308d3cfb8c Mon Sep 17 00:00:00 2001 From: chenfei Date: Fri, 18 Sep 2020 20:07:08 +0800 Subject: [PATCH] add parameters discription of readme of quant --- .../official/cv/mobilenetv2_quant/Readme.md | 26 +++++++++++++++++ .../cv/mobilenetv2_quant/src/config.py | 3 -- .../cv/mobilenetv2_quant/src/dataset.py | 4 +-- .../official/cv/resnet50_quant/Readme.md | 28 +++++++++++++++++++ .../official/cv/resnet50_quant/src/config.py | 3 -- .../official/cv/resnet50_quant/src/dataset.py | 2 +- .../lenet_quant/test_lenet_quant.py | 8 +++--- 7 files changed, 61 insertions(+), 13 deletions(-) diff --git a/model_zoo/official/cv/mobilenetv2_quant/Readme.md b/model_zoo/official/cv/mobilenetv2_quant/Readme.md index 55c6290018..d22e35330b 100644 --- a/model_zoo/official/cv/mobilenetv2_quant/Readme.md +++ b/model_zoo/official/cv/mobilenetv2_quant/Readme.md @@ -8,6 +8,7 @@ - [Environment Requirements](#environment-requirements) - [Script Description](#script-description) - [Script and Sample Code](#script-and-sample-code) + - [Script Parameters](#script-parameters) - [Training Process](#training-process) - [Evaluation Process](#evaluation-process) - [Model Description](#model-description) @@ -83,6 +84,31 @@ For FP16 operators, if the input data type is FP32, the backend of MindSpore wil ├── export.py # export checkpoint files into air/onnx ``` + +## [Script Parameters](#contents) + +Parameters for both training and evaluation can be set in config.py + +- config for MobileNetV2-quant, ImageNet2012 dataset + + ```python + 'class_num': 1000 # the number of classes in the dataset + 'batch_size': 134 # training batch size + 'epoch_size': 60 # training epochs of mobilenetv2-quant + 'start epoch':200 # pretraining epochs of unquantative network + 'warmup_epochs': 0 # number of warmup epochs + 'lr': 0.3 #learning rate + 'momentum': 0.9 # momentum + 'weight_decay': 4e-5 # weight decay value + 'loss_scale': 1024 # the initial loss_scale value + 'label_smooth': 0.1 #label smooth factor + 'loss_scale': 1024 # the initial loss_scale value + 'save_checkpoint':True # whether save checkpoint file after training finish + 'save_checkpoint_epochs': 1 # the step from which start to save checkpoint file. + 'keep_checkpoint_max': 300 # only keep the last keep_checkpoint_max checkpoint + 'save_checkpoint_path': './checkpoint' # the absolute full path to save the checkpoint file + ``` + ## [Training process](#contents) ### Usage diff --git a/model_zoo/official/cv/mobilenetv2_quant/src/config.py b/model_zoo/official/cv/mobilenetv2_quant/src/config.py index 8aa7750755..de4f5c2bd2 100644 --- a/model_zoo/official/cv/mobilenetv2_quant/src/config.py +++ b/model_zoo/official/cv/mobilenetv2_quant/src/config.py @@ -39,8 +39,6 @@ config_ascend_quant = ed({ config_gpu_quant = ed({ "num_classes": 1000, - "image_height": 224, - "image_width": 224, "batch_size": 134, "epoch_size": 60, "start_epoch": 200, @@ -54,5 +52,4 @@ config_gpu_quant = ed({ "save_checkpoint_epochs": 1, "keep_checkpoint_max": 300, "save_checkpoint_path": "./checkpoint", - "quantization_aware": True, }) diff --git a/model_zoo/official/cv/mobilenetv2_quant/src/dataset.py b/model_zoo/official/cv/mobilenetv2_quant/src/dataset.py index 8c35014dce..aefe160426 100644 --- a/model_zoo/official/cv/mobilenetv2_quant/src/dataset.py +++ b/model_zoo/official/cv/mobilenetv2_quant/src/dataset.py @@ -64,7 +64,7 @@ def create_dataset(dataset_path, do_train, config, device_target, repeat_num=1, else: raise ValueError("Unsupported device_target.") - resize_height = config.image_height + resize_height = 224 if do_train: buffer_size = 20480 @@ -128,7 +128,7 @@ def create_dataset_py(dataset_path, do_train, config, device_target, repeat_num= else: raise ValueError("Unsupported device target.") - resize_height = config.image_height + resize_height = 224 if do_train: buffer_size = 20480 diff --git a/model_zoo/official/cv/resnet50_quant/Readme.md b/model_zoo/official/cv/resnet50_quant/Readme.md index 2a537dbef1..2c77e3d3b4 100644 --- a/model_zoo/official/cv/resnet50_quant/Readme.md +++ b/model_zoo/official/cv/resnet50_quant/Readme.md @@ -8,6 +8,7 @@ - [Environment Requirements](#environment-requirements) - [Script Description](#script-description) - [Script and Sample Code](#script-and-sample-code) + - [Script Parameters](#script-parameters) - [Training Process](#training-process) - [Evaluation Process](#evaluation-process) - [Model Description](#model-description) @@ -83,6 +84,33 @@ For FP16 operators, if the input data type is FP32, the backend of MindSpore wil ``` +## [Script Parameters](#contents) + +Parameters for both training and evaluation can be set in config.py + +- config for Resnet50-quant, ImageNet2012 dataset + + ```python + 'class_num': 10 # the number of classes in the dataset + 'batch_size': 32 # training batch size + 'loss_scale': 1024 # the initial loss_scale value + 'momentum': 0.9 # momentum + 'weight_decay': 1e-4 # weight decay value + 'epoch_size': 120 # total training epochs + 'pretrained_epoch_size': 90 # pretraining epochs of resnet50, which is unquantative network of resnet50_quant + 'data_load_mode': 'mindata' # the style of loading data into device + 'save_checkpoint':True # whether save checkpoint file after training finish + 'save_checkpoint_epochs': 1 # the step from which start to save checkpoint file. + 'keep_checkpoint_max': 50 # only keep the last keep_checkpoint_max checkpoint + 'save_checkpoint_path': './' # the absolute full path to save the checkpoint file + "warmup_epochs": 0 # number of warmup epochs + 'lr_decay_mode': "cosine" #learning rate decay mode, including steps, steps_decay, cosine or liner + 'use_label_smooth': True #whether use label smooth + 'label_smooth_factor': 0.1 #label smooth factor + 'lr_init': 0 # initial learning rate + 'lr_max': 0.005 # the max learning rate + ``` + ## [Training process](#contents) ### Usage diff --git a/model_zoo/official/cv/resnet50_quant/src/config.py b/model_zoo/official/cv/resnet50_quant/src/config.py index 8137227d44..b8d46f6a63 100755 --- a/model_zoo/official/cv/resnet50_quant/src/config.py +++ b/model_zoo/official/cv/resnet50_quant/src/config.py @@ -24,9 +24,6 @@ config_quant = ed({ "weight_decay": 1e-4, "epoch_size": 120, "pretrained_epoch_size": 90, - "buffer_size": 1000, - "image_height": 224, - "image_width": 224, "data_load_mode": "mindata", "save_checkpoint": True, "save_checkpoint_epochs": 1, diff --git a/model_zoo/official/cv/resnet50_quant/src/dataset.py b/model_zoo/official/cv/resnet50_quant/src/dataset.py index 688104f41f..4070e76ac1 100755 --- a/model_zoo/official/cv/resnet50_quant/src/dataset.py +++ b/model_zoo/official/cv/resnet50_quant/src/dataset.py @@ -62,7 +62,7 @@ def create_dataset(dataset_path, do_train, repeat_num=1, batch_size=32, target=" ds = load_func(num_parallel_workers=8, shuffle=True, num_shards=device_num, shard_id=rank_id) - image_size = config.image_height + image_size = 224 mean = [0.485 * 255, 0.456 * 255, 0.406 * 255] std = [0.229 * 255, 0.224 * 255, 0.225 * 255] diff --git a/tests/st/quantization/lenet_quant/test_lenet_quant.py b/tests/st/quantization/lenet_quant/test_lenet_quant.py index 1d1e8fb94a..b801cdcfca 100644 --- a/tests/st/quantization/lenet_quant/test_lenet_quant.py +++ b/tests/st/quantization/lenet_quant/test_lenet_quant.py @@ -47,7 +47,7 @@ def train_lenet(): time_cb = TimeMonitor(data_size=ds_train.get_dataset_size()) config_ck = CheckpointConfig(save_checkpoint_steps=cfg.save_checkpoint_steps, keep_checkpoint_max=cfg.keep_checkpoint_max) - ckpoint_cb = ModelCheckpoint(prefix="checkpoint_lenet", config=config_ck) + ckpoint_cb = ModelCheckpoint(prefix="ckpt_lenet_noquant", config=config_ck) model = Model(network, net_loss, net_opt, metrics={"Accuracy": Accuracy()}) print("============== Starting Training Lenet==============") @@ -58,7 +58,7 @@ def train_lenet(): def train_lenet_quant(): context.set_context(mode=context.GRAPH_MODE, device_target=device_target) cfg = quant_cfg - ckpt_path = './checkpoint_lenet-10_1875.ckpt' + ckpt_path = './ckpt_lenet_noquant-10_1875.ckpt' ds_train = create_dataset(os.path.join(data_path, "train"), cfg.batch_size, 1) step_size = ds_train.get_dataset_size() @@ -81,7 +81,7 @@ def train_lenet_quant(): # call back and monitor config_ckpt = CheckpointConfig(save_checkpoint_steps=cfg.epoch_size * step_size, keep_checkpoint_max=cfg.keep_checkpoint_max) - ckpt_callback = ModelCheckpoint(prefix="checkpoint_lenet", config=config_ckpt) + ckpt_callback = ModelCheckpoint(prefix="ckpt_lenet_quant", config=config_ckpt) # define model model = Model(network, net_loss, net_opt, metrics={"Accuracy": Accuracy()}) @@ -96,7 +96,7 @@ def eval_quant(): context.set_context(mode=context.GRAPH_MODE, device_target=device_target) cfg = quant_cfg ds_eval = create_dataset(os.path.join(data_path, "test"), cfg.batch_size, 1) - ckpt_path = './checkpoint_lenet_1-10_937.ckpt' + ckpt_path = './ckpt_lenet_quant-10_937.ckpt' # define fusion network network = LeNet5Fusion(cfg.num_classes) # convert fusion network to quantization aware network