Giter Club home page Giter Club logo

cyclemlp-paddle's Introduction

CycleMLP: A MLP-like Architecture for Dense Prediction

目录

1. 简介

这是一个PaddlePaddle实现的CycleMLP。

    

论文: CycleMLP: A MLP-like Architecture for Dense Prediction

参考repo: CycleMLP

项目aistudio地址:

notebook任务:https://aistudio.baidu.com/aistudio/projectdetail/3877397

在此非常感谢ShoufaChen贡献的CycleMLP,提高了本repo复现论文的效率。

2. 数据集和复现精度

数据集为ImageNet,训练集包含1281167张图像,验证集包含50000张图像。

│imagenet/
├──train/
│  ├── n01440764
│  │   ├── n01440764_10026.JPEG
│  │   ├── n01440764_10027.JPEG
│  │   ├── ......
│  ├── ......
├──val/
│  ├── n01440764
│  │   ├── ILSVRC2012_val_00000293.JPEG
│  │   ├── ILSVRC2012_val_00002138.JPEG
│  │   ├── ......
│  ├── ......

您可以从ImageNet 官网申请下载数据。

模型 top1 acc (参考精度) top1 acc (复现精度) 权重 | 训练日志
CycleMLP-B1 0.789 0.790 checkpoint-best.pd | train.log

权重及训练日志下载地址:百度网盘

3. 准备数据与环境

3.1 准备环境

硬件和框架版本等环境的要求如下:

  • 硬件:4 * RTX3090
  • 框架:
    • PaddlePaddle >= 2.2.0
  • 安装paddlepaddle
# 需要安装2.2及以上版本的Paddle,如果
# 安装GPU版本的Paddle
pip install paddlepaddle-gpu==2.2.0
# 安装CPU版本的Paddle
pip install paddlepaddle==2.2.0

更多安装方法可以参考:Paddle安装指南

  • 下载代码
git clone https://github.com/flytocc/CycleMLP-paddle.git
cd CycleMLP-paddle
  • 安装requirements
pip install -r requirements.txt

3.2 准备数据

如果您已经ImageNet1k数据集,那么该步骤可以跳过,如果您没有,则可以从ImageNet官网申请下载。

4. 开始使用

4.1 模型训练

  • 单机多卡训练
export CUDA_VISIBLE_DEVICES=0,1,2,3
python -m paddle.distributed.launch --gpus="0,1,2,3" \
    main.py \
    --model=CycleMLP_B1 \
    --batch_size=256 \
    --data_path=/path/to/imagenet/ \
    --output_dir=./output/ \
    --dist_eval

部分训练日志如下所示。

[16:56:29.233819] Epoch: [261]  [ 920/1251]  eta: 0:05:50  lr: 0.000052  loss: 3.4592 (3.3812)  time: 1.0303  data: 0.0012
[16:56:49.578909] Epoch: [261]  [ 940/1251]  eta: 0:05:29  lr: 0.000052  loss: 3.7399 (3.3853)  time: 1.0171  data: 0.0015

4.2 模型评估

export CUDA_VISIBLE_DEVICES=0,1,2,3
python -m paddle.distributed.launch --gpus="0,1,2,3" \
    eval.py \
    --model=CycleMLP_B1 \
    --batch_size=256 \
    --data_path=/path/to/imagenet/ \
    --dist_eval \
    --resume=$TRAINED_MODEL

4.3 模型预测

python infer.py \
    --model=CycleMLP_B1 \
    --infer_imgs=./demo/ILSVRC2012_val_00020010.JPEG \
    --resume=$TRAINED_MODEL

最终输出结果为

[{'class_ids': [178, 211, 210, 209, 236], 'scores': [0.8659181594848633, 0.004747727885842323, 0.003118610242381692, 0.0025468438398092985, 0.0017893684562295675], 'file_name': './demo/ILSVRC2012_val_00020010.JPEG', 'label_names': ['Weimaraner', 'vizsla, Hungarian pointer', 'German short-haired pointer', 'Chesapeake Bay retriever', 'Doberman, Doberman pinscher']}]

表示预测的类别为Weimaraner(魏玛猎狗),ID是178,置信度为0.8659181594848633

4.4 模型导出

python export_model.py \
    --model=CycleMLP_B1 \
    --output_dir=./output/ \
    --resume=$TRAINED_MODEL

5. 代码结构

├── cycle_mlp.py
├── demo
├── engine.py
├── eval.py
├── export_model.py
├── infer.py
├── main.py
├── README.md
├── requirements.txt
├── test_tipc
└── util

6. 自动化测试脚本

详细日志在test_tipc/output

TIPC: TIPC: test_tipc/README.md

首先安装auto_log,需要进行安装,安装方式如下: auto_log的详细介绍参考https://github.com/LDOUBLEV/AutoLog。

git clone https://github.com/LDOUBLEV/AutoLog
cd AutoLog/
pip3 install -r requirements.txt
python3 setup.py bdist_wheel
pip3 install ./dist/auto_log-1.2.0-py3-none-any.whl

进行TIPC:

bash test_tipc/prepare.sh test_tipc/config/CycleMLP/CycleMLP_B1.txt 'lite_train_lite_infer'

bash test_tipc/test_train_inference_python.sh test_tipc/config/CycleMLP/CycleMLP_B1.txt 'lite_train_lite_infer'

TIPC结果:

如果运行成功,在终端中会显示下面的内容,具体的日志也会输出到test_tipc/output/文件夹中的文件中。

Run successfully with command - python3.7 eval.py --model=CycleMLP_B1 --data_path=./dataset/ILSVRC2012/ --cls_label_path=./dataset/ILSVRC2012/val_list.txt --resume=./test_tipc/output/norm_train_gpus_0_autocast_null/CycleMLP_B1/checkpoint-latest.pd !
Run successfully with command - python3.7 export_model.py --model=CycleMLP_B1 --resume=./test_tipc/output/norm_train_gpus_0_autocast_null/CycleMLP_B1/checkpoint-latest.pd --output=./test_tipc/output/norm_train_gpus_0_autocast_null !
Run successfully with command - python3.7 inference.py --use_gpu=True --use_tensorrt=False --precision=fp32 --model_file=./test_tipc/output/norm_train_gpus_0_autocast_null/model.pdmodel --batch_size=2 --input_file=./dataset/ILSVRC2012/val  --params_file=./test_tipc/output/norm_train_gpus_0_autocast_null/model.pdiparams > ./test_tipc/output/python_infer_gpu_usetrt_False_precision_fp32_batchsize_2.log 2>&1 !
...

7. License

This project is released under MIT License.

8. 参考链接与文献

  1. CycleMLP: A MLP-like Architecture for Dense Prediction: https://arxiv.org/abs/2107.10224
  2. CycleMLP: https://github.com/ShoufaChen/CycleMLP

再次感谢ShoufaChen贡献的CycleMLP,提高了本repo复现论文的效率。

@inproceedings{
chen2022cyclemlp,
title={Cycle{MLP}: A {MLP}-like Architecture for Dense Prediction},
author={Shoufa Chen and Enze Xie and Chongjian GE and Runjian Chen and Ding Liang and Ping Luo},
booktitle={International Conference on Learning Representations},
year={2022},
url={https://openreview.net/forum?id=NMEceG4v69Y}
}

cyclemlp-paddle's People

Contributors

flytocc avatar

Watchers

 avatar

cyclemlp-paddle's Issues

关于0维Tensor的代码修改请求

Hi,开发者你好,由于飞桨API之前对0维Tensor的支持不完善,通过shape为[1]的1D Tensor来替代shape为[]的0D Tensor,因此在很多本应输出0维tensor的场景中,实际输出的是1维tensor(如:loss)。目前飞桨计划全面支持0维tensor,在大多数情况下不会有不兼容问题,但也发现少量情况可能会报错。

目前发现 会报错 的代码是:loss.numpy()[0] 。原因是此前loss为1D Tensor(错误的语义),运行loss.numpy()[0]可以将其转化为python float数据。在loss被修改为0D Tensor(正确的语义)后,此操作会报错。需要将所有 loss.numpy()[0] 修改为 float(loss) ,以避免后续版本的代码错误。

因此请麻烦修改:

  • 对于shape为[1]的1维Tensor:Tensor.numpy()[0] 修改为 float(Tensor),对当前不会有影响,亦可适应未来变化。感谢贡献代码。

Hi, Developer, Due to the poor support for the 0D tensor in Paddle API. In many case, the output 1D tensor which shoulde be 0D Tensor (such as loss) are used by mistake. Paddle is plan to support 0D tensor fully, which will not cause incompatibility in most cases. However, it is also found that some code will report error.

This code is: loss.numpy()[0] 。 The reason is that the loss was 1D Tensor (wrong) before, it can be used as loss.numpy()[0]. After the loss is modified to 0D Tensor (correct), the operation will result in an error. Therefore, it is needed to modify loss.numpy()[0] to float(loss) , to avoid errors in future paddle version.

Therefore, please modify:

  • As for shape[1] Tensor: modify Tensor.numpy()[0] to float (Tensor) , It will not affect the current situation, but also adapt to future. Thank you for contributing code.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.