diff --git a/AutoDL Design/README.md b/AutoDL Design/README.md new file mode 100644 index 0000000000000000000000000000000000000000..9173578ecb12decc44e0d79bf1655fc5e65dd572 --- /dev/null +++ b/AutoDL Design/README.md @@ -0,0 +1,82 @@ +# AutoDL Design 简介 + +## 目录 +- [安装](#安装) +- [简介](#简介) +- [数据准备](#数据准备) +- [模型训练](#模型训练) + +## 安装 +在当前目录下运行样例代码需要PadddlePaddle Fluid的v.1.3.0或以上的版本。如果你的运行环境中的PaddlePaddle低于此版本,请根据安装文档中的说明来更新PaddlePaddle。 +* 安装Python2.7 +* 训练执行依赖[PARL](https://github.com/PaddlePaddle/PARL) 框架和[absl-py](https://github.com/abseil/abseil-py/tree/master/absl) 库,通过如下命令安装 +``` + pip install parl + pip install absl-py +``` + + +## 简介 +[AutoDL](http://www.paddlepaddle.org/paddle/ModelAutoDL)是一种高效的自动搜索构建最佳网络结构的方法,通过增强学习在不断训练过程中得到定制化高质量的模型。系统由两部分组成,第一部分是网络结构的编码器,第二部分是网络结构的评测器。编码器通常以 RNN 的方式把网络结构进行编码,然后评测器把编码的结果拿去进行训练和评测,拿到包括准确率、模型大小在内的一些指标,反馈给编码器,编码器进行修改,再次编码,如此迭代。经过若干次迭代以后,最终得到一个设计好的模型。这里开源的AutoDl Design是基于PaddlePaddle框架的一种AutoDL技术实现。第二节介绍AutoDL Design的使用步骤。第三节介绍AutoDL Design的实现原理与示例。 + +## 数据准备 +* 克隆[PaddlePaddle/AutoDL](https://github.com/PaddlePaddle/AutoDL.git)到测试机,并进入AutoDL Design路径。 +* 下载[CIFAR-10](https://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz)训练数据,并放入AutoDL Design/cifar路径下并解压,按如下命令执行`dataset_maker.py` 生成10类每类100张图片的pickle训练小数据集。 +``` +tar zxf cifar-10-python.tar.gz +python dataset_maker.py +``` + +## 模型训练 +AutoDL Design在训练过程中每次通过Agent的策略网络生成用于训练的Tokens和邻接矩阵Adj,然后Trainer通过Tokens和Adj进行CNN训练网络的组建与训练,训练20个epoch以后返回训练的acc值作为Reward返回给Agent,Agent收到Reward值以后更新策略,通过不断的迭代,最终可以自动搜索到效果不错的深度神经网络。 +![图片](./img/cnn_net.png) +这里提供了如下两种测试的方法。 + +### 针对生成tokens个数的收敛性测试 +由于CNN训练每次执行时间长,为了测试整体Agent框架的正确性,这里我们把生成tokens个数作为模拟CNN训练的返回Reward,最终自动搜索出来的网络可以使得tokens的个数越来越多。这里tokens向量总长度设置的是20。执行以下命令: +``` + export FLAGS_fraction_of_gpu_memory_to_use=0.98 + export FLAGS_eager_delete_tensor_gb=0.0 + export FLAGS_fast_eager_deletion_mode=1 + CUDA_VISIBLE_DEVICES=0 python -u simple_main.py +``` +预期结果: +日志中 `average rewards`逐步向20收敛递增 + +``` +Simple run target is 20 +mid=0, average rewards=2.500 +... +mid=450, average rewards=17.100 +mid=460, average rewards=17.000 + +``` + +### AutoDL网络自动搜索训练 +基于CIFAR-10小数据集上执行自动网络搜索策略,每次先执行Agent策略网络生成新的策略,然后Trainer根据生成的策略去进行模型的训练与Reward(即acc指标)结果的反馈,最终不断迭代搜索到准确率更高的模型网络结构。执行以下命令: +``` + export FLAGS_fraction_of_gpu_memory_to_use=0.98 + export FLAGS_eager_delete_tensor_gb=0.0 + export FLAGS_fast_eager_deletion_mode=1 + CUDA_VISIBLE_DEVICES=0 python -u main.py +``` +__注意:__ 这里训练需要使用两张卡来训练,Agent使用的卡为`CUDA_VISIBLE_DEVICES=0`(设置在启动`main.py`命令中);Trainer训练使用卡为`CUDA_VISIBLE_DEVICES=1`(设置在[autodl.py](https://github.com/PaddlePaddle/AutoDL/blob/master/AutoDL%20Design/autodl.py#L124)文件中) + +预期结果: +日志中 `average accuracy`逐步增大 + +``` +step = 0, average accuracy = 0.633 +step = 1, average accuracy = 0.688 +step = 2, average accuracy = 0.626 +step = 3, average accuracy = 0.682 +...... +step = 842, average accuracy = 0.823 +step = 843, average accuracy = 0.825 +step = 844, average accuracy = 0.808 +...... +``` +### 结果展示 + +![图片](./img/search_result.png) +横坐标是迭代的step轮数,纵坐标是模型训练的acc指标,通过图中所示,通过不断的迭代搜索,使得自动构建模型的效果在不断增强。 diff --git a/AutoDL Design/autodl.py b/AutoDL Design/autodl.py index dde6edf0b55aeee424bcfc9079cdff5f395d705e..444d0e5da983c300e44fb555b6e55a42a2ba17fa 100644 --- a/AutoDL Design/autodl.py +++ b/AutoDL Design/autodl.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -# -*- encoding:utf-8 -*- +# -*- coding:utf-8 -*- # Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserve. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/AutoDL Design/autodl_agent.py b/AutoDL Design/autodl_agent.py index 39fc8262c9d1030d29c8a2631b494c9fa7429f67..9ef7f0eebfeaed11c0b3b19f2aa6728655362259 100755 --- a/AutoDL Design/autodl_agent.py +++ b/AutoDL Design/autodl_agent.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -# -*- encoding:utf-8 -*- +# -*- coding:utf-8 -*- # Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserve. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/AutoDL Design/cifar/dataset_maker.py b/AutoDL Design/cifar/dataset_maker.py index bc7d89578c1e933b80746971c33065038ff21e98..e0a3aa1e8223759149494a6202d78a8c10f11edb 100644 --- a/AutoDL Design/cifar/dataset_maker.py +++ b/AutoDL Design/cifar/dataset_maker.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -# -*- encoding:utf-8 -*- +# -*- coding:utf-8 -*- # Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserve. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/AutoDL Design/distribute_generator.py b/AutoDL Design/distribute_generator.py index 945d3278ae5184a7eb7ee854d9b828f67aa497b3..824c1620aa604a735e191b507853e2f2c355e5f9 100644 --- a/AutoDL Design/distribute_generator.py +++ b/AutoDL Design/distribute_generator.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -# -*- encoding:utf-8 -*- +# -*- coding:utf-8 -*- # Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserve. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/AutoDL Design/img/cnn_net.png b/AutoDL Design/img/cnn_net.png new file mode 100644 index 0000000000000000000000000000000000000000..f7e6b2c5f5e6df3e3697e4f3e3bae89a3a04abc1 Binary files /dev/null and b/AutoDL Design/img/cnn_net.png differ diff --git a/AutoDL Design/img/search_result.png b/AutoDL Design/img/search_result.png new file mode 100644 index 0000000000000000000000000000000000000000..216ae6cbd8b7a5e5eafe4e14146ddc70d0935048 Binary files /dev/null and b/AutoDL Design/img/search_result.png differ diff --git a/AutoDL Design/inception_train/models/inception.py b/AutoDL Design/inception_train/models/inception.py index dc8b1b268b832100ce7da9021d388a8a483b6fb0..2a3001006b777f451204ae3c805882543fae19e8 100644 --- a/AutoDL Design/inception_train/models/inception.py +++ b/AutoDL Design/inception_train/models/inception.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -# -*- encoding:utf-8 -*- +# -*- coding:utf-8 -*- # Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserve. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/AutoDL Design/inception_train/models/layers.py b/AutoDL Design/inception_train/models/layers.py index 8642cca9f0bb1aebb52c61b80f99001cf9f2fb58..ca8ce533d31478c84caa58083cdf66aa1beea299 100644 --- a/AutoDL Design/inception_train/models/layers.py +++ b/AutoDL Design/inception_train/models/layers.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -# -*- encoding:utf-8 -*- +# -*- coding:utf-8 -*- # Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserve. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/AutoDL Design/inception_train/models/ops.py b/AutoDL Design/inception_train/models/ops.py index 47a5a9fc7da6d34773f727ee4c5ec3616c867ee3..7e41c228e8e97245f2f1bca6c774e1fcc375e314 100644 --- a/AutoDL Design/inception_train/models/ops.py +++ b/AutoDL Design/inception_train/models/ops.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -# -*- encoding:utf-8 -*- +# -*- coding:utf-8 -*- # Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserve. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/AutoDL Design/inception_train/nn.py b/AutoDL Design/inception_train/nn.py index cd697299a895929b8e5c8ff1b6c7d0097de0832e..a79a7c45d0c1e4182eb9e0526ab0e11a322c04a5 100644 --- a/AutoDL Design/inception_train/nn.py +++ b/AutoDL Design/inception_train/nn.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -# -*- encoding:utf-8 -*- +# -*- coding:utf-8 -*- # Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserve. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/AutoDL Design/inception_train/preprocess.py b/AutoDL Design/inception_train/preprocess.py index 33c94f6974a8d02e4d026a2993c4df5a9d1b538f..c14368e94be140aae1814bce5ae8ecadadb6d467 100644 --- a/AutoDL Design/inception_train/preprocess.py +++ b/AutoDL Design/inception_train/preprocess.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -# -*- encoding:utf-8 -*- +# -*- coding:utf-8 -*- # Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserve. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/AutoDL Design/inception_train/reader.py b/AutoDL Design/inception_train/reader.py index 3e97050045c09c79c1cd31249594e18945a7a08d..0b0027880814938f875d0faaf3790bf8ca4e5066 100644 --- a/AutoDL Design/inception_train/reader.py +++ b/AutoDL Design/inception_train/reader.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -# -*- encoding:utf-8 -*- +# -*- coding:utf-8 -*- # Copyright (c) 2019 PaddlePaddle Authors. All Rig hts Reserved # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/AutoDL Design/inception_train/train.py b/AutoDL Design/inception_train/train.py index 1506b8e763606b5796db6804de3c0770c0a2d74a..8ffaa0c202da71c9ff50d084d163ce6ca4ebe3aa 100644 --- a/AutoDL Design/inception_train/train.py +++ b/AutoDL Design/inception_train/train.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -# -*- encoding:utf-8 -*- +# -*- coding:utf-8 -*- # Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserve. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/AutoDL Design/inception_train/utils.py b/AutoDL Design/inception_train/utils.py index 24f94e859ca8cc1e0295c4d1b50b114e0fdb2720..30dc859b08213bb991632f4285268db9c17f0e74 100644 --- a/AutoDL Design/inception_train/utils.py +++ b/AutoDL Design/inception_train/utils.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -# -*- encoding:utf-8 -*- +# -*- coding:utf-8 -*- # Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserve. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/AutoDL Design/main.py b/AutoDL Design/main.py index 93f802c1a1d4981b4f17420adf7d1ab49bbfbc40..19937c6e0c36f5506d8cb00c6eb28d5a848da7fa 100644 --- a/AutoDL Design/main.py +++ b/AutoDL Design/main.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -# -*- encoding:utf-8 -*- +# -*- coding:utf-8 -*- # Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserve. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/AutoDL Design/policy_model.py b/AutoDL Design/policy_model.py index e253aad577dad1bfd66bda01e96d95b3a4916905..9582516dbe4b7421f9121d47c3ad51ecd6154d1f 100644 --- a/AutoDL Design/policy_model.py +++ b/AutoDL Design/policy_model.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -# -*- encoding:utf-8 -*- +# -*- coding:utf-8 -*- # Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserve. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/AutoDL Design/reinforce_policy_gradient.py b/AutoDL Design/reinforce_policy_gradient.py index c117a67cfb65db9b1e3b5d13462d31700ac77535..1537b5cfc36da8caa231140dd3c24a62bbb4f975 100644 --- a/AutoDL Design/reinforce_policy_gradient.py +++ b/AutoDL Design/reinforce_policy_gradient.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -# -*- encoding:utf-8 -*- +# -*- coding:utf-8 -*- # Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserve. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/AutoDL Design/simple_main.py b/AutoDL Design/simple_main.py index 9b03f2c829c7b247f9cd6283e23e7a9e298228d7..1fb78f83f185c4429b1b6f64e55d498d5d0bf330 100755 --- a/AutoDL Design/simple_main.py +++ b/AutoDL Design/simple_main.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -# -*- encoding:utf-8 -*- +# -*- coding:utf-8 -*- # Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserve. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/AutoDL Design/utils.py b/AutoDL Design/utils.py index 5aeb69ffa23260dae30e10db0349ef172dac27bc..67b93526c77877d99069020070eb0ce42689011a 100644 --- a/AutoDL Design/utils.py +++ b/AutoDL Design/utils.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -# -*- encoding:utf-8 -*- +# -*- coding:utf-8 -*- # Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserve. # # Licensed under the Apache License, Version 2.0 (the "License");