From dc7503c48869a49ea7f2cc28bc528328d992fb05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E5=A4=A9=E5=A7=BF?= Date: Wed, 8 Jul 2020 02:42:20 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AC=AC=E4=BA=8C=E5=85=B3=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MindSpore/src/step2/step2.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 MindSpore/src/step2/step2.py diff --git a/MindSpore/src/step2/step2.py b/MindSpore/src/step2/step2.py new file mode 100644 index 0000000..332b721 --- /dev/null +++ b/MindSpore/src/step2/step2.py @@ -0,0 +1,35 @@ +if __name__ == "__main__": + parser = argparse.ArgumentParser(description='MindSpore LeNet Example') + parser.add_argument('--device_target', type=str, default="CPU", choices=['Ascend', 'GPU', 'CPU'], + help='device where the code will be implemented (default: CPU)') + args = parser.parse_args() + context.set_context(mode=context.GRAPH_MODE, device_target=args.device_target) + # download mnist dataset + download_dataset() + # learning rate setting + lr = 0.01 + momentum = 0.9 + epoch_size = 1 + mnist_path = "./MNIST_Data" + # 请在此添加代码完成本关任务 + # **********Begin*********# + ##提示:补全损失函数的定义 + + # **********End**********# + repeat_size = epoch_size + # create the network + network = LeNet5() + # define the optimizer + # 请在此添加代码完成本关任务 + # **********Begin*********# + ##提示:补全优化器的定义 + + # **********End**********# + + # save the network model and parameters for subsequence fine-tuning + ckpoint_cb = ModelCheckpoint(prefix="checkpoint_lenet", config=config_ck) + # group layers into an object with training and evaluation features + model = Model(network, net_loss, net_opt, metrics={"Accuracy": Accuracy()}) + + train_net(args, model, epoch_size, mnist_path, repeat_size, ckpoint_cb) + test_net(args, network, model, mnist_path)