Are you sure you want to delete this task? Once this task is deleted, it cannot be recovered.
xxj1018@foxmail.com ad61e3fd8a | 1 year ago | |
---|---|---|
scripts | 1 year ago | |
src | 1 year ago | |
README.md | 1 year ago | |
eval.py | 1 year ago | |
requriments.txt | 1 year ago | |
train.py | 1 year ago |
图像的二维性质给在计算机视觉中应用自注意力带来了三个挑战:(1)将图像处理为一维序列,忽略了其二维结构。(2)二次复杂度对于高分辨率的图像来说太贵了。(3)它只捕捉了空间适应性,而忽略了通道适应性。在本文中,作者提出了一种新的大核注意(LKA)模块,以使自注意的自适应和长程相关,同时避免了上述问题。作者进一步介绍了一种基于LKA的新的神经网络,即视觉注意网络(VAN)。VAN虽然非常简单和高效,但在包括图像分类、目标检测、语义分割、实例分割等广泛的实验中,它以很大的优势优于最先进的transfomer和卷积神经网络。
使用的数据集:ImageNet2012
└─imagenet
├─train # 训练数据集
└─val # 评估数据集
采用混合精度
的训练方法,使用支持单精度和半精度数据来提高深度学习神经网络的训练速度,同时保持单精度训练所能达到的网络精度。混合精度训练提高计算速度、减少内存使用的同时,支持在特定硬件上训练更大的模型或实现更大批次的训练。
└── VAN
├── eval.py
├── README.md
├── requriments.txt
├── scripts
│ ├── run_distribute_train_ascend.sh
│ ├── run_eval_ascend.sh
│ ├── run_infer_310.sh
│ └── run_standalone_train_ascend.sh
├── src
│ ├── args.py
│ ├── configs
│ │ ├── parser.py
│ │ ├── pth2ckpt
│ │ │ └── pth2ckpt.ipynb
│ │ └── van_base.yaml
│ ├── data
│ │ ├── augment
│ │ │ ├── auto_augment.py
│ │ │ ├── __init__.py
│ │ │ ├── mixup.py
│ │ │ ├── random_erasing.py
│ │ │ └── transforms.py
│ │ ├── data_utils
│ │ │ ├── __init__.py
│ │ │ └── moxing_adapter.py
│ │ ├── imagenet.py
│ │ └── __init__.py
│ ├── models
│ │ ├── __init__.py
│ │ ├── layers
│ │ │ ├── drop_path.py
│ │ │ └── identity.py
│ │ └── van.py
│ ├── tools
│ │ ├── callback.py
│ │ ├── cell.py
│ │ ├── criterion.py
│ │ ├── get_misc.py
│ │ ├── __init__.py
│ │ ├── optimizer.py
│ │ ├── schedulers.py
│ │ └── var_init.py
│ └── trainer
│ └── train_one_step.py
└── train.py
在van_base.yaml中可以同时配置训练参数和评估参数。
配置VAN和ImageNet-1k数据集。
# Architecture 82.8%
arch: van_base
# ===== Dataset ===== #
data_url: ../data/imagenet
set: ImageNet
num_classes: 1000
mix_up: 0.8
cutmix: 1.0
auto_augment: rand-m9-mstd0.5-inc1
interpolation: bicubic
re_prob: 0.0
re_mode: pixel
re_count: 1
mixup_prob: 1.0
switch_prob: 0.5
mixup_mode: batch
image_size: 224
crop_pct: 0.9
# ===== Learning Rate Policy ======== #
optimizer: adamw
base_lr: 0.0005
warmup_lr: 0.000001
min_lr: 0.000001
lr_scheduler: cosine_lr
warmup_length: 5
# ===== Network training config ===== #
amp_level: O1
keep_bn_fp32: True
beta: [ 0.9, 0.999 ]
clip_global_norm_value: 10.
is_dynamic_loss_scale: True
epochs: 300
cooldown_epochs: 10
label_smoothing: 0.1
weight_decay: 0.05
momentum: 0.9
batch_size: 128
drop_path_rate: 0.2
# ===== Hardware setup ===== #
num_parallel_workers: 16
device_target: Ascend
更多配置细节请参考脚本van_base.yaml
。 通过官方网站安装MindSpore后,您可以按照如下步骤进行训练和评估:
Ascend处理器环境运行
# 使用python启动单卡训练
python train.py --device_id 0 --device_target Ascend --config ./src/configs/van_base.yaml \
> train.log 2>&1 &
# 使用脚本启动单卡训练
bash ./scripts/run_standalone_train_ascend.sh [DEVICE_ID] [CONFIG_PATH]
# 使用脚本启动多卡训练
bash ./scripts/run_distribute_train_ascend.sh [RANK_TABLE_FILE] [CONFIG_PATH]
# 使用python启动单卡运行评估示例
python eval.py --device_id 0 --device_target Ascend --config ./src/configs/van_base.yaml > ./eval.log 2>&1 &
# 使用脚本启动单卡运行评估示例
bash ./scripts/run_eval_ascend.sh [DEVICE_ID] [CONFIG_PATH] [CHECKPOINT_PATH]
对于分布式训练,需要提前创建JSON格式的hccl配置文件。
请遵循以下链接中的说明:
参数 | Ascend |
---|---|
模型 | VAN |
模型版本 | van_base |
资源 | Ascend 910 8卡 |
上传日期 | 2022-11-04 |
MindSpore版本 | 1.5.1 |
数据集 | ImageNet-1k Train,共1,281,167张图像 |
训练参数 | epoch=300, batch_size=1024 |
优化器 | AdamWeightDecay |
损失函数 | SoftTargetCrossEntropy |
损失 | 0.747 |
输出 | 概率 |
分类准确率 | 八卡:top1:83.2% top5:96.4% |
速度 | 8卡:371.446毫秒/步 |
训练耗时 | 42h30min03s(run on OpenI) |
请浏览官网主页
2022昇腾AI创新大赛昇思赛道 第一批 赛题八:利用MindSpore实现VAN图像分类网络
Python Jupyter Notebook Shell
Dear OpenI User
Thank you for your continuous support to the Openl Qizhi Community AI Collaboration Platform. In order to protect your usage rights and ensure network security, we updated the Openl Qizhi Community AI Collaboration Platform Usage Agreement in January 2024. The updated agreement specifies that users are prohibited from using intranet penetration tools. After you click "Agree and continue", you can continue to use our services. Thank you for your cooperation and understanding.
For more agreement content, please refer to the《Openl Qizhi Community AI Collaboration Platform Usage Agreement》