未验证 提交 0f9ad827 编写于 作者: R ruri 提交者: GitHub

remove image_shape, refine code (#3951)

refine code
上级 2c4dbca7
...@@ -33,11 +33,11 @@ ...@@ -33,11 +33,11 @@
### 安装说明 ### 安装说明
在当前目录下运行样例代码需要python 2.7及以上版本,PadddlePaddle Fluid v1.6或以上的版本。如果你的运行环境中的PaddlePaddle低于此版本,请根据 [安装文档](http://paddlepaddle.org/documentation/docs/zh/1.6/beginners_guide/install/index_cn.html) 中的说明来更新PaddlePaddle。 在当前目录下运行样例代码需要python 2.7及以上版本,PadddlePaddle Fluid v1.6或以上的版本。如果你的运行环境中的PaddlePaddle低于此版本,请根据 [安装文档](https://www.paddlepaddle.org.cn/install/quick) 中的说明来更新PaddlePaddle。
#### 环境依赖 #### 环境依赖
python >= 2.7,CUDA >= 8.0,CUDNN >= 7.0 python >= 2.7
运行训练代码需要安装numpy,cv2 运行训练代码需要安装numpy,cv2
```bash ```bash
...@@ -129,7 +129,7 @@ CUDA_VISIBLE_DEVICES=0,1,2,3 python -m paddle.distributed.launch train.py \ ...@@ -129,7 +129,7 @@ CUDA_VISIBLE_DEVICES=0,1,2,3 python -m paddle.distributed.launch train.py \
* **model**: 模型名称, 默认值: "ResNet50" * **model**: 模型名称, 默认值: "ResNet50"
* **total_images**: 图片数,ImageNet2012,默认值: 1281167 * **total_images**: 图片数,ImageNet2012,默认值: 1281167
* **class_dim**: 类别数,默认值: 1000 * **class_dim**: 类别数,默认值: 1000
* **image_shape**: 图片大小,默认值: "3,224,224" * **image_shape**: 图片大小,默认值: 3 224 224
* **num_epochs**: 训练回合数,默认值: 120 * **num_epochs**: 训练回合数,默认值: 120
* **batch_size**: batch size大小(所有设备),默认值: 8 * **batch_size**: batch size大小(所有设备),默认值: 8
* **test_batch_size**: 测试batch大小,默认值:16 * **test_batch_size**: 测试batch大小,默认值:16
...@@ -147,7 +147,6 @@ CUDA_VISIBLE_DEVICES=0,1,2,3 python -m paddle.distributed.launch train.py \ ...@@ -147,7 +147,6 @@ CUDA_VISIBLE_DEVICES=0,1,2,3 python -m paddle.distributed.launch train.py \
* **lower_ratio**: 数据随机裁剪处理时的lower ratio值,默认值:3./4. * **lower_ratio**: 数据随机裁剪处理时的lower ratio值,默认值:3./4.
* **upper_ratio**: 数据随机裁剪处理时的upper ratio值,默认值:4./3. * **upper_ratio**: 数据随机裁剪处理时的upper ratio值,默认值:4./3.
* **resize_short_size**: 指定数据处理时改变图像大小的短边值,默认值: 256 * **resize_short_size**: 指定数据处理时改变图像大小的短边值,默认值: 256
* **crop_size**: 指定裁剪的大小,默认值:224
* **use_mixup**: 是否对数据进行mixup处理,默认值: False * **use_mixup**: 是否对数据进行mixup处理,默认值: False
* **mixup_alpha**: 指定mixup处理时的alpha值,默认值: 0.2 * **mixup_alpha**: 指定mixup处理时的alpha值,默认值: 0.2
* **use_aa**: 是否对数据进行auto augment处理. 默认值: False. * **use_aa**: 是否对数据进行auto augment处理. 默认值: False.
...@@ -298,20 +297,120 @@ PaddlePaddle/Models ImageClassification 支持自定义数据 ...@@ -298,20 +297,120 @@ PaddlePaddle/Models ImageClassification 支持自定义数据
表格中列出了在models目录下目前支持的图像分类模型,并且给出了已完成训练的模型在ImageNet-2012验证集合上的top-1和top-5精度,以及Paddle Fluid和Paddle TensorRT基于动态链接库的预测时间(测试GPU型号为NVIDIA® Tesla® P4)。 表格中列出了在models目录下目前支持的图像分类模型,并且给出了已完成训练的模型在ImageNet-2012验证集合上的top-1和top-5精度,以及Paddle Fluid和Paddle TensorRT基于动态链接库的预测时间(测试GPU型号为NVIDIA® Tesla® P4)。
可以通过点击相应模型的名称下载对应的预训练模型。 可以通过点击相应模型的名称下载对应的预训练模型。
- 注意 #### 注意事项
- 1:ResNet50_vd_v2是ResNet50_vd蒸馏版本。
- 2:除EfficientNet外,InceptionV4和Xception采用的输入图像的分辨率为299x299,DarkNet53为256x256,Fix_ResNeXt101_32x48d_wsl为320x320,其余模型使用的分辨率均为224x224。在预测时,DarkNet53与Fix_ResNeXt101_32x48d_wsl系列网络resize_short_size与输入的图像分辨率的宽或高相同,InceptionV4和Xception网络resize_short_size为320,其余网络resize_short_size均为256。
- 3: EfficientNetB0~B7的分辨率大小分别为224x224,240x240,260x260,300x300,380x380,456x456,528x528,600x600,预测时的resize_short_size在其分辨率的长或高的基础上加32,如EfficientNetB1的resize_short_size为272,在该系列模型训练和预测的过程中,图片resize参数interpolation的值设置为2(cubic插值方式),该模型在训练过程中使用了指数滑动平均策略,具体请参考[指数滑动平均](https://www.paddlepaddle.org.cn/documentation/docs/zh/1.5/api_cn/optimizer_cn.html#exponentialmovingaverage)
- 4:调用动态链接库预测时需要将训练模型转换为二进制模型。
```bash
python infer.py \
--model=model_name \
--pretrained_model=${path_to_pretrain_model} \
--save_inference=True
```
- 5: ResNeXt101_wsl系列的预训练模型转自pytorch模型,详情见[ResNeXt wsl](https://pytorch.org/hub/facebookresearch_WSL-Images_resnext/) - 特殊参数配置
<table>
<tr>
<td><b>Model</b>
</td>
<td><b>输入图像分辨率</b>
</td>
<td><b>参数 resize_short_size</b>
</td>
</tr>
<tr>
<td>Inception, Xception
</td>
<td>299
</td>
<td>320
</td>
</tr>
<tr>
<td> DarkNet53
</td>
<td>256
</td>
<td>256
</td>
</tr>
<tr>
<td>Fix_ResNeXt101_32x48d_wsl
</td>
<td>320
</td>
<td>320
</td>
</tr>
<tr>
<td rowspan="8"> EfficientNet: <br/><br/>
预测时的resize_short_size在其分辨率的长或高的基础上加32<br/>
在该系列模型训练和预测的过程中<br/>
图片resize参数interpolation的值设置为2(cubic插值方式)<br/>
该模型在训练过程中使用了指数滑动平均策略<br/>
具体请参考<a href="https://www.paddlepaddle.org.cn/documentation/docs/zh/1.5/api_cn/optimizer_cn.html#exponentialmovingaverage">指数滑动平均</a>
</td>
<td>B0: 224
</td>
<td>256
</td>
</tr>
<tr>
<td>B1: 240
</td>
<td>272
</td>
</tr>
<tr>
<td>B2: 260
</td>
<td>292
</td>
</tr>
<tr>
<td>B3: 300
</td>
<td>332
</td>
</tr>
<tr>
<td>B4: 380
</td>
<td>412
</td>
</tr>
<tr>
<td>B5: 456
</td>
<td>488
</td>
</tr>
<tr>
<td>B6: 528
</td>
<td>560
</td>
</tr>
<tr>
<td>B7: 600
</td>
<td>632
</td>
</tr>
<tr>
<td>其余分类模型
</td>
<td>224
</td>
<td>256
</td>
</tr>
</table>
- 调用动态链接库预测时需要将训练模型转换为二进制模型。
```bash
python infer.py \
--model=model_name \
--pretrained_model=${path_to_pretrain_model} \
--save_inference=True
```
- ResNeXt101_wsl系列的预训练模型转自pytorch模型,详情见[ResNeXt wsl](https://pytorch.org/hub/facebookresearch_WSL-Images_resnext/)
### AlexNet ### AlexNet
......
...@@ -34,7 +34,7 @@ We also recommend users to take a look at the  [IPython Notebook demo](https:/ ...@@ -34,7 +34,7 @@ We also recommend users to take a look at the  [IPython Notebook demo](https:/
### Installation ### Installation
Running samples in this directory requires Python 2.7 and later, CUDA 8.0 and later, CUDNN 7.0 and later, python package: numpy and opencv-python, PaddelPaddle Fluid v1.6 and later, the latest release version is recommended, If the PaddlePaddle on your device is lower than v1.6, please follow the instructions in [installation document](http://paddlepaddle.org/documentation/docs/zh/1.6/beginners_guide/install/index_cn.html) and make an update. Running samples in this directory requires Python 2.7 and later, CUDA 8.0 and later, CUDNN 7.0 and later, python package: numpy and opencv-python, PaddelPaddle Fluid v1.6 and later, the latest release version is recommended, If the PaddlePaddle on your device is lower than v1.6, please follow the instructions in [installation document](https://www.paddlepaddle.org.cn/install/quick) and make an update.
### Data preparation ### Data preparation
...@@ -122,7 +122,7 @@ Solver and hyperparameters: ...@@ -122,7 +122,7 @@ Solver and hyperparameters:
* **model**: name model to use. Default: "ResNet50". * **model**: name model to use. Default: "ResNet50".
* **total_images**: total number of images in the training set. Default: 1281167. * **total_images**: total number of images in the training set. Default: 1281167.
* **class_dim**: the class number of the classification task. Default: 1000. * **class_dim**: the class number of the classification task. Default: 1000.
* **image_shape**: input size of the network. Default: "3,224,224". * **image_shape**: input size of the network. Default: 3 224 224 .
* **num_epochs**: the number of epochs. Default: 120. * **num_epochs**: the number of epochs. Default: 120.
* **batch_size**: the batch size of all devices. Default: 8. * **batch_size**: the batch size of all devices. Default: 8.
* **test_batch_size**: the test batch size, Default: 16 * **test_batch_size**: the test batch size, Default: 16
...@@ -140,7 +140,6 @@ Reader and preprocess: ...@@ -140,7 +140,6 @@ Reader and preprocess:
* **lower_ratio**: the lower ratio in ramdom crop. Default:3./4. . * **lower_ratio**: the lower ratio in ramdom crop. Default:3./4. .
* **upper_ration**: the upper ratio in ramdom crop. Default:4./3. . * **upper_ration**: the upper ratio in ramdom crop. Default:4./3. .
* **resize_short_size**: the resize_short_size. Default: 256. * **resize_short_size**: the resize_short_size. Default: 256.
* **crop_size**: the crop size, Default: 224.
* **use_mixup**: whether to use mixup data processing or not. Default:False. * **use_mixup**: whether to use mixup data processing or not. Default:False.
* **mixup_alpha**: the mixup_alpha parameter. Default: 0.2. * **mixup_alpha**: the mixup_alpha parameter. Default: 0.2.
* **use_aa**: whether to use auto augment data processing or not. Default:False. * **use_aa**: whether to use auto augment data processing or not. Default:False.
...@@ -290,18 +289,118 @@ with GCC 5.4 and up. ...@@ -290,18 +289,118 @@ with GCC 5.4 and up.
The image classification models currently supported by PaddlePaddle are listed in the table. It shows the top-1/top-5 accuracy on the ImageNet-2012 validation set of these models, the inference time of Paddle Fluid and Paddle TensorRT based on dynamic link library(test GPU model: Tesla P4). The image classification models currently supported by PaddlePaddle are listed in the table. It shows the top-1/top-5 accuracy on the ImageNet-2012 validation set of these models, the inference time of Paddle Fluid and Paddle TensorRT based on dynamic link library(test GPU model: Tesla P4).
Pretrained models can be downloaded by clicking related model names. Pretrained models can be downloaded by clicking related model names.
- Note #### Note
- 1: ResNet50_vd_v2 is the distilled version of ResNet50_vd.
- 2: In addition to EfficientNet, the image resolution feeded in InceptionV4 and Xception net is ```299x299```, Fix_ResNeXt101_32x48d_wsl is ```320x320```, DarkNet is ```256x256```, others are ```224x224```.In test time, the resize_short_size of the DarkNet53 and Fix_ResNeXt101_32x48d_wsl series networks is the same as the width or height of the input image resolution, the InceptionV4 and Xception network resize_short_size is 320, and the other networks resize_short_size are 256. - Some special settings
- 3: The resolutions of EfficientNetB0~B7 are ```224x224```,```240x240```,```260x260```,```300x300```,```380x380```,```456x456```,```528x528```,```600x600``` respectively, the resize_short_size in the inference phase is increased by 32 on the basis of the length or height of the resolution, for example, the resize_short_size of EfficientNetB1 is 272.In the process of training and inference phase of these series of models, the value of the resize parameter interpolation is set to 2 (cubic interpolation mode). Besides, the model uses ExponentialMovingAverage during the training process, this trick please refer to [ExponentialMovingAverage](https://www.paddlepaddle.org.cn/documentation/docs/en/1.5/api/optimizer.html#exponentialmovingaverage).
- 4: It's necessary to convert the train model to a binary model when appling dynamic link library to infer, One can do it by running following command: <table>
```bash <tr>
python infer.py\ <td><b>Model</b>
--model=model_name \ </td>
--pretrained_model=${path_to_pretrained_model} \ <td><b>Resolution</b>
--save_inference=True </td>
``` <td><b>Parameter: resize_short_size</b>
- 5: The pretrained model of the ResNeXt101_wsl series network is converted from the pytorch model. Please refer to [RESNEXT WSL](https://pytorch.org/hub/facebookresearch_WSL-Images_resnext/) for details. </td>
</tr>
<tr>
<td>Inception, Xception
</td>
<td>299
</td>
<td>320
</td>
</tr>
<tr>
<td> DarkNet53
</td>
<td>256
</td>
<td>256
</td>
</tr>
<tr>
<td>Fix_ResNeXt101_32x48d_wsl
</td>
<td>320
</td>
<td>320
</td>
</tr>
<tr>
<td rowspan="8"> EfficientNet: <br/><br/>
In the inference phase, the resize_short_size increases 32 compared to the resolution <br/>
and using the 2nd interpolation(cubic interpolation mode). <br/>
The ExponentialMovingAverage method is also applied during the training process <br/>
Please refer to <a href="https://www.paddlepaddle.org.cn/documentation/docs/zh/1.5/api_cn/optimizer_cn.html#exponentialmovingaverage">ExponentialMovingAverage</a>
</td>
<td>B0: 224
</td>
<td>256
</td>
</tr>
<tr>
<td>B1: 240
</td>
<td>272
</td>
</tr>
<tr>
<td>B2: 260
</td>
<td>292
</td>
</tr>
<tr>
<td>B3: 300
</td>
<td>332
</td>
</tr>
<tr>
<td>B4: 380
</td>
<td>412
</td>
</tr>
<tr>
<td>B5: 456
</td>
<td>488
</td>
</tr>
<tr>
<td>B6: 528
</td>
<td>560
</td>
</tr>
<tr>
<td>B7: 600
</td>
<td>632
</td>
</tr>
<tr>
<td>Other models
</td>
<td>224
</td>
<td>256
</td>
</tr>
</table>
- It's necessary to convert the train model to a binary model when appling dynamic link library to infer, One can do it by running following command:
```bash
python infer.py\
--model=model_name \
--pretrained_model=${path_to_pretrained_model} \
--save_inference=True
```
- The pretrained model of the ResNeXt101_wsl series network is converted from the pytorch model. Please refer to [RESNEXT WSL](https://pytorch.org/hub/facebookresearch_WSL-Images_resnext/) for details.
### AlexNet ### AlexNet
|Model | Top-1 | Top-5 | Paddle Fluid inference time(ms) | Paddle TensorRT inference time(ms) | |Model | Top-1 | Top-5 | Paddle Fluid inference time(ms) | Paddle TensorRT inference time(ms) |
......
...@@ -37,7 +37,6 @@ add_arg('data_dir', str, "./data/ILSVRC2012/", "The ImageNet datset") ...@@ -37,7 +37,6 @@ add_arg('data_dir', str, "./data/ILSVRC2012/", "The ImageNet datset")
add_arg('batch_size', int, 256, "Minibatch size.") add_arg('batch_size', int, 256, "Minibatch size.")
add_arg('use_gpu', bool, True, "Whether to use GPU or not.") add_arg('use_gpu', bool, True, "Whether to use GPU or not.")
add_arg('class_dim', int, 1000, "Class number.") add_arg('class_dim', int, 1000, "Class number.")
add_arg('image_shape', str, "3,224,224", "Input image size")
parser.add_argument("--pretrained_model", default=None, required=True, type=str, help="The path to load pretrained model") parser.add_argument("--pretrained_model", default=None, required=True, type=str, help="The path to load pretrained model")
add_arg('model', str, "ResNet50", "Set the network to use.") add_arg('model', str, "ResNet50", "Set the network to use.")
add_arg('resize_short_size', int, 256, "Set resize short size") add_arg('resize_short_size', int, 256, "Set resize short size")
...@@ -45,7 +44,7 @@ add_arg('reader_thread', int, 8, "The number of multi thr ...@@ -45,7 +44,7 @@ add_arg('reader_thread', int, 8, "The number of multi thr
add_arg('reader_buf_size', int, 2048, "The buf size of multi thread reader") add_arg('reader_buf_size', int, 2048, "The buf size of multi thread reader")
parser.add_argument('--image_mean', nargs='+', type=float, default=[0.485, 0.456, 0.406], help="The mean of input image data") parser.add_argument('--image_mean', nargs='+', type=float, default=[0.485, 0.456, 0.406], help="The mean of input image data")
parser.add_argument('--image_std', nargs='+', type=float, default=[0.229, 0.224, 0.225], help="The std of input image data") parser.add_argument('--image_std', nargs='+', type=float, default=[0.229, 0.224, 0.225], help="The std of input image data")
add_arg('crop_size', int, 224, "The value of crop size") parser.add_argument('--image_shape', nargs="+", type=int, default=[3,224,224], help=" The shape of image")
add_arg('interpolation', int, None, "The interpolation mode") add_arg('interpolation', int, None, "The interpolation mode")
add_arg('padding_type', str, "SAME", "Padding type of convolution") add_arg('padding_type', str, "SAME", "Padding type of convolution")
add_arg('use_se', bool, True, "Whether to use Squeeze-and-Excitation module for EfficientNet.") add_arg('use_se', bool, True, "Whether to use Squeeze-and-Excitation module for EfficientNet.")
...@@ -53,7 +52,7 @@ add_arg('use_se', bool, True, "Whether to use Squeeze- ...@@ -53,7 +52,7 @@ add_arg('use_se', bool, True, "Whether to use Squeeze-
def eval(args): def eval(args):
image_shape = [int(m) for m in args.image_shape.split(",")] image_shape = args.image_shape
model_list = [m for m in dir(models) if "__" not in m] model_list = [m for m in dir(models) if "__" not in m]
assert args.model in model_list, "{} is not in lists: {}".format(args.model, assert args.model in model_list, "{} is not in lists: {}".format(args.model,
......
...@@ -36,7 +36,6 @@ add_arg = functools.partial(add_arguments, argparser=parser) ...@@ -36,7 +36,6 @@ add_arg = functools.partial(add_arguments, argparser=parser)
add_arg('data_dir', str, "./data/ILSVRC2012/", "The ImageNet data") add_arg('data_dir', str, "./data/ILSVRC2012/", "The ImageNet data")
add_arg('use_gpu', bool, True, "Whether to use GPU or not.") add_arg('use_gpu', bool, True, "Whether to use GPU or not.")
add_arg('class_dim', int, 1000, "Class number.") add_arg('class_dim', int, 1000, "Class number.")
add_arg('image_shape', str, "3,224,224", "Input image size")
parser.add_argument("--pretrained_model", default=None, required=True, type=str, help="The path to load pretrained model") parser.add_argument("--pretrained_model", default=None, required=True, type=str, help="The path to load pretrained model")
add_arg('model', str, "ResNet50", "Set the network to use.") add_arg('model', str, "ResNet50", "Set the network to use.")
add_arg('save_inference', bool, False, "Whether to save inference model or not") add_arg('save_inference', bool, False, "Whether to save inference model or not")
...@@ -45,7 +44,7 @@ add_arg('reader_thread', int, 1, "The number of multi thr ...@@ -45,7 +44,7 @@ add_arg('reader_thread', int, 1, "The number of multi thr
add_arg('reader_buf_size', int, 2048, "The buf size of multi thread reader") add_arg('reader_buf_size', int, 2048, "The buf size of multi thread reader")
parser.add_argument('--image_mean', nargs='+', type=float, default=[0.485, 0.456, 0.406], help="The mean of input image data") parser.add_argument('--image_mean', nargs='+', type=float, default=[0.485, 0.456, 0.406], help="The mean of input image data")
parser.add_argument('--image_std', nargs='+', type=float, default=[0.229, 0.224, 0.225], help="The std of input image data") parser.add_argument('--image_std', nargs='+', type=float, default=[0.229, 0.224, 0.225], help="The std of input image data")
add_arg('crop_size', int, 224, "The value of crop size") parser.add_argument('--image_shape', nargs='+', type=int, default=[3, 224, 224], help="the shape of image")
add_arg('topk', int, 1, "topk") add_arg('topk', int, 1, "topk")
add_arg('label_path', str, "./utils/tools/readable_label.txt", "readable label filepath") add_arg('label_path', str, "./utils/tools/readable_label.txt", "readable label filepath")
add_arg('interpolation', int, None, "The interpolation mode") add_arg('interpolation', int, None, "The interpolation mode")
...@@ -55,7 +54,7 @@ add_arg('use_se', bool, True, "Whether to use Squeeze- ...@@ -55,7 +54,7 @@ add_arg('use_se', bool, True, "Whether to use Squeeze-
def infer(args): def infer(args):
image_shape = [int(m) for m in args.image_shape.split(",")] image_shape = args.image_shape
model_list = [m for m in dir(models) if "__" not in m] model_list = [m for m in dir(models) if "__" not in m]
assert args.model in model_list, "{} is not in lists: {}".format(args.model, assert args.model in model_list, "{} is not in lists: {}".format(args.model,
model_list) model_list)
......
...@@ -195,12 +195,13 @@ def create_mixup_reader(settings, rd): ...@@ -195,12 +195,13 @@ def create_mixup_reader(settings, rd):
return mixup_reader return mixup_reader
def process_image(sample, settings, mode, color_jitter, rotate): def process_image(sample, settings, mode, color_jitter, rotate):
""" process_image """ """ process_image """
mean = settings.image_mean mean = settings.image_mean
std = settings.image_std std = settings.image_std
crop_size = settings.crop_size crop_size = settings.image_shape[1]
img_path = sample[0] img_path = sample[0]
img = cv2.imread(img_path) img = cv2.imread(img_path)
...@@ -209,7 +210,8 @@ def process_image(sample, settings, mode, color_jitter, rotate): ...@@ -209,7 +210,8 @@ def process_image(sample, settings, mode, color_jitter, rotate):
if rotate: if rotate:
img = rotate_image(img) img = rotate_image(img)
if crop_size > 0: if crop_size > 0:
img = random_crop(img, crop_size, settings, interpolation=settings.interpolation) img = random_crop(
img, crop_size, settings, interpolation=settings.interpolation)
if color_jitter: if color_jitter:
img = distort_color(img) img = distort_color(img)
if np.random.randint(0, 2) == 1: if np.random.randint(0, 2) == 1:
...@@ -217,7 +219,8 @@ def process_image(sample, settings, mode, color_jitter, rotate): ...@@ -217,7 +219,8 @@ def process_image(sample, settings, mode, color_jitter, rotate):
else: else:
if crop_size > 0: if crop_size > 0:
target_size = settings.resize_short_size target_size = settings.resize_short_size
img = resize_short(img, target_size, interpolation=settings.interpolation) img = resize_short(
img, target_size, interpolation=settings.interpolation)
img = crop_image(img, target_size=crop_size, center=True) img = crop_image(img, target_size=crop_size, center=True)
img = img[:, :, ::-1] img = img[:, :, ::-1]
...@@ -239,6 +242,7 @@ def process_image(sample, settings, mode, color_jitter, rotate): ...@@ -239,6 +242,7 @@ def process_image(sample, settings, mode, color_jitter, rotate):
elif mode == 'test': elif mode == 'test':
return (img, ) return (img, )
def process_batch_data(input_data, settings, mode, color_jitter, rotate): def process_batch_data(input_data, settings, mode, color_jitter, rotate):
batch_data = [] batch_data = []
for sample in input_data: for sample in input_data:
...@@ -249,6 +253,7 @@ def process_batch_data(input_data, settings, mode, color_jitter, rotate): ...@@ -249,6 +253,7 @@ def process_batch_data(input_data, settings, mode, color_jitter, rotate):
print("File not exist : %s" % sample[0]) print("File not exist : %s" % sample[0])
return batch_data return batch_data
class ImageNetReader: class ImageNetReader:
def __init__(self, seed=None): def __init__(self, seed=None):
self.shuffle_seed = seed self.shuffle_seed = seed
...@@ -257,7 +262,8 @@ class ImageNetReader: ...@@ -257,7 +262,8 @@ class ImageNetReader:
assert isinstance(seed, int), "shuffle seed must be int" assert isinstance(seed, int), "shuffle seed must be int"
self.shuffle_seed = seed self.shuffle_seed = seed
def _reader_creator(self, settings, def _reader_creator(self,
settings,
file_list, file_list,
mode, mode,
shuffle=False, shuffle=False,
...@@ -268,7 +274,13 @@ class ImageNetReader: ...@@ -268,7 +274,13 @@ class ImageNetReader:
if mode == 'test': if mode == 'test':
batch_size = 1 batch_size = 1
else: else:
batch_size = settings.batch_size / paddle.fluid.core.get_cuda_device_count() if settings.use_gpu:
batch_size = settings.batch_size // paddle.fluid.core.get_cuda_device_count(
)
else:
batch_size = settings.batch_size // int(
os.environ.get('CPU_NUM', 1))
def reader(): def reader():
def read_file_list(): def read_file_list():
with open(file_list) as flist: with open(file_list) as flist:
...@@ -280,7 +292,8 @@ class ImageNetReader: ...@@ -280,7 +292,8 @@ class ImageNetReader:
os._exit(1) os._exit(1)
if num_trainers > 1 and mode == "train": if num_trainers > 1 and mode == "train":
assert self.shuffle_seed is not None, "multiprocess train, shuffle seed must be set!" assert self.shuffle_seed is not None, "multiprocess train, shuffle seed must be set!"
np.random.RandomState(self.shuffle_seed).shuffle(full_lines) np.random.RandomState(self.shuffle_seed).shuffle(
full_lines)
elif shuffle: elif shuffle:
np.random.shuffle(full_lines) np.random.shuffle(full_lines)
...@@ -303,7 +316,8 @@ class ImageNetReader: ...@@ -303,7 +316,8 @@ class ImageNetReader:
"If num_trainers > 1, the shuffle_seed must be set, because " \ "If num_trainers > 1, the shuffle_seed must be set, because " \
"the order of batch data generated by reader " \ "the order of batch data generated by reader " \
"must be the same in the respective processes." "must be the same in the respective processes."
data_reader = paddle.fluid.contrib.reader.distributed_batch_reader(data_reader) data_reader = paddle.fluid.contrib.reader.distributed_batch_reader(
data_reader)
mapper = functools.partial( mapper = functools.partial(
process_batch_data, process_batch_data,
...@@ -319,7 +333,6 @@ class ImageNetReader: ...@@ -319,7 +333,6 @@ class ImageNetReader:
settings.reader_buf_size, settings.reader_buf_size,
order=False) order=False)
def train(self, settings): def train(self, settings):
"""Create a reader for trainning """Create a reader for trainning
...@@ -351,11 +364,11 @@ class ImageNetReader: ...@@ -351,11 +364,11 @@ class ImageNetReader:
reader = create_mixup_reader(settings, reader) reader = create_mixup_reader(settings, reader)
reader = fluid.io.batch( reader = fluid.io.batch(
reader, reader,
batch_size=int(settings.batch_size / paddle.fluid.core.get_cuda_device_count()), batch_size=int(settings.batch_size /
paddle.fluid.core.get_cuda_device_count()),
drop_last=True) drop_last=True)
return reader return reader
def val(self, settings): def val(self, settings):
"""Create a reader for eval """Create a reader for eval
...@@ -372,8 +385,11 @@ class ImageNetReader: ...@@ -372,8 +385,11 @@ class ImageNetReader:
file_list) file_list)
return self._reader_creator( return self._reader_creator(
settings, file_list, 'val', shuffle=False, data_dir=settings.data_dir) settings,
file_list,
'val',
shuffle=False,
data_dir=settings.data_dir)
def test(self, settings): def test(self, settings):
"""Create a reader for testing """Create a reader for testing
...@@ -389,4 +405,8 @@ class ImageNetReader: ...@@ -389,4 +405,8 @@ class ImageNetReader:
file_list), "{} doesn't exist, please check data list path".format( file_list), "{} doesn't exist, please check data list path".format(
file_list) file_list)
return self._reader_creator( return self._reader_creator(
settings, file_list, 'test', shuffle=False, data_dir=settings.data_dir) settings,
file_list,
'test',
shuffle=False,
data_dir=settings.data_dir)
...@@ -9,9 +9,6 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98 ...@@ -9,9 +9,6 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98
python train.py \ python train.py \
--model=AlexNet \ --model=AlexNet \
--batch_size=256 \ --batch_size=256 \
--total_images=1281167 \
--class_dim=1000 \
--image_shape=3,224,224 \
--model_save_dir=output/ \ --model_save_dir=output/ \
--lr_strategy=piecewise_decay \ --lr_strategy=piecewise_decay \
--num_epochs=120 \ --num_epochs=120 \
......
...@@ -2,9 +2,6 @@ ...@@ -2,9 +2,6 @@
python train.py \ python train.py \
--model=DPN107 \ --model=DPN107 \
--batch_size=256 \ --batch_size=256 \
--total_images=1281167 \
--image_shape=3,224,224 \
--class_dim=1000 \
--lr_strategy=cosine_decay \ --lr_strategy=cosine_decay \
--lr=0.1 \ --lr=0.1 \
--num_epochs=200 \ --num_epochs=200 \
......
...@@ -2,9 +2,6 @@ ...@@ -2,9 +2,6 @@
python train.py \ python train.py \
--model=DPN131 \ --model=DPN131 \
--batch_size=256 \ --batch_size=256 \
--total_images=1281167 \
--image_shape=3,224,224 \
--class_dim=1000 \
--lr_strategy=cosine_decay \ --lr_strategy=cosine_decay \
--lr=0.1 \ --lr=0.1 \
--num_epochs=200 \ --num_epochs=200 \
......
...@@ -2,9 +2,6 @@ ...@@ -2,9 +2,6 @@
python train.py \ python train.py \
--model=DPN68 \ --model=DPN68 \
--batch_size=256 \ --batch_size=256 \
--total_images=1281167 \
--image_shape=3,224,224 \
--class_dim=1000 \
--lr_strategy=cosine_decay \ --lr_strategy=cosine_decay \
--lr=0.1 \ --lr=0.1 \
--num_epochs=200 \ --num_epochs=200 \
......
...@@ -2,9 +2,6 @@ ...@@ -2,9 +2,6 @@
python train.py \ python train.py \
--model=DPN92 \ --model=DPN92 \
--batch_size=256 \ --batch_size=256 \
--total_images=1281167 \
--image_shape=3,224,224 \
--class_dim=1000 \
--lr_strategy=cosine_decay \ --lr_strategy=cosine_decay \
--lr=0.1 \ --lr=0.1 \
--num_epochs=200 \ --num_epochs=200 \
......
...@@ -2,9 +2,6 @@ ...@@ -2,9 +2,6 @@
python train.py \ python train.py \
--model=DPN98 \ --model=DPN98 \
--batch_size=256 \ --batch_size=256 \
--total_images=1281167 \
--image_shape=3,224,224 \
--class_dim=1000 \
--lr_strategy=cosine_decay \ --lr_strategy=cosine_decay \
--lr=0.1 \ --lr=0.1 \
--num_epochs=200 \ --num_epochs=200 \
......
...@@ -3,9 +3,7 @@ ...@@ -3,9 +3,7 @@
python train.py \ python train.py \
--model=DarkNet53 \ --model=DarkNet53 \
--batch_size=256 \ --batch_size=256 \
--total_images=1281167 \ --image_shape=3 256 256 \
--image_shape=3,256,256 \
--class_dim=1000 \
--lr_strategy=cosine_decay \ --lr_strategy=cosine_decay \
--lr=0.1 \ --lr=0.1 \
--num_epochs=200 \ --num_epochs=200 \
......
...@@ -3,9 +3,6 @@ ...@@ -3,9 +3,6 @@
python train.py \ python train.py \
--model=DenseNet121 \ --model=DenseNet121 \
--batch_size=256 \ --batch_size=256 \
--total_images=1281167 \
--image_shape=3,224,224 \
--class_dim=1000 \
--lr_strategy=piecewise_decay \ --lr_strategy=piecewise_decay \
--lr=0.1 \ --lr=0.1 \
--num_epochs=120 \ --num_epochs=120 \
......
...@@ -3,9 +3,6 @@ ...@@ -3,9 +3,6 @@
python train.py \ python train.py \
--model=DenseNet161 \ --model=DenseNet161 \
--batch_size=256 \ --batch_size=256 \
--total_images=1281167 \
--image_shape=3,224,224 \
--class_dim=1000 \
--lr_strategy=piecewise_decay \ --lr_strategy=piecewise_decay \
--lr=0.1 \ --lr=0.1 \
--num_epochs=120 \ --num_epochs=120 \
......
...@@ -3,9 +3,6 @@ ...@@ -3,9 +3,6 @@
python train.py \ python train.py \
--model=DenseNet169 \ --model=DenseNet169 \
--batch_size=256 \ --batch_size=256 \
--total_images=1281167 \
--image_shape=3,224,224 \
--class_dim=1000 \
--lr_strategy=piecewise_decay \ --lr_strategy=piecewise_decay \
--lr=0.1 \ --lr=0.1 \
--num_epochs=120 \ --num_epochs=120 \
......
...@@ -3,9 +3,6 @@ ...@@ -3,9 +3,6 @@
python train.py \ python train.py \
--model=DenseNet201 \ --model=DenseNet201 \
--batch_size=256 \ --batch_size=256 \
--total_images=1281167 \
--image_shape=3,224,224 \
--class_dim=1000 \
--lr_strategy=piecewise_decay \ --lr_strategy=piecewise_decay \
--lr=0.1 \ --lr=0.1 \
--num_epochs=120 \ --num_epochs=120 \
......
...@@ -3,9 +3,6 @@ ...@@ -3,9 +3,6 @@
python train.py \ python train.py \
--model=DenseNet264 \ --model=DenseNet264 \
--batch_size=256 \ --batch_size=256 \
--total_images=1281167 \
--image_shape=3,224,224 \
--class_dim=1000 \
--lr_strategy=piecewise_decay \ --lr_strategy=piecewise_decay \
--lr=0.1 \ --lr=0.1 \
--num_epochs=120 \ --num_epochs=120 \
......
...@@ -8,9 +8,6 @@ python -u train.py \ ...@@ -8,9 +8,6 @@ python -u train.py \
--model=EfficientNet \ --model=EfficientNet \
--batch_size=512 \ --batch_size=512 \
--test_batch_size=128 \ --test_batch_size=128 \
--total_images=1281167 \
--class_dim=1000 \
--image_shape=3,224,224 \
--resize_short_size=256 \ --resize_short_size=256 \
--model_save_dir=output/ \ --model_save_dir=output/ \
--lr_strategy=exponential_decay_warmup \ --lr_strategy=exponential_decay_warmup \
......
...@@ -9,9 +9,6 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98 ...@@ -9,9 +9,6 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98
python train.py \ python train.py \
--model=GoogLeNet \ --model=GoogLeNet \
--batch_size=256 \ --batch_size=256 \
--total_images=1281167 \
--class_dim=1000 \
--image_shape=3,224,224 \
--model_save_dir=output/ \ --model_save_dir=output/ \
--lr_strategy=cosine_decay \ --lr_strategy=cosine_decay \
--lr=0.01 \ --lr=0.01 \
......
...@@ -9,9 +9,7 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98 ...@@ -9,9 +9,7 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98
python train.py \ python train.py \
--model=InceptionV4 \ --model=InceptionV4 \
--batch_size=256 \ --batch_size=256 \
--total_images=1281167 \ --image_shape=3 299 299 \
--image_shape=3,299,299 \
--class_dim=1000 \
--lr_strategy=cosine_decay \ --lr_strategy=cosine_decay \
--lr=0.045 \ --lr=0.045 \
--num_epochs=200 \ --num_epochs=200 \
......
...@@ -9,9 +9,6 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98 ...@@ -9,9 +9,6 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98
python train.py \ python train.py \
--model=MobileNetV1 \ --model=MobileNetV1 \
--batch_size=256 \ --batch_size=256 \
--total_images=1281167 \
--class_dim=1000 \
--image_shape=3,224,224 \
--model_save_dir=output/ \ --model_save_dir=output/ \
--lr_strategy=piecewise_decay \ --lr_strategy=piecewise_decay \
--num_epochs=120 \ --num_epochs=120 \
......
...@@ -7,9 +7,6 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98 ...@@ -7,9 +7,6 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98
python train.py \ python train.py \
--model=MobileNetV1_x0_25 \ --model=MobileNetV1_x0_25 \
--batch_size=256 \ --batch_size=256 \
--total_images=1281167 \
--class_dim=1000 \
--image_shape=3,224,224 \
--model_save_dir=output/ \ --model_save_dir=output/ \
--lr_strategy=piecewise_decay \ --lr_strategy=piecewise_decay \
--num_epochs=120 \ --num_epochs=120 \
......
...@@ -7,9 +7,6 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98 ...@@ -7,9 +7,6 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98
python train.py \ python train.py \
--model=MobileNetV1_x0_5 \ --model=MobileNetV1_x0_5 \
--batch_size=256 \ --batch_size=256 \
--total_images=1281167 \
--class_dim=1000 \
--image_shape=3,224,224 \
--model_save_dir=output/ \ --model_save_dir=output/ \
--lr_strategy=piecewise_decay \ --lr_strategy=piecewise_decay \
--num_epochs=120 \ --num_epochs=120 \
......
...@@ -7,9 +7,6 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98 ...@@ -7,9 +7,6 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98
python train.py \ python train.py \
--model=MobileNetV1_x0_75 \ --model=MobileNetV1_x0_75 \
--batch_size=256 \ --batch_size=256 \
--total_images=1281167 \
--class_dim=1000 \
--image_shape=3,224,224 \
--model_save_dir=output/ \ --model_save_dir=output/ \
--lr_strategy=piecewise_decay \ --lr_strategy=piecewise_decay \
--num_epochs=120 \ --num_epochs=120 \
......
...@@ -9,9 +9,6 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98 ...@@ -9,9 +9,6 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98
python train.py \ python train.py \
--model=MobileNetV2 \ --model=MobileNetV2 \
--batch_size=500 \ --batch_size=500 \
--total_images=1281167 \
--class_dim=1000 \
--image_shape=3,224,224 \
--model_save_dir=output/ \ --model_save_dir=output/ \
--lr_strategy=cosine_decay \ --lr_strategy=cosine_decay \
--num_epochs=240 \ --num_epochs=240 \
......
...@@ -2,9 +2,6 @@ ...@@ -2,9 +2,6 @@
python train.py \ python train.py \
--model=MobileNetV2_x0_25 \ --model=MobileNetV2_x0_25 \
--batch_size=256 \ --batch_size=256 \
--total_images=1281167 \
--class_dim=1000 \
--image_shape=3,224,224 \
--model_save_dir=output/ \ --model_save_dir=output/ \
--lr_strategy=cosine_decay \ --lr_strategy=cosine_decay \
--num_epochs=240 \ --num_epochs=240 \
......
...@@ -2,9 +2,6 @@ ...@@ -2,9 +2,6 @@
python train.py \ python train.py \
--model=MobileNetV2_x0_5 \ --model=MobileNetV2_x0_5 \
--batch_size=256 \ --batch_size=256 \
--total_images=1281167 \
--class_dim=1000 \
--image_shape=3,224,224 \
--model_save_dir=output/ \ --model_save_dir=output/ \
--lr_strategy=cosine_decay \ --lr_strategy=cosine_decay \
--num_epochs=240 \ --num_epochs=240 \
......
...@@ -7,9 +7,6 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98 ...@@ -7,9 +7,6 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98
python train.py \ python train.py \
--model=MobileNetV2_x0_75 \ --model=MobileNetV2_x0_75 \
--batch_size=256 \ --batch_size=256 \
--total_images=1281167 \
--class_dim=1000 \
--image_shape=3,224,224 \
--model_save_dir=output/ \ --model_save_dir=output/ \
--lr_strategy=cosine_decay \ --lr_strategy=cosine_decay \
--num_epochs=240 \ --num_epochs=240 \
......
...@@ -2,9 +2,6 @@ ...@@ -2,9 +2,6 @@
python train.py \ python train.py \
--model=MobileNetV2_x1_5 \ --model=MobileNetV2_x1_5 \
--batch_size=256 \ --batch_size=256 \
--total_images=1281167 \
--class_dim=1000 \
--image_shape=3,224,224 \
--model_save_dir=output/ \ --model_save_dir=output/ \
--lr_strategy=cosine_decay \ --lr_strategy=cosine_decay \
--num_epochs=240 \ --num_epochs=240 \
......
...@@ -2,9 +2,6 @@ ...@@ -2,9 +2,6 @@
python train.py \ python train.py \
--model=MobileNetV2_x2_0 \ --model=MobileNetV2_x2_0 \
--batch_size=256 \ --batch_size=256 \
--total_images=1281167 \
--class_dim=1000 \
--image_shape=3,224,224 \
--model_save_dir=output/ \ --model_save_dir=output/ \
--lr_strategy=cosine_decay \ --lr_strategy=cosine_decay \
--num_epochs=240 \ --num_epochs=240 \
......
...@@ -9,9 +9,6 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98 ...@@ -9,9 +9,6 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98
python train.py \ python train.py \
--model=ResNeXt101_32x4d \ --model=ResNeXt101_32x4d \
--batch_size=256 \ --batch_size=256 \
--total_images=1281167 \
--image_shape=3,224,224 \
--class_dim=1000 \
--lr_strategy=piecewise_decay \ --lr_strategy=piecewise_decay \
--lr=0.1 \ --lr=0.1 \
--num_epochs=120 \ --num_epochs=120 \
......
...@@ -9,9 +9,6 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98 ...@@ -9,9 +9,6 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98
python train.py \ python train.py \
--model=ResNeXt101_64x4d \ --model=ResNeXt101_64x4d \
--batch_size=256 \ --batch_size=256 \
--total_images=1281167 \
--image_shape=3,224,224 \
--class_dim=1000 \
--lr_strategy=piecewise_decay \ --lr_strategy=piecewise_decay \
--lr=0.1 \ --lr=0.1 \
--num_epochs=120 \ --num_epochs=120 \
......
...@@ -9,9 +9,6 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98 ...@@ -9,9 +9,6 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98
python train.py \ python train.py \
--model=ResNeXt101_vd_32x4d \ --model=ResNeXt101_vd_32x4d \
--batch_size=256 \ --batch_size=256 \
--total_images=1281167 \
--image_shape=3,224,224 \
--class_dim=1000 \
--lr_strategy=cosine_decay \ --lr_strategy=cosine_decay \
--lr=0.1 \ --lr=0.1 \
--num_epochs=200 \ --num_epochs=200 \
......
...@@ -9,9 +9,6 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98 ...@@ -9,9 +9,6 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98
python train.py \ python train.py \
--model=ResNeXt101_vd_64x4d \ --model=ResNeXt101_vd_64x4d \
--batch_size=256 \ --batch_size=256 \
--total_images=1281167 \
--image_shape=3,224,224 \
--class_dim=1000 \
--lr_strategy=cosine_decay \ --lr_strategy=cosine_decay \
--lr=0.1 \ --lr=0.1 \
--num_epochs=200 \ --num_epochs=200 \
......
...@@ -2,9 +2,6 @@ ...@@ -2,9 +2,6 @@
python train.py \ python train.py \
--model=ResNeXt152_32x4d \ --model=ResNeXt152_32x4d \
--batch_size=256 \ --batch_size=256 \
--total_images=1281167 \
--image_shape=3,224,224 \
--class_dim=1000 \
--lr_strategy=piecewise_decay \ --lr_strategy=piecewise_decay \
--lr=0.1 \ --lr=0.1 \
--num_epochs=120 \ --num_epochs=120 \
......
...@@ -8,9 +8,6 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98 ...@@ -8,9 +8,6 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98
python train.py \ python train.py \
--model=ResNeXt152_64x4d \ --model=ResNeXt152_64x4d \
--batch_size=256 \ --batch_size=256 \
--total_images=1281167 \
--image_shape=3,224,224 \
--class_dim=1000 \
--lr_strategy=piecewise_decay \ --lr_strategy=piecewise_decay \
--lr=0.1 \ --lr=0.1 \
--num_epochs=120 \ --num_epochs=120 \
......
...@@ -2,9 +2,6 @@ ...@@ -2,9 +2,6 @@
python train.py \ python train.py \
--model=ResNeXt152_vd_64x4d \ --model=ResNeXt152_vd_64x4d \
--batch_size=256 \ --batch_size=256 \
--total_images=1281167 \
--image_shape=3,224,224 \
--class_dim=1000 \
--lr_strategy=cosine_decay \ --lr_strategy=cosine_decay \
--lr=0.1 \ --lr=0.1 \
--num_epochs=200 \ --num_epochs=200 \
......
python train.py \ python train.py \
--model=ResNeXt50_32x4d \ --model=ResNeXt50_32x4d \
--batch_size=256 \ --batch_size=256 \
--total_images=1281167 \
--image_shape=3,224,224 \
--class_dim=1000 \
--lr_strategy=piecewise_decay \ --lr_strategy=piecewise_decay \
--lr=0.1 \ --lr=0.1 \
--num_epochs=120 \ --num_epochs=120 \
......
...@@ -2,9 +2,6 @@ ...@@ -2,9 +2,6 @@
python train.py \ python train.py \
--model=ResNeXt50_vd_64x4d \ --model=ResNeXt50_vd_64x4d \
--batch_size=256 \ --batch_size=256 \
--total_images=1281167 \
--image_shape=3,224,224 \
--class_dim=1000 \
--lr_strategy=cosine_decay \ --lr_strategy=cosine_decay \
--lr=0.1 \ --lr=0.1 \
--num_epochs=200 \ --num_epochs=200 \
......
...@@ -9,9 +9,6 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98 ...@@ -9,9 +9,6 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98
python train.py \ python train.py \
--model=ResNet101 \ --model=ResNet101 \
--batch_size=256 \ --batch_size=256 \
--total_images=1281167 \
--class_dim=1000 \
--image_shape=3,224,224 \
--model_save_dir=output/ \ --model_save_dir=output/ \
--lr_strategy=piecewise_decay \ --lr_strategy=piecewise_decay \
--num_epochs=120 \ --num_epochs=120 \
......
...@@ -9,9 +9,6 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98 ...@@ -9,9 +9,6 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98
python train.py \ python train.py \
--model=ResNet101_vd \ --model=ResNet101_vd \
--batch_size=256 \ --batch_size=256 \
--total_images=1281167 \
--image_shape=3,224,224 \
--class_dim=1000 \
--lr_strategy=cosine_decay \ --lr_strategy=cosine_decay \
--lr=0.1 \ --lr=0.1 \
--num_epochs=200 \ --num_epochs=200 \
......
...@@ -9,9 +9,6 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98 ...@@ -9,9 +9,6 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98
python train.py \ python train.py \
--model=ResNet152 \ --model=ResNet152 \
--batch_size=256 \ --batch_size=256 \
--total_images=1281167 \
--class_dim=1000 \
--image_shape=3,224,224 \
--model_save_dir=output/ \ --model_save_dir=output/ \
--lr_strategy=piecewise_decay \ --lr_strategy=piecewise_decay \
--lr=0.1 \ --lr=0.1 \
......
...@@ -8,9 +8,6 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98 ...@@ -8,9 +8,6 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98
python train.py \ python train.py \
--model=ResNet152_vd \ --model=ResNet152_vd \
--batch_size=256 \ --batch_size=256 \
--total_images=1281167 \
--image_shape=3,224,224 \
--class_dim=1000 \
--lr_strategy=cosine_decay \ --lr_strategy=cosine_decay \
--lr=0.1 \ --lr=0.1 \
--num_epochs=200 \ --num_epochs=200 \
......
...@@ -9,9 +9,6 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98 ...@@ -9,9 +9,6 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98
python train.py \ python train.py \
--model=ResNet18 \ --model=ResNet18 \
--batch_size=256 \ --batch_size=256 \
--total_images=1281167 \
--class_dim=1000 \
--image_shape=3,224,224 \
--model_save_dir=output/ \ --model_save_dir=output/ \
--lr_strategy=cosine_decay \ --lr_strategy=cosine_decay \
--lr=0.1 \ --lr=0.1 \
......
...@@ -6,9 +6,6 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98 ...@@ -6,9 +6,6 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98
python train.py \ python train.py \
--model=ResNet18_vd \ --model=ResNet18_vd \
--batch_size=256 \ --batch_size=256 \
--total_images=1281167 \
--image_shape=3,224,224 \
--class_dim=1000 \
--lr_strategy=cosine_decay \ --lr_strategy=cosine_decay \
--lr=0.1 \ --lr=0.1 \
--num_epochs=200 \ --num_epochs=200 \
......
...@@ -9,9 +9,6 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98 ...@@ -9,9 +9,6 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98
python train.py \ python train.py \
--model=ResNet200_vd \ --model=ResNet200_vd \
--batch_size=256 \ --batch_size=256 \
--total_images=1281167 \
--image_shape=3,224,224 \
--class_dim=1000 \
--lr_strategy=cosine_decay \ --lr_strategy=cosine_decay \
--lr=0.1 \ --lr=0.1 \
--num_epochs=200 \ --num_epochs=200 \
......
...@@ -8,9 +8,6 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98 ...@@ -8,9 +8,6 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98
python train.py \ python train.py \
--model=ResNet34 \ --model=ResNet34 \
--batch_size=256 \ --batch_size=256 \
--total_images=1281167 \
--class_dim=1000 \
--image_shape=3,224,224 \
--model_save_dir=output/ \ --model_save_dir=output/ \
--lr_strategy=cosine_decay \ --lr_strategy=cosine_decay \
--lr=0.1 \ --lr=0.1 \
......
...@@ -6,9 +6,6 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98 ...@@ -6,9 +6,6 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98
python train.py \ python train.py \
--model=ResNet34_vd \ --model=ResNet34_vd \
--batch_size=256 \ --batch_size=256 \
--total_images=1281167 \
--image_shape=3,224,224 \
--class_dim=1000 \
--lr_strategy=cosine_decay \ --lr_strategy=cosine_decay \
--lr=0.1 \ --lr=0.1 \
--num_epochs=200 \ --num_epochs=200 \
......
...@@ -9,9 +9,6 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98 ...@@ -9,9 +9,6 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98
python train.py \ python train.py \
--model=ResNet50 \ --model=ResNet50 \
--batch_size=256 \ --batch_size=256 \
--total_images=1281167 \
--class_dim=1000 \
--image_shape=3,224,224 \
--model_save_dir=output/ \ --model_save_dir=output/ \
--lr_strategy=piecewise_decay \ --lr_strategy=piecewise_decay \
--num_epochs=120 \ --num_epochs=120 \
......
...@@ -8,9 +8,6 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98 ...@@ -8,9 +8,6 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98
python -m paddle.distributed.launch train.py \ python -m paddle.distributed.launch train.py \
--model=ResNet50 \ --model=ResNet50 \
--batch_size=256 \ --batch_size=256 \
--total_images=1281167 \
--class_dim=1000 \
--image_shape=3,224,224 \
--model_save_dir=output/ \ --model_save_dir=output/ \
--lr_strategy=piecewise_decay \ --lr_strategy=piecewise_decay \
--num_epochs=120 \ --num_epochs=120 \
......
...@@ -9,9 +9,6 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98 ...@@ -9,9 +9,6 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98
python train.py \ python train.py \
--model=ResNet50_vc \ --model=ResNet50_vc \
--batch_size=256 \ --batch_size=256 \
--total_images=1281167 \
--image_shape=3,224,224 \
--class_dim=1000 \
--lr_strategy=cosine_decay \ --lr_strategy=cosine_decay \
--lr=0.1 \ --lr=0.1 \
--num_epochs=200 \ --num_epochs=200 \
......
...@@ -8,9 +8,6 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98 ...@@ -8,9 +8,6 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98
python train.py \ python train.py \
--model=ResNet50_vd \ --model=ResNet50_vd \
--batch_size=256 \ --batch_size=256 \
--total_images=1281167 \
--image_shape=3,224,224 \
--class_dim=1000 \
--lr_strategy=cosine_decay \ --lr_strategy=cosine_decay \
--lr=0.1 \ --lr=0.1 \
--num_epochs=200 \ --num_epochs=200 \
......
...@@ -9,9 +9,6 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98 ...@@ -9,9 +9,6 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98
python train.py \ python train.py \
--model=SENet154_vd \ --model=SENet154_vd \
--batch_size=256 \ --batch_size=256 \
--total_images=1281167 \
--image_shape=3,224,224 \
--class_dim=1000 \
--lr_strategy=cosine_decay \ --lr_strategy=cosine_decay \
--lr=0.1 \ --lr=0.1 \
--num_epochs=200 \ --num_epochs=200 \
......
...@@ -9,9 +9,6 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98 ...@@ -9,9 +9,6 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98
python train.py \ python train.py \
--model=SE_ResNeXt101_32x4d \ --model=SE_ResNeXt101_32x4d \
--batch_size=400 \ --batch_size=400 \
--total_images=1281167 \
--class_dim=1000 \
--image_shape=3,224,224 \
--lr_strategy=cosine_decay \ --lr_strategy=cosine_decay \
--model_save_dir=output/ \ --model_save_dir=output/ \
--lr=0.1 \ --lr=0.1 \
......
...@@ -10,9 +10,6 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98 ...@@ -10,9 +10,6 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98
python train.py \ python train.py \
--model=SE_ResNeXt50_32x4d \ --model=SE_ResNeXt50_32x4d \
--batch_size=400 \ --batch_size=400 \
--total_images=1281167 \
--class_dim=1000 \
--image_shape=3,224,224 \
--lr_strategy=cosine_decay \ --lr_strategy=cosine_decay \
--model_save_dir=output/ \ --model_save_dir=output/ \
--lr=0.1 \ --lr=0.1 \
......
...@@ -2,9 +2,6 @@ ...@@ -2,9 +2,6 @@
python train.py \ python train.py \
--model=SE_ResNet50_vd \ --model=SE_ResNet50_vd \
--batch_size=256 \ --batch_size=256 \
--total_images=1281167 \
--image_shape=3,224,224 \
--class_dim=1000 \
--lr_strategy=cosine_decay \ --lr_strategy=cosine_decay \
--lr=0.1 \ --lr=0.1 \
--num_epochs=200 \ --num_epochs=200 \
......
...@@ -8,9 +8,6 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98 ...@@ -8,9 +8,6 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98
python train.py \ python train.py \
--model=ShuffleNetV2 \ --model=ShuffleNetV2 \
--batch_size=1024 \ --batch_size=1024 \
--total_images=1281167 \
--class_dim=1000 \
--image_shape=3,224,224 \
--model_save_dir=output/ \ --model_save_dir=output/ \
--lr_strategy=cosine_decay_warmup \ --lr_strategy=cosine_decay_warmup \
--lr=0.5 \ --lr=0.5 \
......
...@@ -8,9 +8,6 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98 ...@@ -8,9 +8,6 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98
python train.py \ python train.py \
--model=ShuffleNetV2_swish \ --model=ShuffleNetV2_swish \
--batch_size=1024 \ --batch_size=1024 \
--total_images=1281167 \
--class_dim=1000 \
--image_shape=3,224,224 \
--model_save_dir=output/ \ --model_save_dir=output/ \
--lr_strategy=cosine_decay_warmup \ --lr_strategy=cosine_decay_warmup \
--lr=0.5 \ --lr=0.5 \
......
...@@ -2,9 +2,6 @@ ...@@ -2,9 +2,6 @@
python train.py \ python train.py \
--model=ShuffleNetV2_x0_25 \ --model=ShuffleNetV2_x0_25 \
--batch_size=1024 \ --batch_size=1024 \
--total_images=1281167 \
--class_dim=1000 \
--image_shape=3,224,224 \
--model_save_dir=output/ \ --model_save_dir=output/ \
--lr_strategy=cosine_decay_warmup \ --lr_strategy=cosine_decay_warmup \
--num_epochs=240 \ --num_epochs=240 \
......
...@@ -2,9 +2,6 @@ ...@@ -2,9 +2,6 @@
python train.py \ python train.py \
--model=ShuffleNetV2_x0_33 \ --model=ShuffleNetV2_x0_33 \
--batch_size=1024 \ --batch_size=1024 \
--total_images=1281167 \
--class_dim=1000 \
--image_shape=3,224,224 \
--model_save_dir=output/ \ --model_save_dir=output/ \
--lr_strategy=cosine_decay_warmup \ --lr_strategy=cosine_decay_warmup \
--num_epochs=240 \ --num_epochs=240 \
......
...@@ -2,9 +2,6 @@ ...@@ -2,9 +2,6 @@
python train.py \ python train.py \
--model=ShuffleNetV2_x0_5 \ --model=ShuffleNetV2_x0_5 \
--batch_size=1024 \ --batch_size=1024 \
--total_images=1281167 \
--class_dim=1000 \
--image_shape=3,224,224 \
--model_save_dir=output/ \ --model_save_dir=output/ \
--lr_strategy=cosine_decay_warmup \ --lr_strategy=cosine_decay_warmup \
--num_epochs=240 \ --num_epochs=240 \
......
python train.py \ python train.py \
--model=ShuffleNetV2_x1_5 \ --model=ShuffleNetV2_x1_5 \
--batch_size=512 \ --batch_size=512 \
--total_images=1281167 \
--class_dim=1000 \
--image_shape=3,224,224 \
--model_save_dir=output/ \ --model_save_dir=output/ \
--lr_strategy=cosine_decay_warmup \ --lr_strategy=cosine_decay_warmup \
--num_epochs=240 \ --num_epochs=240 \
......
...@@ -2,9 +2,6 @@ ...@@ -2,9 +2,6 @@
python train.py \ python train.py \
--model=ShuffleNetV2_x2_0 \ --model=ShuffleNetV2_x2_0 \
--batch_size=512 \ --batch_size=512 \
--total_images=1281167 \
--class_dim=1000 \
--image_shape=3,224,224 \
--model_save_dir=output/ \ --model_save_dir=output/ \
--lr_strategy=cosine_decay_warmup \ --lr_strategy=cosine_decay_warmup \
--num_epochs=240 \ --num_epochs=240 \
......
...@@ -2,10 +2,7 @@ ...@@ -2,10 +2,7 @@
python train.py \ python train.py \
--model=SqueezeNet1_0 \ --model=SqueezeNet1_0 \
--batch_size=256 \ --batch_size=256 \
--total_images=1281167 \
--image_shape=3,224,224 \
--lr_strategy=cosine_decay \ --lr_strategy=cosine_decay \
--class_dim=1000 \
--model_save_dir=output/ \ --model_save_dir=output/ \
--lr=0.02 \ --lr=0.02 \
--num_epochs=120 \ --num_epochs=120 \
......
...@@ -2,10 +2,7 @@ ...@@ -2,10 +2,7 @@
python train.py \ python train.py \
--model=SqueezeNet1_1 \ --model=SqueezeNet1_1 \
--batch_size=256 \ --batch_size=256 \
--total_images=1281167 \
--image_shape=3,224,224 \
--lr_strategy=cosine_decay \ --lr_strategy=cosine_decay \
--class_dim=1000 \
--model_save_dir=output/ \ --model_save_dir=output/ \
--lr=0.02 \ --lr=0.02 \
--num_epochs=120 \ --num_epochs=120 \
......
...@@ -9,10 +9,7 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98 ...@@ -9,10 +9,7 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98
python train.py \ python train.py \
--model=VGG11 \ --model=VGG11 \
--batch_size=512 \ --batch_size=512 \
--total_images=1281167 \
--image_shape=3,224,224 \
--lr_strategy=cosine_decay \ --lr_strategy=cosine_decay \
--class_dim=1000 \
--model_save_dir=output/ \ --model_save_dir=output/ \
--lr=0.1 \ --lr=0.1 \
--num_epochs=90 \ --num_epochs=90 \
......
...@@ -9,9 +9,6 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98 ...@@ -9,9 +9,6 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98
python train.py \ python train.py \
--model=VGG13 \ --model=VGG13 \
--batch_size=256 \ --batch_size=256 \
--total_images=1281167 \
--class_dim=1000 \
--image_shape=3,224,224 \
--lr_strategy=cosine_decay \ --lr_strategy=cosine_decay \
--lr=0.01 \ --lr=0.01 \
--num_epochs=90 \ --num_epochs=90 \
......
...@@ -9,10 +9,7 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98 ...@@ -9,10 +9,7 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98
python train.py \ python train.py \
--model=VGG16 \ --model=VGG16 \
--batch_size=256 \ --batch_size=256 \
--total_images=1281167 \
--class_dim=1000 \
--lr_strategy=cosine_decay \ --lr_strategy=cosine_decay \
--image_shape=3,224,224 \
--model_save_dir=output/ \ --model_save_dir=output/ \
--lr=0.01 \ --lr=0.01 \
--num_epochs=90 \ --num_epochs=90 \
......
...@@ -9,9 +9,6 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98 ...@@ -9,9 +9,6 @@ export FLAGS_fraction_of_gpu_memory_to_use=0.98
python train.py \ python train.py \
--model=VGG19 \ --model=VGG19 \
--batch_size=256 \ --batch_size=256 \
--total_images=1281167 \
--class_dim=1000 \
--image_shape=3,224,224 \
--lr_strategy=cosine_decay \ --lr_strategy=cosine_decay \
--lr=0.01 \ --lr=0.01 \
--num_epochs=150 \ --num_epochs=150 \
......
python train.py \ python train.py \
--model=Xception41 \ --model=Xception41 \
--batch_size=256 \ --batch_size=256 \
--total_images=1281167 \ --image_shape=3 299 299 \
--image_shape=3,299,299 \
--class_dim=1000 \
--lr_strategy=cosine_decay \ --lr_strategy=cosine_decay \
--lr=0.045 \ --lr=0.045 \
--num_epochs=120 \ --num_epochs=120 \
......
...@@ -2,9 +2,7 @@ ...@@ -2,9 +2,7 @@
python train.py \ python train.py \
--model=Xception41_deeplab \ --model=Xception41_deeplab \
--batch_size=256 \ --batch_size=256 \
--total_images=1281167 \ --image_shape=3 299 299 \
--image_shape=3,299,299 \
--class_dim=1000 \
--lr_strategy=cosine_decay \ --lr_strategy=cosine_decay \
--lr=0.045 \ --lr=0.045 \
--num_epochs=120 \ --num_epochs=120 \
......
...@@ -2,9 +2,7 @@ ...@@ -2,9 +2,7 @@
python train.py \ python train.py \
--model=Xception65 \ --model=Xception65 \
--batch_size=256 \ --batch_size=256 \
--total_images=1281167 \ --image_shape=3 299 299 \
--image_shape=3,299,299 \
--class_dim=1000 \
--lr_strategy=cosine_decay \ --lr_strategy=cosine_decay \
--lr=0.1 \ --lr=0.1 \
--num_epochs=200 \ --num_epochs=200 \
......
...@@ -2,9 +2,7 @@ ...@@ -2,9 +2,7 @@
python train.py \ python train.py \
--model=Xception65_deeplab \ --model=Xception65_deeplab \
--batch_size=256 \ --batch_size=256 \
--total_images=1281167 \ --image_shape=3 299 299 \
--image_shape=3,299,299 \
--class_dim=1000 \
--lr_strategy=cosine_decay \ --lr_strategy=cosine_decay \
--lr=0.045 \ --lr=0.045 \
--num_epochs=120 \ --num_epochs=120 \
......
...@@ -2,9 +2,7 @@ ...@@ -2,9 +2,7 @@
python train.py \ python train.py \
--model=Xception71 \ --model=Xception71 \
--batch_size=256 \ --batch_size=256 \
--total_images=1281167 \ --image_shape=3 299 299 \
--image_shape=3,299,299 \
--class_dim=1000 \
--lr_strategy=cosine_decay \ --lr_strategy=cosine_decay \
--lr=0.1 \ --lr=0.1 \
--num_epochs=200 \ --num_epochs=200 \
......
...@@ -17,25 +17,10 @@ from __future__ import division ...@@ -17,25 +17,10 @@ from __future__ import division
from __future__ import print_function from __future__ import print_function
import os import os
import numpy as np
import time import time
import sys import sys
import numpy as np
def set_paddle_flags(flags):
for key, value in flags.items():
if os.environ.get(key, None) is None:
os.environ[key] = str(value)
# NOTE(paddle-dev): All of these flags should be
# set before `import paddle`. Otherwise, it would
# not take any effect.
set_paddle_flags({
'FLAGS_eager_delete_tensor_gb': 0, # enable gc
'FLAGS_fraction_of_gpu_memory_to_use': 0.98
})
import paddle import paddle
import paddle.fluid as fluid import paddle.fluid as fluid
from paddle.fluid import profiler from paddle.fluid import profiler
...@@ -48,8 +33,8 @@ from build_model import create_model ...@@ -48,8 +33,8 @@ from build_model import create_model
def build_program(is_train, main_prog, startup_prog, args): def build_program(is_train, main_prog, startup_prog, args):
"""build program, and add grad op in program accroding to different mode """build program, and add grad op in program accroding to different mode
Args: Parameters:
is_train: mode: train or test is_train: indicate train mode or test mode
main_prog: main program main_prog: main program
startup_prog: strartup program startup_prog: strartup program
args: arguments args: arguments
...@@ -59,11 +44,10 @@ def build_program(is_train, main_prog, startup_prog, args): ...@@ -59,11 +44,10 @@ def build_program(is_train, main_prog, startup_prog, args):
test mode: [Loss, data_loader] test mode: [Loss, data_loader]
""" """
if args.model.startswith('EfficientNet'): if args.model.startswith('EfficientNet'):
is_test = False if is_train else True
override_params = {"drop_connect_rate": args.drop_connect_rate} override_params = {"drop_connect_rate": args.drop_connect_rate}
padding_type = args.padding_type padding_type = args.padding_type
use_se = args.use_se use_se = args.use_se
model = models.__dict__[args.model](is_test=is_test, model = models.__dict__[args.model](is_test=not is_train,
override_params=override_params, override_params=override_params,
padding_type=padding_type, padding_type=padding_type,
use_se=use_se) use_se=use_se)
...@@ -94,6 +78,7 @@ def build_program(is_train, main_prog, startup_prog, args): ...@@ -94,6 +78,7 @@ def build_program(is_train, main_prog, startup_prog, args):
loss_out.append(data_loader) loss_out.append(data_loader)
return loss_out return loss_out
def validate(args, test_iter, exe, test_prog, test_fetch_list, pass_id, def validate(args, test_iter, exe, test_prog, test_fetch_list, pass_id,
train_batch_metrics_record): train_batch_metrics_record):
test_batch_time_record = [] test_batch_time_record = []
...@@ -108,8 +93,7 @@ def validate(args, test_iter, exe, test_prog, test_fetch_list, pass_id, ...@@ -108,8 +93,7 @@ def validate(args, test_iter, exe, test_prog, test_fetch_list, pass_id,
test_batch_elapse = t2 - t1 test_batch_elapse = t2 - t1
test_batch_time_record.append(test_batch_elapse) test_batch_time_record.append(test_batch_elapse)
test_batch_metrics_avg = np.mean( test_batch_metrics_avg = np.mean(np.array(test_batch_metrics), axis=1)
np.array(test_batch_metrics), axis=1)
test_batch_metrics_record.append(test_batch_metrics_avg) test_batch_metrics_record.append(test_batch_metrics_avg)
print_info(pass_id, test_batch_id, args.print_step, print_info(pass_id, test_batch_id, args.print_step,
...@@ -196,7 +180,8 @@ def train(args): ...@@ -196,7 +180,8 @@ def train(args):
train_fetch_vars[0], exe) train_fetch_vars[0], exe)
for pass_id in range(args.num_epochs): for pass_id in range(args.num_epochs):
if num_trainers > 1 and not args.use_dali: if num_trainers > 1 and not args.use_dali:
imagenet_reader.set_shuffle_seed(pass_id + (args.random_seed if args.random_seed else 0)) imagenet_reader.set_shuffle_seed(pass_id + (
args.random_seed if args.random_seed else 0))
train_batch_id = 0 train_batch_id = 0
train_batch_time_record = [] train_batch_time_record = []
train_batch_metrics_record = [] train_batch_metrics_record = []
...@@ -230,10 +215,12 @@ def train(args): ...@@ -230,10 +215,12 @@ def train(args):
if args.use_ema: if args.use_ema:
print('ExponentialMovingAverage validate start...') print('ExponentialMovingAverage validate start...')
with ema.apply(exe): with ema.apply(exe):
validate(args, test_iter, exe, test_prog, test_fetch_list, pass_id, train_batch_metrics_record) validate(args, test_iter, exe, test_prog, test_fetch_list,
pass_id, train_batch_metrics_record)
print('ExponentialMovingAverage validate over!') print('ExponentialMovingAverage validate over!')
validate(args, test_iter, exe, test_prog, test_fetch_list, pass_id, train_batch_metrics_record) validate(args, test_iter, exe, test_prog, test_fetch_list, pass_id,
train_batch_metrics_record)
#For now, save model per epoch. #For now, save model per epoch.
if pass_id % args.save_step == 0: if pass_id % args.save_step == 0:
save_model(args, exe, train_prog, pass_id) save_model(args, exe, train_prog, pass_id)
...@@ -241,6 +228,7 @@ def train(args): ...@@ -241,6 +228,7 @@ def train(args):
if args.use_dali: if args.use_dali:
test_iter.reset() test_iter.reset()
def main(): def main():
args = parse_args() args = parse_args()
if int(os.getenv("PADDLE_TRAINER_ID", 0)) == 0: if int(os.getenv("PADDLE_TRAINER_ID", 0)) == 0:
......
...@@ -98,9 +98,9 @@ def parse_args(): ...@@ -98,9 +98,9 @@ def parse_args():
# SOLVER AND HYPERPARAMETERS # SOLVER AND HYPERPARAMETERS
add_arg('model', str, "ResNet50", "The name of network.") add_arg('model', str, "ResNet50", "The name of network.")
add_arg('total_images', int, 1281167, "The number of total training images.") add_arg('total_images', int, 1281167, "The number of total training images.")
parser.add_argument('--image_shape', nargs='+', type=int, default=[3, 224, 224], help="The shape of image")
add_arg('num_epochs', int, 120, "The number of total epochs.") add_arg('num_epochs', int, 120, "The number of total epochs.")
add_arg('class_dim', int, 1000, "The number of total classes.") add_arg('class_dim', int, 1000, "The number of total classes.")
add_arg('image_shape', str, "3,224,224", "The size of Input image, order: [channels, height, weidth] ")
add_arg('batch_size', int, 8, "Minibatch size on a device.") add_arg('batch_size', int, 8, "Minibatch size on a device.")
add_arg('test_batch_size', int, 16, "Test batch size on a deveice.") add_arg('test_batch_size', int, 16, "Test batch size on a deveice.")
add_arg('lr', float, 0.1, "The learning rate.") add_arg('lr', float, 0.1, "The learning rate.")
...@@ -119,7 +119,6 @@ def parse_args(): ...@@ -119,7 +119,6 @@ def parse_args():
add_arg('lower_ratio', float, 3./4., "The value of lower_ratio in ramdom_crop") add_arg('lower_ratio', float, 3./4., "The value of lower_ratio in ramdom_crop")
add_arg('upper_ratio', float, 4./3., "The value of upper_ratio in ramdom_crop") add_arg('upper_ratio', float, 4./3., "The value of upper_ratio in ramdom_crop")
add_arg('resize_short_size', int, 256, "The value of resize_short_size") add_arg('resize_short_size', int, 256, "The value of resize_short_size")
add_arg('crop_size', int, 224, "The value of crop size")
add_arg('use_mixup', bool, False, "Whether to use mixup") add_arg('use_mixup', bool, False, "Whether to use mixup")
add_arg('mixup_alpha', float, 0.2, "The value of mixup_alpha") add_arg('mixup_alpha', float, 0.2, "The value of mixup_alpha")
add_arg('reader_thread', int, 8, "The number of multi thread reader") add_arg('reader_thread', int, 8, "The number of multi thread reader")
...@@ -142,12 +141,14 @@ def parse_args(): ...@@ -142,12 +141,14 @@ def parse_args():
add_arg('ema_decay', float, 0.9999, "The value of ema decay rate") add_arg('ema_decay', float, 0.9999, "The value of ema decay rate")
add_arg('padding_type', str, "SAME", "Padding type of convolution") add_arg('padding_type', str, "SAME", "Padding type of convolution")
add_arg('use_se', bool, True, "Whether to use Squeeze-and-Excitation module for EfficientNet.") add_arg('use_se', bool, True, "Whether to use Squeeze-and-Excitation module for EfficientNet.")
# yapf: enable
#NOTE: args for profiler #NOTE: args for profiler
add_arg('is_profiler', int, 0, "the profiler switch.(used for benchmark)") add_arg('is_profiler', int, 0, "the profiler switch.(used for benchmark)")
add_arg('profiler_path', str, './', "the profiler output file path.(used for benchmark)") add_arg('profiler_path', str, './', "the profiler output file path.(used for benchmark)")
add_arg('max_iter', int, 0, "the max train batch num.(used for benchmark)") add_arg('max_iter', int, 0, "the max train batch num.(used for benchmark)")
add_arg('validate', int, 1, "whether validate.(used for benchmark)") add_arg('validate', int, 1, "whether validate.(used for benchmark)")
# yapf: enable
args = parser.parse_args() args = parser.parse_args()
return args return args
...@@ -306,8 +307,7 @@ def create_data_loader(is_train, args): ...@@ -306,8 +307,7 @@ def create_data_loader(is_train, args):
Returns: Returns:
data_loader and the input data of net, data_loader and the input data of net,
""" """
image_shape = [int(m) for m in args.image_shape.split(",")] image_shape = args.image_shape
feed_image = fluid.data( feed_image = fluid.data(
name="feed_image", name="feed_image",
shape=[None] + image_shape, shape=[None] + image_shape,
...@@ -387,7 +387,6 @@ def print_info(pass_id, batch_id, print_step, metrics, time_info, info_mode): ...@@ -387,7 +387,6 @@ def print_info(pass_id, batch_id, print_step, metrics, time_info, info_mode):
elif info_mode == "epoch": elif info_mode == "epoch":
## TODO add time elapse ## TODO add time elapse
#if isinstance(metrics,np.ndarray):
if len(metrics) == 5: if len(metrics) == 5:
train_loss, _, test_loss, test_acc1, test_acc5 = metrics train_loss, _, test_loss, test_acc1, test_acc5 = metrics
print( print(
...@@ -416,11 +415,12 @@ def best_strategy_compiled(args, program, loss, exe): ...@@ -416,11 +415,12 @@ def best_strategy_compiled(args, program, loss, exe):
return program return program
else: else:
build_strategy = fluid.compiler.BuildStrategy() build_strategy = fluid.compiler.BuildStrategy()
#Feature will be supported in Fluid v1.6
#build_strategy.enable_inplace = True
exec_strategy = fluid.ExecutionStrategy() exec_strategy = fluid.ExecutionStrategy()
exec_strategy.num_threads = fluid.core.get_cuda_device_count()
if args.use_gpu:
exec_strategy.num_threads = fluid.core.get_cuda_device_count()
exec_strategy.num_iteration_per_drop_scope = 10 exec_strategy.num_iteration_per_drop_scope = 10
num_trainers = int(os.environ.get('PADDLE_TRAINERS_NUM', 1)) num_trainers = int(os.environ.get('PADDLE_TRAINERS_NUM', 1))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册