位置:首页 > 新闻资讯 > 【悉读经典】ConvNext 在PaddleClas、Seg、Det中的应用

【悉读经典】ConvNext 在PaddleClas、Seg、Det中的应用

时间:2025-07-17  |  作者:  |  阅读:0

本项目基于ConvNeXt论文《A ConvNet for the 2020s》的核心思想,探索了现代卷积网络的优化路径。通过系统性地改进ResNet50架构(包括训练策略调整、宏观设计优化、ResNeXt化、倒置瓶颈结构、大卷积核应用等7大模块),在ImageNet上将准确率从76.1%提升至82.0%。

【悉读经典】ConvNext 在PaddleClas、Seg、Det中的应用_wishdown.com

项目背景

本项目首先摘抄了ConvNeXt论文的观点内容然后通过代码实现了:

但并未进行超参优化,感兴趣的同学可以自行探索

《A ConvNet for the 2020s》

time:

release in 2020.01

read in 2022.03.27

ref:

pdf;?url;?code

ConvNeXt:探索CNN网络的极限潜力 ——AiStudio

key words:

Backbone;图像分类;??卷积

Modernizing a ConvNet: a Roadmap

重新以resnet50(flops与ResNet相同,且结构较为简单)为基准(?76.1%?),以swin的训练技巧训练resnet50,作为baseline,进行网络训练

并且逐步加入结构变化与tricks,以接近transformer,包括

  1. macro design,
  2. ResNeXt,
  3. inverted bottleneck,
  4. large kernel size,
  5. various layer-wise micro designs

Training Techniques

视觉transformer不仅提出了新架构,也提出了新的训练技巧,例如AdamW

本文使用的是近似于DeiT的训练策略,仅使用这些训练策略,就可以在resnet50上提升2.7精度(78.8%)√:

Macro Design

Changing stage compute ratio

借鉴Swim-T中1 1 3 1的计算比,

本文将resnet50中的3 4 6 3?计算比调整为 3 3 9 3,精度(79.4%)√:

Changing stem to “Patchify”

ResNet的stem部分使用的是 2步长卷积大卷积核+池化,将输入图像4倍下采样

视觉transformer中,使用更碎片化/patchify的策略,使用大卷积核-14或16size及不重叠卷积,swim使用了相似的策略,但是将patch size设置为4

文本使用4 * 4的4步长卷积替换stem部分,精度(79.5%)√

ResNeXt-ify

ResNeXt使用了分组卷积,降了了FLOPs,因此可以通过拓宽网络的形式来弥补网络的性能损失

深度卷积/depthwise类似于自关注的加权机制,每个通道上进行操作,只在空间维度进行信息混合;使用深度卷积+1 * 1卷积,可以将空间信息混合、通道信息混合进行分离,这种属性在视觉transformer中也有出现,它们的操作要么值对空间维度进行混合,要么只对通道维度进行混合,而不是同时对两者进行操作。

本文使用深度卷积,有效降低了FLOPs,但为了Swin-T一致,将网络通道数增加到96,精度(80.5%)√

Inverted Bottleneck

transformer的一大重要设计是,将瓶颈/bottleneck进行倒置,即:MLP中的隐藏维度是输入维度的4倍

【悉读经典】ConvNext 在PaddleClas、Seg、Det中的应用_wishdown.com

如上图,swin中的通道96-384-96,resnet中通道64-64-256,ConvNeXt中通道96-384-96

本文使用瓶颈倒置后,FLOPs降低,主要源于shortcut的1 * 1卷积参数减少,同时精度(80.6%)√

但是在大模型, ResNet-200/ Swin-B的比较中,该结构应用将精度从81.9%提升到82.6%

Large Kernel Sizes

transformer的一大特点在于,非局部自关注,使得每层可以有一个全局感受野。

swin使用的自关注窗口尺寸至少为7* 7,显著大于ResNe(X)t的 3 * 3

Moving up depthwise conv layer

参考transformer中,将MSA模块放在MLP模块之前,本文也探索将深度卷积放置在2层1 * 1卷积之前,如图所示,分别为ResNeXt模块、瓶颈倒置模块、深度卷积提前模块

【悉读经典】ConvNext 在PaddleClas、Seg、Det中的应用_wishdown.com

这一操作也显著降低FLOPs,但精度(79.9%)√

Increasing the kernel size

在深度卷积提前模块的基础上

本文尝试3 5 7 9 11多种尺寸卷积核,当尺度达到7时,精度饱和,因此选用7 * 7卷积,精度(80.6%)√

Micro Design

**Replacing ReLU with GELU **

GELU被认为是ReLU的平滑变体,

本文也使用了GELU,精度(80.6%)√

Fewer activation functions.

transformer中使用了k、q、v嵌入,映射,双fc的MLP,但只在MLP中使用了1次激活

本文也只在1 * 1卷积中使用1次激活,精度(81.3%)√

Fewer normalization layers

transformer中的normalization层也很少

本文尝试保留2个nor层,精度并无提升,当只保留1个nor层时,精度(81.4%)√

【悉读经典】ConvNext 在PaddleClas、Seg、Det中的应用_wishdown.com

Substituting BN with LN

BN层是卷积网络加速收敛、减少过拟合的重要组件,但是也存在一些问题

在原始ResNet中使用LN替换BN,效果并不理想

本文在前述改进下使用LN替换BN,有略微提升,精度(81.5%)√

Separate downsampling layers

ResNet中,在stage起始阶段使用3 * 3的2步长卷积下采样

swin中,将这个过程分离到每个stage之间,

本文采用swin策略,使用2 * 2的2步长卷积下采样,并进一步增加LN以提高训练稳定性(LN位置:每次下采样之后、stem之后,最终全局平均池化之前),精度(82.0%)√

改进历程汇总

【悉读经典】ConvNext 在PaddleClas、Seg、Det中的应用_wishdown.com

实验:

本文提出的ConvNeXt对比通道架构的Swin处理速度略快,精度高

【悉读经典】ConvNext 在PaddleClas、Seg、Det中的应用_wishdown.com

【悉读经典】ConvNext 在PaddleClas、Seg、Det中的应用_wishdown.com

此外还附有ConvNeXt与ViT的比较

ConvNeXt与Swin在下游任务的比较

附录中有参数设置等

【conclusion】

个人十分喜欢这篇论文,个人也曾经尝试过进行unet相关结构的替换改造,但是由于跟人水平有限,最后一团糟;

这篇论文的逻辑非常清晰,并且对每个修改都有放出效果,比赛魔改模型可以参考改论文

为了进一步追求准确率,可以考虑对于depth conv、move d.conv的取舍,

这篇文章证明了卷积网络的精度不止于目前的水平,绝对可以更进一步

在PaddleClas中使用ConvNeXt进行图像分类

——以“猫十二分类体验赛”为例

环境准备

In [1]

# pip升级!pip install --user --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple# 下载仓库,并切换到2.3版本%cd /home/aistudio/!git clone https://gitee.com/paddlepaddle/PaddleClas.git #该行仅在初次运行项目时运行即可,后续不需要运行该行命令%cd /home/aistudio/PaddleClas!git checkout -b release/2.3 origin/release/2.3# 安装依赖环境!pip install -r requirements.txt登录后复制

Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simpleRequirement already satisfied: pip in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (22.0.4)/home/aistudio正克隆到 'PaddleClas'...remote: Enumerating objects: 25293, done.remote: Counting objects: 100% (5176/5176), done.remote: Compressing objects: 100% (1840/1840), done.remote: Total 25293 (delta 3636), reused 4691 (delta 3319), pack-reused 20117接收对象中: 100% (25293/25293), 155.60 MiB | 22.57 MiB/s, 完成.处理 delta 中: 100% (17421/17421), 完成.检查连接... 完成。/home/aistudio/PaddleClasfatal: 一个分支名 'release/2.3' 已经存在。Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simpleRequirement already satisfied: prettytable in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 1)) (0.7.2)Requirement already satisfied: ujson in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 2)) (5.1.0)Collecting opencv-python==4.4.0.46 Downloading https://pypi.tuna.tsinghua.edu.cn/packages/1b/2d/62eba161d3d713e1720504de1c25d439b02c85159804d9ecead10be5d87e/opencv_python-4.4.0.46-cp37-cp37m-manylinux2014_x86_64.whl (49.5 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 49.5/49.5 MB 2.1 MB/s eta 0:00:0000:0100:01Requirement already satisfied: pillow in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 4)) (8.2.0)Requirement already satisfied: tqdm in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 5)) (4.27.0)Requirement already satisfied: PyYAML in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 6)) (5.1.2)Requirement already satisfied: visualdl>=2.2.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 7)) (2.2.3)Requirement already satisfied: scipy in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 8)) (1.6.3)Collecting scikit-learn==0.23.2 Downloading https://pypi.tuna.tsinghua.edu.cn/packages/f4/cb/64623369f348e9bfb29ff898a57ac7c91ed4921f228e9726546614d63ccb/scikit_learn-0.23.2-cp37-cp37m-manylinux1_x86_64.whl (6.8 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 6.8/6.8 MB 2.5 MB/s eta 0:00:0000:0100:01Requirement already satisfied: gast==0.3.3 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 10)) (0.3.3)Collecting faiss-cpu==1.7.1.post2 Downloading https://pypi.tuna.tsinghua.edu.cn/packages/4c/d6/072a9d18430b8c68c99ffb49fe14fbf89c62f71dcd4f5f692c7691447a14/faiss_cpu-1.7.1.post2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.4 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 8.4/8.4 MB 3.0 MB/s eta 0:00:0000:0100:01Requirement already satisfied: numpy>=1.14.5 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from opencv-python==4.4.0.46->-r requirements.txt (line 3)) (1.19.5)Requirement already satisfied: threadpoolctl>=2.0.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from scikit-learn==0.23.2->-r requirements.txt (line 9)) (2.1.0)Requirement already satisfied: joblib>=0.11 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from scikit-learn==0.23.2->-r requirements.txt (line 9)) (0.14.1)Requirement already satisfied: protobuf>=3.11.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.2.0->-r requirements.txt (line 7)) (3.14.0)Requirement already satisfied: Flask-Babel>=1.0.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.2.0->-r requirements.txt (line 7)) (1.0.0)Requirement already satisfied: six>=1.14.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.2.0->-r requirements.txt (line 7)) (1.16.0)Requirement already satisfied: pandas in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.2.0->-r requirements.txt (line 7)) (1.1.5)Requirement already satisfied: pre-commit in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.2.0->-r requirements.txt (line 7)) (1.21.0)Requirement already satisfied: bce-python-sdk in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.2.0->-r requirements.txt (line 7)) (0.8.53)Requirement already satisfied: shellcheck-py in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.2.0->-r requirements.txt (line 7)) (0.7.1.1)Requirement already satisfied: flake8>=3.7.9 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.2.0->-r requirements.txt (line 7)) (4.0.1)Requirement already satisfied: matplotlib in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.2.0->-r requirements.txt (line 7)) (2.2.3)Requirement already satisfied: flask>=1.1.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.2.0->-r requirements.txt (line 7)) (1.1.1)Requirement already satisfied: requests in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.2.0->-r requirements.txt (line 7)) (2.24.0)Requirement already satisfied: pycodestyle<2.9.0,>=2.8.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flake8>=3.7.9->visualdl>=2.2.0->-r requirements.txt (line 7)) (2.8.0)Requirement already satisfied: pyflakes<2.5.0,>=2.4.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flake8>=3.7.9->visualdl>=2.2.0->-r requirements.txt (line 7)) (2.4.0)Requirement already satisfied: importlib-metadata<4.3 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flake8>=3.7.9->visualdl>=2.2.0->-r requirements.txt (line 7)) (4.2.0)Requirement already satisfied: mccabe<0.7.0,>=0.6.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flake8>=3.7.9->visualdl>=2.2.0->-r requirements.txt (line 7)) (0.6.1)Requirement already satisfied: click>=5.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flask>=1.1.1->visualdl>=2.2.0->-r requirements.txt (line 7)) (7.0)Requirement already satisfied: Werkzeug>=0.15 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flask>=1.1.1->visualdl>=2.2.0->-r requirements.txt (line 7)) (0.16.0)Requirement already satisfied: itsdangerous>=0.24 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flask>=1.1.1->visualdl>=2.2.0->-r requirements.txt (line 7)) (1.1.0)Requirement already satisfied: Jinja2>=2.10.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flask>=1.1.1->visualdl>=2.2.0->-r requirements.txt (line 7)) (3.1.1)Requirement already satisfied: pytz in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from Flask-Babel>=1.0.0->visualdl>=2.2.0->-r requirements.txt (line 7)) (2022.1)Requirement already satisfied: Babel>=2.3 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from Flask-Babel>=1.0.0->visualdl>=2.2.0->-r requirements.txt (line 7)) (2.9.1)Requirement already satisfied: future>=0.6.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from bce-python-sdk->visualdl>=2.2.0->-r requirements.txt (line 7)) (0.18.0)Requirement already satisfied: pycryptodome>=3.8.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from bce-python-sdk->visualdl>=2.2.0->-r requirements.txt (line 7)) (3.9.9)Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from matplotlib->visualdl>=2.2.0->-r requirements.txt (line 7)) (3.0.7)Requirement already satisfied: python-dateutil>=2.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from matplotlib->visualdl>=2.2.0->-r requirements.txt (line 7)) (2.8.2)Requirement already satisfied: cycler>=0.10 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from matplotlib->visualdl>=2.2.0->-r requirements.txt (line 7)) (0.10.0)Requirement already satisfied: kiwisolver>=1.0.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from matplotlib->visualdl>=2.2.0->-r requirements.txt (line 7)) (1.1.0)Requirement already satisfied: toml in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from pre-commit->visualdl>=2.2.0->-r requirements.txt (line 7)) (0.10.0)Requirement already satisfied: cfgv>=2.0.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from pre-commit->visualdl>=2.2.0->-r requirements.txt (line 7)) (2.0.1)Requirement already satisfied: virtualenv>=15.2 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from pre-commit->visualdl>=2.2.0->-r requirements.txt (line 7)) (16.7.9)Requirement already satisfied: nodeenv>=0.11.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from pre-commit->visualdl>=2.2.0->-r requirements.txt (line 7)) (1.3.4)Requirement already satisfied: aspy.yaml in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from pre-commit->visualdl>=2.2.0->-r requirements.txt (line 7)) (1.3.0)Requirement already satisfied: identify>=1.0.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from pre-commit->visualdl>=2.2.0->-r requirements.txt (line 7)) (1.4.10)Requirement already satisfied: idna<3,>=2.5 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests->visualdl>=2.2.0->-r requirements.txt (line 7)) (2.10)Requirement already satisfied: certifi>=2017.4.17 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests->visualdl>=2.2.0->-r requirements.txt (line 7)) (2021.10.8)Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests->visualdl>=2.2.0->-r requirements.txt (line 7)) (1.25.11)Requirement already satisfied: chardet<4,>=3.0.2 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests->visualdl>=2.2.0->-r requirements.txt (line 7)) (3.0.4)Requirement already satisfied: typing-extensions>=3.6.4 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from importlib-metadata<4.3->flake8>=3.7.9->visualdl>=2.2.0->-r requirements.txt (line 7)) (4.1.1)Requirement already satisfied: zipp>=0.5 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from importlib-metadata<4.3->flake8>=3.7.9->visualdl>=2.2.0->-r requirements.txt (line 7)) (3.7.0)Requirement already satisfied: MarkupSafe>=2.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from Jinja2>=2.10.1->flask>=1.1.1->visualdl>=2.2.0->-r requirements.txt (line 7)) (2.0.1)Requirement already satisfied: setuptools in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from kiwisolver>=1.0.1->matplotlib->visualdl>=2.2.0->-r requirements.txt (line 7)) (56.2.0)Installing collected packages: faiss-cpu, opencv-python, scikit-learn Attempting uninstall: opencv-python Found existing installation: opencv-python 4.1.1.26 Uninstalling opencv-python-4.1.1.26: Successfully uninstalled opencv-python-4.1.1.26 Attempting uninstall: scikit-learn Found existing installation: scikit-learn 0.24.2 Uninstalling scikit-learn-0.24.2: Successfully uninstalled scikit-learn-0.24.2Successfully installed faiss-cpu-1.7.1.post2 opencv-python-4.4.0.46 scikit-learn-0.23.2登录后复制

数据准备

In [2]

!unzip -oq /home/aistudio/data/data10954/cat_12_train.zip -d /home/aistudio/data/data10954/!unzip -oq /home/aistudio/data/data10954/cat_12_test.zip -d /home/aistudio/data/data10954/登录后复制

代码准备

In [3]

# 以下代码及配置,均基于PASSL中内容进行迁移!cp /home/aistudio/work/class/convnext.yml /home/aistudio/PaddleClas/convnext.yml # 配置文件!cp /home/aistudio/work/class/convnext.py /home/aistudio/PaddleClas/ppcls/arch/backbone/legendary_models/convnext.py # 网络结构代码!cp /home/aistudio/work/class/__init__1.py /home/aistudio/PaddleClas/ppcls/arch/backbone/legendary_models/__init__.py # 导入网络!cp /home/aistudio/work/class/__init__2.py /home/aistudio/PaddleClas/ppcls/arch/backbone/__init__.py # 导入网络!cp /home/aistudio/work/class/__init__3.py /home/aistudio/PaddleClas/ppcls/data/preprocess/__init__.py # 增加RandomResizedCrop算子!cp /home/aistudio/work/class/imagenet_dataset.py /home/aistudio/PaddleClas/ppcls/data/dataloader/imagenet_dataset.py # 修改数据读取方法!cp /home/aistudio/work/class/save_load.py /home/aistudio/PaddleClas/ppcls/utils/save_load.py # 修改参数加载方法!cp /home/aistudio/work/class/engine.py /home/aistudio/PaddleClas/ppcls/engine/engine.py # 修改推理输出过程,将推理结果以csv格式保存在/home/aistudio/result.csv下!cp /home/aistudio/work/class/train_list.txt /home/aistudio/data/data10954/train_list.txt # 去掉前160个样本,剩余2000个样本,去掉4个无法读取样本作为训练集!cp /home/aistudio/work/class/val_list.txt /home/aistudio/data/data10954/val_list.txt # 取前160个样本作为验证集,去掉1个无法读取样本登录后复制

网络训练

In [4]

# 简单训练5 epoch!python /home/aistudio/PaddleClas/tools/train.py -c /home/aistudio/PaddleClas/convnext.yml -o Arch.class_num=12 -o Global.epochs=5 -o Optimizer.lr.epoch=5 -o Optimizer.lr.step_each_epoch=32 -o Optimizer.lr.warmup_epoch=1 -o DataLoader.Train.sampler.batch_size=64 -o DataLoader.Eval.sampler.batch_size=128登录后复制

A new filed (epoch) detected![2022/03/31 18:04:25] root INFO: ============================================================= PaddleClas is powered by PaddlePaddle ! =============================================================== ==== For more info please go to the following website. ==== ==== https://github.com/PaddlePaddle/PaddleClas =============================================================[2022/03/31 18:04:25] root INFO: Arch : [2022/03/31 18:04:25] root INFO: class_num : 12[2022/03/31 18:04:25] root INFO: name : ConvNeXt_Tiny[2022/03/31 18:04:25] root INFO: DataLoader : [2022/03/31 18:04:25] root INFO: Eval : [2022/03/31 18:04:25] root INFO: dataset : [2022/03/31 18:04:25] root INFO: cls_label_path : /home/aistudio/data/data10954/val_list.txt[2022/03/31 18:04:25] root INFO: image_root : /home/aistudio/data/data10954/[2022/03/31 18:04:25] root INFO: name : ImageNetDataset[2022/03/31 18:04:25] root INFO: transform_ops : [2022/03/31 18:04:25] root INFO: DecodeImage : [2022/03/31 18:04:25] root INFO: channel_first : False[2022/03/31 18:04:25] root INFO: to_rgb : True[2022/03/31 18:04:25] root INFO: ResizeImage : [2022/03/31 18:04:25] root INFO: resize_short : 256[2022/03/31 18:04:25] root INFO: CropImage : [2022/03/31 18:04:25] root INFO: size : 224[2022/03/31 18:04:25] root INFO: NormalizeImage : [2022/03/31 18:04:25] root INFO: mean : [0.485, 0.456, 0.406][2022/03/31 18:04:25] root INFO: order : [2022/03/31 18:04:25] root INFO: scale : 1.0/255.0[2022/03/31 18:04:25] root INFO: std : [0.229, 0.224, 0.225][2022/03/31 18:04:25] root INFO: loader : [2022/03/31 18:04:25] root INFO: num_workers : 4[2022/03/31 18:04:25] root INFO: use_shared_memory : True[2022/03/31 18:04:25] root INFO: sampler : [2022/03/31 18:04:25] root INFO: batch_size : 128[2022/03/31 18:04:25] root INFO: drop_last : False[2022/03/31 18:04:25] root INFO: name : DistributedBatchSampler[2022/03/31 18:04:25] root INFO: shuffle : False[2022/03/31 18:04:25] root INFO: Train : [2022/03/31 18:04:25] root INFO: dataset : [2022/03/31 18:04:25] root INFO: cls_label_path : /home/aistudio/data/data10954/train_list.txt[2022/03/31 18:04:25] root INFO: image_root : /home/aistudio/data/data10954/[2022/03/31 18:04:25] root INFO: name : ImageNetDataset[2022/03/31 18:04:25] root INFO: transform_ops : [2022/03/31 18:04:25] root INFO: DecodeImage : [2022/03/31 18:04:25] root INFO: channel_first : False[2022/03/31 18:04:25] root INFO: to_rgb : True[2022/03/31 18:04:25] root INFO: RandomResizedCrop : [2022/03/31 18:04:25] root INFO: interpolation : bicubic[2022/03/31 18:04:25] root INFO: ratio : [1.0, 1.0][2022/03/31 18:04:25] root INFO: scale : [0.75, 1.0][2022/03/31 18:04:25] root INFO: size : 224[2022/03/31 18:04:25] root INFO: NormalizeImage : [2022/03/31 18:04:25] root INFO: mean : [0.485, 0.456, 0.406][2022/03/31 18:04:25] root INFO: order : [2022/03/31 18:04:25] root INFO: scale : 1.0/255.0[2022/03/31 18:04:25] root INFO: std : [0.229, 0.224, 0.225][2022/03/31 18:04:25] root INFO: loader : [2022/03/31 18:04:25] root INFO: num_workers : 4[2022/03/31 18:04:25] root INFO: use_shared_memory : True[2022/03/31 18:04:25] root INFO: sampler : [2022/03/31 18:04:25] root INFO: batch_size : 64[2022/03/31 18:04:25] root INFO: drop_last : False[2022/03/31 18:04:25] root INFO: name : DistributedBatchSampler[2022/03/31 18:04:25] root INFO: shuffle : True[2022/03/31 18:04:25] root INFO: Global : [2022/03/31 18:04:25] root INFO: checkpoints : None[2022/03/31 18:04:25] root INFO: device : gpu[2022/03/31 18:04:25] root INFO: epochs : 5[2022/03/31 18:04:25] root INFO: eval_during_train : True[2022/03/31 18:04:25] root INFO: eval_interval : 1[2022/03/31 18:04:25] root INFO: image_shape : [3, 300, 300][2022/03/31 18:04:25] root INFO: output_dir : /home/aistudio/data/output_class/[2022/03/31 18:04:25] root INFO: pretrained_model : https://passl.bj.bcebos.com/models/convnext_tiny_1k_224.pdparams[2022/03/31 18:04:25] root INFO: print_batch_step : 10[2022/03/31 18:04:25] root INFO: save_inference_dir : /home/aistudio/data/inference[2022/03/31 18:04:25] root INFO: save_interval : 1[2022/03/31 18:04:25] root INFO: use_visualdl : False[2022/03/31 18:04:25] root INFO: Infer : [2022/03/31 18:04:25] root INFO: PostProcess : [2022/03/31 18:04:25] root INFO: class_id_map_file : /home/aistudio/work/class/label_list.txt[2022/03/31 18:04:25] root INFO: name : Topk[2022/03/31 18:04:25] root INFO: topk : 5[2022/03/31 18:04:25] root INFO: batch_size : 100[2022/03/31 18:04:25] root INFO: infer_imgs : docs/images/inference_deployment/whl_demo.jpg[2022/03/31 18:04:25] root INFO: transforms : [2022/03/31 18:04:25] root INFO: DecodeImage : [2022/03/31 18:04:25] root INFO: channel_first : False[2022/03/31 18:04:25] root INFO: to_rgb : True[2022/03/31 18:04:25] root INFO: ResizeImage : [2022/03/31 18:04:25] root INFO: resize_short : 256[2022/03/31 18:04:25] root INFO: CropImage : [2022/03/31 18:04:25] root INFO: size : 224[2022/03/31 18:04:25] root INFO: NormalizeImage : [2022/03/31 18:04:25] root INFO: mean : [0.485, 0.456, 0.406][2022/03/31 18:04:25] root INFO: order : [2022/03/31 18:04:25] root INFO: scale : 1.0/255.0[2022/03/31 18:04:25] root INFO: std : [0.229, 0.224, 0.225][2022/03/31 18:04:25] root INFO: ToCHWImage : None[2022/03/31 18:04:25] root INFO: Loss : [2022/03/31 18:04:25] root INFO: Eval : [2022/03/31 18:04:25] root INFO: CELoss : [2022/03/31 18:04:25] root INFO: weight : 1.0[2022/03/31 18:04:25] root INFO: Train : [2022/03/31 18:04:25] root INFO: CELoss : [2022/03/31 18:04:25] root INFO: epsilon : 0.1[2022/03/31 18:04:25] root INFO: weight : 1.0[2022/03/31 18:04:25] root INFO: Metric : [2022/03/31 18:04:25] root INFO: Eval : [2022/03/31 18:04:25] root INFO: TopkAcc : [2022/03/31 18:04:25] root INFO: topk : [1, 5][2022/03/31 18:04:25] root INFO: Train : [2022/03/31 18:04:25] root INFO: TopkAcc : [2022/03/31 18:04:25] root INFO: topk : [1, 5][2022/03/31 18:04:25] root INFO: Optimizer : [2022/03/31 18:04:25] root INFO: beta1 : 0.9[2022/03/31 18:04:25] root INFO: beta2 : 0.999[2022/03/31 18:04:25] root INFO: lr : [2022/03/31 18:04:25] root INFO: epoch : 5[2022/03/31 18:04:25] root INFO: epochs : 300[2022/03/31 18:04:25] root INFO: eta_min : 1e-05[2022/03/31 18:04:25] root INFO: learning_rate : 0.000125[2022/03/31 18:04:25] root INFO: name : Cosine[2022/03/31 18:04:25] root INFO: step_each_epoch : 32[2022/03/31 18:04:25] root INFO: warmup_epoch : 1[2022/03/31 18:04:25] root INFO: warmup_start_lr : 1e-06[2022/03/31 18:04:25] root INFO: name : AdamW[2022/03/31 18:04:25] root INFO: weight_decay : 0.05[2022/03/31 18:04:25] root INFO: profiler_options : None[2022/03/31 18:04:25] root INFO: train with paddle 2.2.2 and device CUDAPlace(0)[2022/03/31 18:04:25] root WARNING: 'TopkAcc' metric can not be used when setting 'batch_transform_ops' in config. The 'TopkAcc' metric has been removed.W0331 18:04:25.969805 303 device_context.cc:447] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 10.1, Runtime API Version: 10.1W0331 18:04:25.974506 303 device_context.cc:465] device: 0, cuDNN Version: 7.6.[2022/03/31 18:04:30] root INFO: unique_endpoints {''}[2022/03/31 18:04:30] root INFO: Downloading convnext_tiny_1k_224.pdparams from https://passl.bj.bcebos.com/models/convnext_tiny_1k_224.pdparams100%|████████████████████████████████| 111694/111694 [00:03<00:00, 37222.88it/s]/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/dygraph/layers.py:1441: UserWarning: Skip loading for head.fc_cls.weight. head.fc_cls.weight receives a shape [768, 1000], but the expected shape is [768, 12]. warnings.warn((”Skip loading for {}. “.format(key) + str(err)))/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/dygraph/layers.py:1441: UserWarning: Skip loading for head.fc_cls.bias. head.fc_cls.bias receives a shape [1000], but the expected shape is [12]. warnings.warn((”Skip loading for {}. “.format(key) + str(err)))model loading : [182]/[182][2022/03/31 18:04:33] root WARNING: The training strategy in config files provided by PaddleClas is based on 4 gpus. But the number of gpus is 1 in current training. Please modify the stategy (learning rate, batch size and so on) if use config files in PaddleClas to train.[2022/03/31 18:04:35] root INFO: [Train][Epoch 1/5][Iter: 0/32]lr: 0.00000, CELoss: 2.50516, loss: 2.50516, batch_cost: 2.09711s, reader_cost: 1.59906, ips: 30.51826 images/sec, eta: 0:05:35[2022/03/31 18:04:38] root INFO: [Train][Epoch 1/5][Iter: 10/32]lr: 0.00004, CELoss: 2.50141, loss: 2.50141, batch_cost: 0.30005s, reader_cost: 0.00157, ips: 213.29944 images/sec, eta: 0:00:45[2022/03/31 18:04:41] root INFO: [Train][Epoch 1/5][Iter: 20/32]lr: 0.00008, CELoss: 2.45706, loss: 2.45706, batch_cost: 0.29993s, reader_cost: 0.00162, ips: 213.38383 images/sec, eta: 0:00:41[2022/03/31 18:04:45] root INFO: [Train][Epoch 1/5][Iter: 30/32]lr: 0.00012, CELoss: 2.37709, loss: 2.37709, batch_cost: 0.30253s, reader_cost: 0.00129, ips: 211.55021 images/sec, eta: 0:00:39[2022/03/31 18:04:45] root INFO: [Train][Epoch 1/5][Avg]CELoss: 2.37555, loss: 2.37555[2022/03/31 18:04:46] root INFO: [Eval][Epoch 1][Iter: 0/2]CELoss: 3.13076, loss: 3.13076, top1: 0.00000, top5: 0.00000, batch_cost: 1.38679s, reader_cost: 1.21769, ips: 92.29973 images/sec[2022/03/31 18:04:46] root INFO: [Eval][Epoch 1][Avg]CELoss: 3.12133, loss: 3.12133, top1: 0.00000, top5: 0.00000[2022/03/31 18:04:46] root INFO: [Eval][Epoch 1][best metric: 0.0]/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/framework/io.py:415: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working if isinstance(obj, collections.Iterable) and not isinstance(obj, ([2022/03/31 18:04:47] root INFO: Already save model in /home/aistudio/data/output_class/ConvNeXt_Tiny/epoch_1[2022/03/31 18:04:48] root INFO: Already save model in /home/aistudio/data/output_class/ConvNeXt_Tiny/latest[2022/03/31 18:04:50] root INFO: [Train][Epoch 2/5][Iter: 0/32]lr: 0.00012, CELoss: 1.99909, loss: 1.99909, batch_cost: 0.35991s, reader_cost: 0.06413, ips: 177.82215 images/sec, eta: 0:00:46[2022/03/31 18:04:53] root INFO: [Train][Epoch 2/5][Iter: 10/32]lr: 0.00012, CELoss: 1.79004, loss: 1.79004, batch_cost: 0.30007s, reader_cost: 0.00032, ips: 213.28602 images/sec, eta: 0:00:35[2022/03/31 18:04:56] root INFO: [Train][Epoch 2/5][Iter: 20/32]lr: 0.00012, CELoss: 1.59704, loss: 1.59704, batch_cost: 0.31246s, reader_cost: 0.00283, ips: 204.82522 images/sec, eta: 0:00:33[2022/03/31 18:04:59] root INFO: [Train][Epoch 2/5][Iter: 30/32]lr: 0.00011, CELoss: 1.41669, loss: 1.41669, batch_cost: 0.30708s, reader_cost: 0.00258, ips: 208.41727 images/sec, eta: 0:00:30[2022/03/31 18:05:00] root INFO: [Train][Epoch 2/5][Avg]CELoss: 1.41307, loss: 1.41307[2022/03/31 18:05:01] root INFO: [Eval][Epoch 2][Iter: 0/2]CELoss: 3.16468, loss: 3.16468, top1: 0.00000, top5: 0.06250, batch_cost: 1.35001s, reader_cost: 1.18088, ips: 94.81415 images/sec[2022/03/31 18:05:01] root INFO: [Eval][Epoch 2][Avg]CELoss: 3.16081, loss: 3.16081, top1: 0.00000, top5: 0.10063[2022/03/31 18:05:01] root INFO: [Eval][Epoch 2][best metric: 0.0][2022/03/31 18:05:02] root INFO: Already save model in /home/aistudio/data/output_class/ConvNeXt_Tiny/epoch_2[2022/03/31 18:05:03] root INFO: Already save model in /home/aistudio/data/output_class/ConvNeXt_Tiny/latest[2022/03/31 18:05:05] root INFO: [Train][Epoch 3/5][Iter: 0/32]lr: 0.00011, CELoss: 0.83580, loss: 0.83580, batch_cost: 0.35745s, reader_cost: 0.05875, ips: 179.04732 images/sec, eta: 0:00:34[2022/03/31 18:05:08] root INFO: [Train][Epoch 3/5][Iter: 10/32]lr: 0.00010, CELoss: 0.79101, loss: 0.79101, batch_cost: 0.30012s, reader_cost: 0.00047, ips: 213.25137 images/sec, eta: 0:00:25[2022/03/31 18:05:11] root INFO: [Train][Epoch 3/5][Iter: 20/32]lr: 0.00008, CELoss: 0.75128, loss: 0.75128, batch_cost: 0.29991s, reader_cost: 0.00046, ips: 213.39916 images/sec, eta: 0:00:22[2022/03/31 18:05:14] root INFO: [Train][Epoch 3/5][Iter: 30/32]lr: 0.00007, CELoss: 0.73154, loss: 0.73154, batch_cost: 0.29861s, reader_cost: 0.00047, ips: 214.32552 images/sec, eta: 0:00:19[2022/03/31 18:05:14] root INFO: [Train][Epoch 3/5][Avg]CELoss: 0.73081, loss: 0.73081[2022/03/31 18:05:15] root INFO: [Eval][Epoch 3][Iter: 0/2]CELoss: 2.32611, loss: 2.32611, top1: 0.03906, top5: 0.89844, batch_cost: 1.40323s, reader_cost: 1.22578, ips: 91.21806 images/sec[2022/03/31 18:05:16] root INFO: [Eval][Epoch 3][Avg]CELoss: 2.34307, loss: 2.34307, top1: 0.03774, top5: 0.89308[2022/03/31 18:05:17] root INFO: Already save model in /home/aistudio/data/output_class/ConvNeXt_Tiny/best_model[2022/03/31 18:05:17] root INFO: [Eval][Epoch 3][best metric: 0.03773584886916778][2022/03/31 18:05:18] root INFO: Already save model in /home/aistudio/data/output_class/ConvNeXt_Tiny/epoch_3[2022/03/31 18:05:19] root INFO: Already save model in /home/aistudio/data/output_class/ConvNeXt_Tiny/latest[2022/03/31 18:05:20] root INFO: [Train][Epoch 4/5][Iter: 0/32]lr: 0.00007, CELoss: 0.66662, loss: 0.66662, batch_cost: 0.33352s, reader_cost: 0.04039, ips: 191.89510 images/sec, eta: 0:00:21[2022/03/31 18:05:23] root INFO: [Train][Epoch 4/5][Iter: 10/32]lr: 0.00005, CELoss: 0.64193, loss: 0.64193, batch_cost: 0.33196s, reader_cost: 0.01953, ips: 192.79643 images/sec, eta: 0:00:17[2022/03/31 18:05:26] root INFO: [Train][Epoch 4/5][Iter: 20/32]lr: 0.00004, CELoss: 0.63435, loss: 0.63435, batch_cost: 0.31193s, reader_cost: 0.00752, ips: 205.17229 images/sec, eta: 0:00:13[2022/03/31 18:05:29] root INFO: [Train][Epoch 4/5][Iter: 30/32]lr: 0.00003, CELoss: 0.62602, loss: 0.62602, batch_cost: 0.30605s, reader_cost: 0.00473, ips: 209.11636 images/sec, eta: 0:00:10[2022/03/31 18:05:29] root INFO: [Train][Epoch 4/5][Avg]CELoss: 0.62564, loss: 0.62564[2022/03/31 18:05:31] root INFO: [Eval][Epoch 4][Iter: 0/2]CELoss: 1.86182, loss: 1.86182, top1: 0.25781, top5: 0.96875, batch_cost: 1.35239s, reader_cost: 1.18338, ips: 94.64708 images/sec[2022/03/31 18:05:31] root INFO: [Eval][Epoch 4][Avg]CELoss: 1.88848, loss: 1.88848, top1: 0.25157, top5: 0.96855[2022/03/31 18:05:32] root INFO: Already save model in /home/aistudio/data/output_class/ConvNeXt_Tiny/best_model[2022/03/31 18:05:32] root INFO: [Eval][Epoch 4][best metric: 0.25157232573197325][2022/03/31 18:05:33] root INFO: Already save model in /home/aistudio/data/output_class/ConvNeXt_Tiny/epoch_4[2022/03/31 18:05:34] root INFO: Already save model in /home/aistudio/data/output_class/ConvNeXt_Tiny/latest[2022/03/31 18:05:35] root INFO: [Train][Epoch 5/5][Iter: 0/32]lr: 0.00003, CELoss: 0.62709, loss: 0.62709, batch_cost: 0.34112s, reader_cost: 0.04507, ips: 187.61492 images/sec, eta: 0:00:10[2022/03/31 18:05:38] root INFO: [Train][Epoch 5/5][Iter: 10/32]lr: 0.00002, CELoss: 0.59784, loss: 0.59784, batch_cost: 0.31666s, reader_cost: 0.00276, ips: 202.10665 images/sec, eta: 0:00:06[2022/03/31 18:05:41] root INFO: [Train][Epoch 5/5][Iter: 20/32]lr: 0.00001, CELoss: 0.58959, loss: 0.58959, batch_cost: 0.31246s, reader_cost: 0.00219, ips: 204.82474 images/sec, eta: 0:00:03[2022/03/31 18:05:44] root INFO: [Train][Epoch 5/5][Iter: 30/32]lr: 0.00001, CELoss: 0.58536, loss: 0.58536, batch_cost: 0.30651s, reader_cost: 0.00157, ips: 208.80046 images/sec, eta: 0:00:00[2022/03/31 18:05:45] root INFO: [Train][Epoch 5/5][Avg]CELoss: 0.58511, loss: 0.58511[2022/03/31 18:05:46] root INFO: [Eval][Epoch 5][Iter: 0/2]CELoss: 1.68354, loss: 1.68354, top1: 0.29688, top5: 0.96094, batch_cost: 1.36943s, reader_cost: 1.19968, ips: 93.46979 images/sec[2022/03/31 18:05:46] root INFO: [Eval][Epoch 5][Avg]CELoss: 1.70561, loss: 1.70561, top1: 0.28931, top5: 0.96855[2022/03/31 18:05:47] root INFO: Already save model in /home/aistudio/data/output_class/ConvNeXt_Tiny/best_model[2022/03/31 18:05:47] root INFO: [Eval][Epoch 5][best metric: 0.289308174601141][2022/03/31 18:05:48] root INFO: Already save model in /home/aistudio/data/output_class/ConvNeXt_Tiny/epoch_5[2022/03/31 18:05:49] root INFO: Already save model in /home/aistudio/data/output_class/ConvNeXt_Tiny/latest登录后复制In [5]

# 将训练参数转移到best_model/class下, 进行长期保存!mkdir /home/aistudio/best_model!mkdir /home/aistudio/best_model/class!cp /home/aistudio/data/output_class/ConvNeXt_Tiny/best_model.pdparams /home/aistudio/best_model/class/model.pdparams登录后复制

图片推理

In [6]

# 结果保存在/home/aistudio/data/infer_class/result.csv下!python /home/aistudio/PaddleClas/tools/infer.py -c /home/aistudio/PaddleClas/convnext.yml -o Infer.batch_size=100 -o Infer.infer_imgs=/home/aistudio/data/data10954/cat_12_test/ -o Global.pretrained_model=/home/aistudio/best_model/class/model.pdparams登录后复制

[2022/03/31 18:05:53] root INFO: ============================================================= PaddleClas is powered by PaddlePaddle ! =============================================================== ==== For more info please go to the following website. ==== ==== https://github.com/PaddlePaddle/PaddleClas =============================================================[2022/03/31 18:05:53] root INFO: Arch : [2022/03/31 18:05:53] root INFO: class_num : 12[2022/03/31 18:05:53] root INFO: name : ConvNeXt_Tiny[2022/03/31 18:05:53] root INFO: DataLoader : [2022/03/31 18:05:53] root INFO: Eval : [2022/03/31 18:05:53] root INFO: dataset : [2022/03/31 18:05:53] root INFO: cls_label_path : /home/aistudio/data/data10954/val_list.txt[2022/03/31 18:05:53] root INFO: image_root : /home/aistudio/data/data10954/[2022/03/31 18:05:53] root INFO: name : ImageNetDataset[2022/03/31 18:05:53] root INFO: transform_ops : [2022/03/31 18:05:53] root INFO: DecodeImage : [2022/03/31 18:05:53] root INFO: channel_first : False[2022/03/31 18:05:53] root INFO: to_rgb : True[2022/03/31 18:05:53] root INFO: ResizeImage : [2022/03/31 18:05:53] root INFO: resize_short : 256[2022/03/31 18:05:53] root INFO: CropImage : [2022/03/31 18:05:53] root INFO: size : 224[2022/03/31 18:05:53] root INFO: NormalizeImage : [2022/03/31 18:05:53] root INFO: mean : [0.485, 0.456, 0.406][2022/03/31 18:05:53] root INFO: order : [2022/03/31 18:05:53] root INFO: scale : 1.0/255.0[2022/03/31 18:05:53] root INFO: std : [0.229, 0.224, 0.225][2022/03/31 18:05:53] root INFO: loader : [2022/03/31 18:05:53] root INFO: num_workers : 4[2022/03/31 18:05:53] root INFO: use_shared_memory : True[2022/03/31 18:05:53] root INFO: sampler : [2022/03/31 18:05:53] root INFO: batch_size : 128[2022/03/31 18:05:53] root INFO: drop_last : False[2022/03/31 18:05:53] root INFO: name : DistributedBatchSampler[2022/03/31 18:05:53] root INFO: shuffle : False[2022/03/31 18:05:53] root INFO: Train : [2022/03/31 18:05:53] root INFO: dataset : [2022/03/31 18:05:53] root INFO: cls_label_path : /home/aistudio/data/data10954/train_list.txt[2022/03/31 18:05:53] root INFO: image_root : /home/aistudio/data/data10954/[2022/03/31 18:05:53] root INFO: name : ImageNetDataset[2022/03/31 18:05:53] root INFO: transform_ops : [2022/03/31 18:05:53] root INFO: DecodeImage : [2022/03/31 18:05:53] root INFO: channel_first : False[2022/03/31 18:05:53] root INFO: to_rgb : True[2022/03/31 18:05:53] root INFO: RandomResizedCrop : [2022/03/31 18:05:53] root INFO: interpolation : bicubic[2022/03/31 18:05:53] root INFO: ratio : [1.0, 1.0][2022/03/31 18:05:53] root INFO: scale : [0.75, 1.0][2022/03/31 18:05:53] root INFO: size : 224[2022/03/31 18:05:53] root INFO: NormalizeImage : [2022/03/31 18:05:53] root INFO: mean : [0.485, 0.456, 0.406][2022/03/31 18:05:53] root INFO: order : [2022/03/31 18:05:53] root INFO: scale : 1.0/255.0[2022/03/31 18:05:53] root INFO: std : [0.229, 0.224, 0.225][2022/03/31 18:05:53] root INFO: loader : [2022/03/31 18:05:53] root INFO: num_workers : 4[2022/03/31 18:05:53] root INFO: use_shared_memory : True[2022/03/31 18:05:53] root INFO: sampler : [2022/03/31 18:05:53] root INFO: batch_size : 128[2022/03/31 18:05:53] root INFO: drop_last : False[2022/03/31 18:05:53] root INFO: name : DistributedBatchSampler[2022/03/31 18:05:53] root INFO: shuffle : True[2022/03/31 18:05:53] root INFO: Global : [2022/03/31 18:05:53] root INFO: checkpoints : None[2022/03/31 18:05:53] root INFO: device : gpu[2022/03/31 18:05:53] root INFO: epochs : 300[2022/03/31 18:05:53] root INFO: eval_during_train : True[2022/03/31 18:05:53] root INFO: eval_interval : 1[2022/03/31 18:05:53] root INFO: image_shape : [3, 300, 300][2022/03/31 18:05:53] root INFO: output_dir : /home/aistudio/data/output_class/[2022/03/31 18:05:53] root INFO: pretrained_model : /home/aistudio/best_model/class/model.pdparams[2022/03/31 18:05:53] root INFO: print_batch_step : 10[2022/03/31 18:05:53] root INFO: save_inference_dir : /home/aistudio/data/inference[2022/03/31 18:05:53] root INFO: save_interval : 1[2022/03/31 18:05:53] root INFO: use_visualdl : False[2022/03/31 18:05:53] root INFO: Infer : [2022/03/31 18:05:53] root INFO: PostProcess : [2022/03/31 18:05:53] root INFO: class_id_map_file : /home/aistudio/work/class/label_list.txt[2022/03/31 18:05:53] root INFO: name : Topk[2022/03/31 18:05:53] root INFO: topk : 5[2022/03/31 18:05:53] root INFO: batch_size : 100[2022/03/31 18:05:53] root INFO: infer_imgs : /home/aistudio/data/data10954/cat_12_test/[2022/03/31 18:05:53] root INFO: transforms : [2022/03/31 18:05:53] root INFO: DecodeImage : [2022/03/31 18:05:53] root INFO: channel_first : False[2022/03/31 18:05:53] root INFO: to_rgb : True[2022/03/31 18:05:53] root INFO: ResizeImage : [2022/03/31 18:05:53] root INFO: resize_short : 256[2022/03/31 18:05:53] root INFO: CropImage : [2022/03/31 18:05:53] root INFO: size : 224[2022/03/31 18:05:53] root INFO: NormalizeImage : [2022/03/31 18:05:53] root INFO: mean : [0.485, 0.456, 0.406][2022/03/31 18:05:53] root INFO: order : [2022/03/31 18:05:53] root INFO: scale : 1.0/255.0[2022/03/31 18:05:53] root INFO: std : [0.229, 0.224, 0.225][2022/03/31 18:05:53] root INFO: ToCHWImage : None[2022/03/31 18:05:53] root INFO: Loss : [2022/03/31 18:05:53] root INFO: Eval : [2022/03/31 18:05:53] root INFO: CELoss : [2022/03/31 18:05:53] root INFO: weight : 1.0[2022/03/31 18:05:53] root INFO: Train : [2022/03/31 18:05:53] root INFO: CELoss : [2022/03/31 18:05:53] root INFO: epsilon : 0.1[2022/03/31 18:05:53] root INFO: weight : 1.0[2022/03/31 18:05:53] root INFO: Metric : [2022/03/31 18:05:53] root INFO: Eval : [2022/03/31 18:05:53] root INFO: TopkAcc : [2022/03/31 18:05:53] root INFO: topk : [1, 5][2022/03/31 18:05:53] root INFO: Train : [2022/03/31 18:05:53] root INFO: TopkAcc : [2022/03/31 18:05:53] root INFO: topk : [1, 5][2022/03/31 18:05:53] root INFO: Optimizer : [2022/03/31 18:05:53] root INFO: beta1 : 0.9[2022/03/31 18:05:53] root INFO: beta2 : 0.999[2022/03/31 18:05:53] root INFO: lr : [2022/03/31 18:05:53] root INFO: epochs : 300[2022/03/31 18:05:53] root INFO: eta_min : 1e-05[2022/03/31 18:05:53] root INFO: learning_rate : 0.000125[2022/03/31 18:05:53] root INFO: name : Cosine[2022/03/31 18:05:53] root INFO: step_each_epoch : 1000[2022/03/31 18:05:53] root INFO: warmup_epoch : 20[2022/03/31 18:05:53] root INFO: warmup_start_lr : 1e-06[2022/03/31 18:05:53] root INFO: name : AdamW[2022/03/31 18:05:53] root INFO: weight_decay : 0.05[2022/03/31 18:05:53] root INFO: train with paddle 2.2.2 and device CUDAPlace(0)W0331 18:05:53.266223 642 device_context.cc:447] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 10.1, Runtime API Version: 10.1W0331 18:05:53.270807 642 device_context.cc:465] device: 0, cuDNN Version: 7.6.model loading : [182]/[182]infer process : 100%|████████████████████████| 240/240 [00:01<00:00, 128.35it/s]result save to /home/aistudio/data/infer_class/result.csv登录后复制

在PaddleSeg中使用ConvNeXt进行特征提取实现语义分割

——以“遥感影像地块分割”为例

参考 :?基于paddleSeg的自定义遥感数据语义分割——以DLRSD为例

并依据paddleseg中ocrNet_hrnetw48_cityscapes配置进行修改

环境准备

In [7]

# pip升级!pip install --user --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple# 下载仓库,并切换到2.3版本%cd /home/aistudio/!git clone https://gitee.com/paddlepaddle/PaddleSeg.git #该行仅在初次运行项目时运行即可,后续不需要运行改行命令%cd /home/aistudio/PaddleSeg!git checkout -b release/2.3 origin/release/2.3# 安装依赖!pip install -r requirements.txt登录后复制

Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simpleRequirement already satisfied: pip in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (22.0.4)/home/aistudio正克隆到 'PaddleSeg'...remote: Enumerating objects: 16439, done.remote: Counting objects: 100% (1402/1402), done.remote: Compressing objects: 100% (811/811), done.remote: Total 16439 (delta 710), reused 1166 (delta 573), pack-reused 15037接收对象中: 100% (16439/16439), 341.09 MiB | 14.09 MiB/s, 完成.处理 delta 中: 100% (10574/10574), 完成.检查连接... 完成。/home/aistudio/PaddleSeg分支 release/2.3 设置为跟踪来自 origin 的远程分支 release/2.3。切换到一个新分支 'release/2.3'Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simpleRequirement already satisfied: pre-commit in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 1)) (1.21.0)Requirement already satisfied: yapf==0.26.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 2)) (0.26.0)Requirement already satisfied: flake8 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 3)) (4.0.1)Requirement already satisfied: pyyaml>=5.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 4)) (5.1.2)Requirement already satisfied: visualdl>=2.0.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 5)) (2.2.3)Requirement already satisfied: opencv-python in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 6)) (4.4.0.46)Requirement already satisfied: tqdm in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 7)) (4.27.0)Requirement already satisfied: filelock in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 8)) (3.0.12)Requirement already satisfied: scipy in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 9)) (1.6.3)Requirement already satisfied: prettytable in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 10)) (0.7.2)Requirement already satisfied: cfgv>=2.0.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from pre-commit->-r requirements.txt (line 1)) (2.0.1)Requirement already satisfied: toml in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from pre-commit->-r requirements.txt (line 1)) (0.10.0)Requirement already satisfied: nodeenv>=0.11.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from pre-commit->-r requirements.txt (line 1)) (1.3.4)Requirement already satisfied: six in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from pre-commit->-r requirements.txt (line 1)) (1.16.0)Requirement already satisfied: virtualenv>=15.2 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from pre-commit->-r requirements.txt (line 1)) (16.7.9)Requirement already satisfied: aspy.yaml in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from pre-commit->-r requirements.txt (line 1)) (1.3.0)Requirement already satisfied: importlib-metadata in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from pre-commit->-r requirements.txt (line 1)) (4.2.0)Requirement already satisfied: identify>=1.0.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from pre-commit->-r requirements.txt (line 1)) (1.4.10)Requirement already satisfied: pycodestyle<2.9.0,>=2.8.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flake8->-r requirements.txt (line 3)) (2.8.0)Requirement already satisfied: pyflakes<2.5.0,>=2.4.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flake8->-r requirements.txt (line 3)) (2.4.0)Requirement already satisfied: mccabe<0.7.0,>=0.6.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flake8->-r requirements.txt (line 3)) (0.6.1)Requirement already satisfied: numpy in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.0.0->-r requirements.txt (line 5)) (1.19.5)Requirement already satisfied: Pillow>=7.0.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.0.0->-r requirements.txt (line 5)) (8.2.0)Requirement already satisfied: matplotlib in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.0.0->-r requirements.txt (line 5)) (2.2.3)Requirement already satisfied: requests in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.0.0->-r requirements.txt (line 5)) (2.24.0)Requirement already satisfied: pandas in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.0.0->-r requirements.txt (line 5)) (1.1.5)Requirement already satisfied: Flask-Babel>=1.0.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.0.0->-r requirements.txt (line 5)) (1.0.0)Requirement already satisfied: shellcheck-py in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.0.0->-r requirements.txt (line 5)) (0.7.1.1)Requirement already satisfied: flask>=1.1.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.0.0->-r requirements.txt (line 5)) (1.1.1)Requirement already satisfied: bce-python-sdk in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.0.0->-r requirements.txt (line 5)) (0.8.53)Requirement already satisfied: protobuf>=3.11.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.0.0->-r requirements.txt (line 5)) (3.14.0)Requirement already satisfied: itsdangerous>=0.24 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flask>=1.1.1->visualdl>=2.0.0->-r requirements.txt (line 5)) (1.1.0)Requirement already satisfied: Jinja2>=2.10.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flask>=1.1.1->visualdl>=2.0.0->-r requirements.txt (line 5)) (3.1.1)Requirement already satisfied: Werkzeug>=0.15 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flask>=1.1.1->visualdl>=2.0.0->-r requirements.txt (line 5)) (0.16.0)Requirement already satisfied: click>=5.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flask>=1.1.1->visualdl>=2.0.0->-r requirements.txt (line 5)) (7.0)Requirement already satisfied: Babel>=2.3 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from Flask-Babel>=1.0.0->visualdl>=2.0.0->-r requirements.txt (line 5)) (2.9.1)Requirement already satisfied: pytz in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from Flask-Babel>=1.0.0->visualdl>=2.0.0->-r requirements.txt (line 5)) (2022.1)Requirement already satisfied: zipp>=0.5 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from importlib-metadata->pre-commit->-r requirements.txt (line 1)) (3.7.0)Requirement already satisfied: typing-extensions>=3.6.4 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from importlib-metadata->pre-commit->-r requirements.txt (line 1)) (4.1.1)Requirement already satisfied: future>=0.6.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from bce-python-sdk->visualdl>=2.0.0->-r requirements.txt (line 5)) (0.18.0)Requirement already satisfied: pycryptodome>=3.8.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from bce-python-sdk->visualdl>=2.0.0->-r requirements.txt (line 5)) (3.9.9)Requirement already satisfied: python-dateutil>=2.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from matplotlib->visualdl>=2.0.0->-r requirements.txt (line 5)) (2.8.2)Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from matplotlib->visualdl>=2.0.0->-r requirements.txt (line 5)) (3.0.7)Requirement already satisfied: cycler>=0.10 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from matplotlib->visualdl>=2.0.0->-r requirements.txt (line 5)) (0.10.0)Requirement already satisfied: kiwisolver>=1.0.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from matplotlib->visualdl>=2.0.0->-r requirements.txt (line 5)) (1.1.0)Requirement already satisfied: idna<3,>=2.5 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests->visualdl>=2.0.0->-r requirements.txt (line 5)) (2.10)Requirement already satisfied: certifi>=2017.4.17 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests->visualdl>=2.0.0->-r requirements.txt (line 5)) (2021.10.8)Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests->visualdl>=2.0.0->-r requirements.txt (line 5)) (1.25.11)Requirement already satisfied: chardet<4,>=3.0.2 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests->visualdl>=2.0.0->-r requirements.txt (line 5)) (3.0.4)Requirement already satisfied: MarkupSafe>=2.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from Jinja2>=2.10.1->flask>=1.1.1->visualdl>=2.0.0->-r requirements.txt (line 5)) (2.0.1)Requirement already satisfied: setuptools in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from kiwisolver>=1.0.1->matplotlib->visualdl>=2.0.0->-r requirements.txt (line 5)) (56.2.0)登录后复制

数据准备

In [8]

!unzip -oq /home/aistudio/data/data77571/train_and_label.zip -d /home/aistudio/data/data77571/!unzip -oq /home/aistudio/data/data77571/img_test.zip -d /home/aistudio/data/data77571/登录后复制In [9]

# 生产数据集划分txt!python /home/aistudio/work/segmentation/data_split.py 0.98 0.02 0 /home/aistudio/data/data77571/img_train /home/aistudio/data/data77571/lab_train登录后复制

total 66652, split: train 65318 - 0.98 rate, val 1334 - 0.02 rate, test 0 - 0.00 rate登录后复制

代码准备

In [10]

# 以下代码及配置,基于PASSL中内容,并结合OCRNet18的配置进行迁移!cp /home/aistudio/work/segmentation/convnext.yml /home/aistudio/PaddleSeg/convnext.yml!cp /home/aistudio/work/segmentation/convnext.py /home/aistudio/PaddleSeg/paddleseg/models/backbones/convnext.py # 网络结构代码!cp /home/aistudio/work/segmentation/__init__.py /home/aistudio/PaddleSeg/paddleseg/models/backbones/__init__.py # 导入网络!cp /home/aistudio/work/segmentation/utils.py /home/aistudio/PaddleSeg/paddleseg/utils/utils.py # 加载tif数据与模型参数!cp /home/aistudio/work/segmentation/predict.py /home/aistudio/PaddleSeg/paddleseg/core/predict.py # 预测类别结果保存登录后复制

网络训练

In [11]

!python /home/aistudio/PaddleSeg/train.py --config /home/aistudio/PaddleSeg/convnext.yml --save_dir /home/aistudio/data/output_seg --do_eval --use_vdl --batch_size 64 --iters 300 --save_interval 100 --log_iters 20 --fp16登录后复制

/home/aistudio/PaddleSeg/paddleseg/models/losses/rmi_loss.py:78: DeprecationWarning: invalid escape sequence i ”“”2022-03-31 18:07:33 [INFO]------------Environment Information-------------platform: Linux-4.4.0-150-generic-x86_64-with-debian-stretch-sidPython: 3.7.4 (default, Aug 13 2019, 20:35:49) [GCC 7.3.0]Paddle compiled with cuda: TrueNVCC: Cuda compilation tools, release 10.1, V10.1.243cudnn: 7.6GPUs used: 1CUDA_VISIBLE_DEVICES: NoneGPU: ['GPU 0: Tesla V100-SXM2-16GB']GCC: gcc (Ubuntu 7.5.0-3ubuntu1~16.04) 7.5.0PaddlePaddle: 2.2.2OpenCV: 4.4.0------------------------------------------------2022-03-31 18:07:33 [INFO]---------------Config Information---------------batch_size: 64iters: 300loss: coef: - 1 - 0.4 types: - ignore_index: 255 type: CrossEntropyLoss - ignore_index: 255 type: CrossEntropyLosslr_scheduler: learning_rate: 0.00125 power: 0.9 type: PolynomialDecaymodel: backbone: class_num: 6 pretrained: https://passl.bj.bcebos.com/models/convnext_tiny_1k_224.pdparams type: ConvNeXt_Tiny backbone_indices: - 0 type: OCRNetoptimizer: type: sgdtrain_dataset: dataset_root: /home/aistudio/data/data77571/ mode: train num_classes: 7 train_path: /home/aistudio/data/data77571//train.txt transforms: - max_scale_factor: 2.0 min_scale_factor: 0.5 scale_step_size: 0.25 type: ResizeStepScaling - crop_size: - 256 - 256 type: RandomPaddingCrop - type: RandomHorizontalFlip - type: Normalize type: Datasetval_dataset: dataset_root: /home/aistudio/data/data77571/ mode: val num_classes: 7 transforms: - type: Normalize type: Dataset val_path: /home/aistudio/data/data77571//val.txt------------------------------------------------W0331 18:07:34.499039 829 device_context.cc:447] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 10.1, Runtime API Version: 10.1W0331 18:07:34.499097 829 device_context.cc:465] device: 0, cuDNN Version: 7.6.2022-03-31 18:07:39 [INFO]use amp to train/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/dygraph/math_op_patch.py:253: UserWarning: The dtype of left and right variables are not the same, left dtype is paddle.float16, but right dtype is paddle.float32, the right dtype will convert to paddle.float16 format(lhs_dtype, rhs_dtype, lhs_dtype))/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/dygraph/math_op_patch.py:253: UserWarning: The dtype of left and right variables are not the same, left dtype is paddle.float32, but right dtype is paddle.float16, the right dtype will convert to paddle.float32 format(lhs_dtype, rhs_dtype, lhs_dtype))/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/nn/layer/norm.py:653: UserWarning: When training, we now always track global mean and variance. “When training, we now always track global mean and variance.”)/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/dygraph/math_op_patch.py:253: UserWarning: The dtype of left and right variables are not the same, left dtype is paddle.float32, but right dtype is paddle.int64, the right dtype will convert to paddle.float32 format(lhs_dtype, rhs_dtype, lhs_dtype))2022-03-31 18:07:51 [INFO][TRAIN] epoch: 1, iter: 20/300, loss: 2.4015, lr: 0.001179, batch_cost: 0.6064, reader_cost: 0.25345, ips: 105.5410 samples/sec | ETA 00:02:492022-03-31 18:08:02 [INFO][TRAIN] epoch: 1, iter: 40/300, loss: 2.0847, lr: 0.001103, batch_cost: 0.5819, reader_cost: 0.23513, ips: 109.9897 samples/sec | ETA 00:02:312022-03-31 18:08:14 [INFO][TRAIN] epoch: 1, iter: 60/300, loss: 1.9073, lr: 0.001026, batch_cost: 0.5722, reader_cost: 0.22481, ips: 111.8435 samples/sec | ETA 00:02:172022-03-31 18:08:25 [INFO][TRAIN] epoch: 1, iter: 80/300, loss: 1.9318, lr: 0.000949, batch_cost: 0.5649, reader_cost: 0.22012, ips: 113.2866 samples/sec | ETA 00:02:042022-03-31 18:08:37 [INFO][TRAIN] epoch: 1, iter: 100/300, loss: 1.8939, lr: 0.000872, batch_cost: 0.5726, reader_cost: 0.22607, ips: 111.7723 samples/sec | ETA 00:01:542022-03-31 18:08:37 [INFO]Start evaluating (total_samples: 1334, total_iters: 1334)...1334/1334 [==============================] - 33s 24ms/step - batch_cost: 0.0243 - reader cost: 1.2418e-042022-03-31 18:09:09 [INFO][EVAL] #Images: 1334 mIoU: 0.1310 Acc: 0.4490 Kappa: 0.2189 2022-03-31 18:09:09 [INFO][EVAL] Class IoU: [0.3424 0.3964 0.1779 0. 0. 0. 0. ]2022-03-31 18:09:09 [INFO][EVAL] Class Acc: [0.4389 0.5091 0.3204 0. 0. 0. 0. ]2022-03-31 18:09:10 [INFO][EVAL] The model with the best validation mIoU (0.1310) was saved at iter 100.2022-03-31 18:09:20 [INFO][TRAIN] epoch: 1, iter: 120/300, loss: 1.8603, lr: 0.000793, batch_cost: 0.5013, reader_cost: 0.15525, ips: 127.6626 samples/sec | ETA 00:01:302022-03-31 18:09:32 [INFO][TRAIN] epoch: 1, iter: 140/300, loss: 1.7972, lr: 0.000714, batch_cost: 0.5840, reader_cost: 0.23824, ips: 109.5959 samples/sec | ETA 00:01:332022-03-31 18:09:43 [INFO][TRAIN] epoch: 1, iter: 160/300, loss: 1.8544, lr: 0.000634, batch_cost: 0.5719, reader_cost: 0.22721, ips: 111.9147 samples/sec | ETA 00:01:202022-03-31 18:09:55 [INFO][TRAIN] epoch: 1, iter: 180/300, loss: 1.8221, lr: 0.000552, batch_cost: 0.5771, reader_cost: 0.23047, ips: 110.9003 samples/sec | ETA 00:01:092022-03-31 18:10:06 [INFO][TRAIN] epoch: 1, iter: 200/300, loss: 1.8082, lr: 0.000469, batch_cost: 0.5988, reader_cost: 0.24987, ips: 106.8825 samples/sec | ETA 00:00:592022-03-31 18:10:06 [INFO]Start evaluating (total_samples: 1334, total_iters: 1334)...1334/1334 [==============================] - 32s 24ms/step - batch_cost: 0.0241 - reader cost: 9.0381e-052022-03-31 18:10:39 [INFO][EVAL] #Images: 1334 mIoU: 0.1478 Acc: 0.4874 Kappa: 0.2597 2022-03-31 18:10:39 [INFO][EVAL] Class IoU: [0.3592 0.422 0.0859 0.1673 0. 0. 0. ]2022-03-31 18:10:39 [INFO][EVAL] Class Acc: [0.4692 0.4845 0.5087 0.6331 0. 0. 0. ]2022-03-31 18:10:39 [INFO][EVAL] The model with the best validation mIoU (0.1478) was saved at iter 200.2022-03-31 18:10:50 [INFO][TRAIN] epoch: 1, iter: 220/300, loss: 1.7500, lr: 0.000385, batch_cost: 0.5090, reader_cost: 0.16244, ips: 125.7461 samples/sec | ETA 00:00:402022-03-31 18:11:02 [INFO][TRAIN] epoch: 1, iter: 240/300, loss: 1.7677, lr: 0.000298, batch_cost: 0.5957, reader_cost: 0.24562, ips: 107.4420 samples/sec | ETA 00:00:352022-03-31 18:11:13 [INFO][TRAIN] epoch: 1, iter: 260/300, loss: 1.7278, lr: 0.000208, batch_cost: 0.5890, reader_cost: 0.24190, ips: 108.6544 samples/sec | ETA 00:00:232022-03-31 18:11:25 [INFO][TRAIN] epoch: 1, iter: 280/300, loss: 1.7522, lr: 0.000114, batch_cost: 0.6062, reader_cost: 0.26048, ips: 105.5836 samples/sec | ETA 00:00:122022-03-31 18:11:38 [INFO][TRAIN] epoch: 1, iter: 300/300, loss: 1.7757, lr: 0.000007, batch_cost: 0.6104, reader_cost: 0.26477, ips: 104.8474 samples/sec | ETA 00:00:002022-03-31 18:11:38 [INFO]Start evaluating (total_samples: 1334, total_iters: 1334)...1334/1334 [==============================] - 33s 25ms/step - batch_cost: 0.0246 - reader cost: 9.6194e-052022-03-31 18:12:11 [INFO][EVAL] #Images: 1334 mIoU: 0.1765 Acc: 0.5187 Kappa: 0.3205 2022-03-31 18:12:11 [INFO][EVAL] Class IoU: [0.361 0.4712 0.2135 0.1899 0. 0. 0. ]2022-03-31 18:12:11 [INFO][EVAL] Class Acc: [0.4795 0.5663 0.4366 0.5706 0. 0. 0. ]2022-03-31 18:12:11 [INFO][EVAL] The model with the best validation mIoU (0.1765) was saved at iter 300.<class 'paddle.nn.layer.conv.Conv2D'>'s flops has been countedCannot find suitable count function for <class 'paddleseg.models.backbones.convnext.LayerNorm'>. Treat it as zero FLOPs.<class 'paddle.nn.layer.common.Linear'>'s flops has been countedCannot find suitable count function for <class 'paddle.nn.layer.activation.GELU'>. Treat it as zero FLOPs.Cannot find suitable count function for <class 'paddleseg.models.backbones.convnext.Identity'>. Treat it as zero FLOPs.Cannot find suitable count function for <class 'paddle.nn.layer.norm.LayerNorm'>. Treat it as zero FLOPs.Cannot find suitable count function for <class 'paddle.nn.layer.loss.CrossEntropyLoss'>. Treat it as zero FLOPs.Cannot find suitable count function for <class 'paddleseg.models.ocrnet.SpatialGatherBlock'>. Treat it as zero FLOPs.<class 'paddle.nn.layer.norm.BatchNorm2D'>'s flops has been counted<class 'paddle.nn.layer.activation.ReLU'>'s flops has been countedCannot find suitable count function for <class 'paddle.nn.layer.common.Dropout2D'>. Treat it as zero FLOPs.Total Flops: 11207499520 Total Params: 29462030登录后复制In [12]

# 将训练参数转移到best_model/seg下!mkdir /home/aistudio/best_model!mkdir /home/aistudio/best_model/seg!cp /home/aistudio/data/output_seg/best_model/model.pdparams /home/aistudio/best_model/seg/model.pdparams登录后复制

mkdir: 无法创建目录“/home/aistudio/best_model": 文件已存在登录后复制

图片推理

In [13]

# 结果保存在/home/aistudio/data/infer_seg下!python /home/aistudio/PaddleSeg/predict.py --config /home/aistudio/PaddleSeg/convnext.yml --model_path /home/aistudio/best_model/seg/model.pdparams --image_path /home/aistudio/data/data77571/img_testA --save_dir /home/aistudio/data/infer_seg登录后复制

2022-03-31 18:12:15 [INFO]---------------Config Information---------------batch_size: 4iters: 15000loss: coef: - 1 - 0.4 types: - type: CrossEntropyLoss - type: CrossEntropyLosslr_scheduler: learning_rate: 0.00125 power: 0.9 type: PolynomialDecaymodel: backbone: class_num: 6 pretrained: https://passl.bj.bcebos.com/models/convnext_tiny_1k_224.pdparams type: ConvNeXt_Tiny backbone_indices: - 0 type: OCRNetoptimizer: type: sgdtrain_dataset: dataset_root: /home/aistudio/data/data77571/ mode: train num_classes: 7 train_path: /home/aistudio/data/data77571//train.txt transforms: - max_scale_factor: 2.0 min_scale_factor: 0.5 scale_step_size: 0.25 type: ResizeStepScaling - crop_size: - 256 - 256 type: RandomPaddingCrop - type: RandomHorizontalFlip - type: Normalize type: Datasetval_dataset: dataset_root: /home/aistudio/data/data77571/ mode: val num_classes: 7 transforms: - type: Normalize type: Dataset val_path: /home/aistudio/data/data77571//val.txt------------------------------------------------W0331 18:12:16.364639 1223 device_context.cc:447] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 10.1, Runtime API Version: 10.1W0331 18:12:16.364699 1223 device_context.cc:465] device: 0, cuDNN Version: 7.6.2022-03-31 18:12:20 [INFO]Number of predict images = 46082022-03-31 18:12:20 [INFO]Loading pretrained model from /home/aistudio/best_model/seg/model.pdparams2022-03-31 18:12:20 [INFO]There are 240/240 variables loaded into OCRNet.2022-03-31 18:12:20 [INFO]Start to predict...4608/4608 [==============================] - 94s 20ms/step登录后复制

在PaddleDet中使用ConvNeXt进行特征提取实现目标检测

——以“钢铁缺陷检测挑战赛”为例

参考基于paddleDetection的自定义遥感数据目标检测——以RSOD为例

并基于PaddleDetection中的cascade_rcnn_r50_fpn_1x_coco配置进行修改

环境准备

In [14]

# pip升级!pip install --user --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple# 下载仓库,并切换到2.3版本%cd /home/aistudio/!git clone https://gitee.com/paddlepaddle/PaddleDetection.git%cd /home/aistudio/PaddleDetection!git checkout -b release/2.3 origin/release/2.3# 安装依赖!pip install -r requirements.txt登录后复制

Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simpleRequirement already satisfied: pip in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (22.0.4)/home/aistudio正克隆到 'PaddleDetection'...remote: Enumerating objects: 22586, done.remote: Counting objects: 100% (3056/3056), done.remote: Compressing objects: 100% (1496/1496), done.remote: Total 22586 (delta 2170), reused 2221 (delta 1553), pack-reused 19530接收对象中: 100% (22586/22586), 261.38 MiB | 21.95 MiB/s, 完成.处理 delta 中: 100% (16719/16719), 完成.检查连接... 完成。/home/aistudio/PaddleDetectionfatal: 一个分支名 'release/2.3' 已经存在。Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simpleRequirement already satisfied: tqdm in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 1)) (4.27.0)Collecting typeguard Downloading https://pypi.tuna.tsinghua.edu.cn/packages/9a/bb/d43e5c75054e53efce310e79d63df0ac3f25e34c926be5dffb7d283fb2a8/typeguard-2.13.3-py3-none-any.whl (17 kB)Requirement already satisfied: visualdl>=2.1.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 3)) (2.2.3)Requirement already satisfied: opencv-python in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 4)) (4.4.0.46)Requirement already satisfied: PyYAML in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 5)) (5.1.2)Collecting shapely Downloading https://pypi.tuna.tsinghua.edu.cn/packages/9d/4d/4b0d86ed737acb29c5e627a91449470a9fb914f32640db3f1cb7ba5bc19e/Shapely-1.8.1.post1-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (2.0 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.0/2.0 MB 1.3 MB/s eta 0:00:0000:0100:01Requirement already satisfied: scipy in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 7)) (1.6.3)Collecting terminaltables Downloading https://pypi.tuna.tsinghua.edu.cn/packages/c4/fb/ea621e0a19733e01fe4005d46087d383693c0f4a8f824b47d8d4122c87e0/terminaltables-3.1.10-py2.py3-none-any.whl (15 kB)Requirement already satisfied: Cython in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 9)) (0.29)Collecting pycocotools Downloading https://pypi.tuna.tsinghua.edu.cn/packages/75/5c/ac61ea715d7a89ecc31c090753bde28810238225ca8b71778dfe3e6a68bc/pycocotools-2.0.4.tar.gz (106 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 106.6/106.6 KB 1.1 MB/s eta 0:00:00a 0:00:01 Installing build dependencies ... done Getting requirements to build wheel ... done Preparing metadata (pyproject.toml) ... doneRequirement already satisfied: setuptools>=42.0.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 12)) (56.2.0)Collecting lap Downloading https://pypi.tuna.tsinghua.edu.cn/packages/bf/64/d9fb6a75b15e783952b2fec6970f033462e67db32dc43dfbb404c14e91c2/lap-0.4.0.tar.gz (1.5 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.5/1.5 MB 1.4 MB/s eta 0:00:00a 0:00:01 Preparing metadata (setup.py) ... doneRequirement already satisfied: sklearn in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 14)) (0.0)Collecting motmetrics Downloading https://pypi.tuna.tsinghua.edu.cn/packages/9c/28/9c3bc8e2a87f4c9e7b04ab72856ec7f9895a66681a65973ffaf9562ef879/motmetrics-1.2.0-py3-none-any.whl (151 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 151.6/151.6 KB 356.9 kB/s eta 0:00:00a 0:00:01Requirement already satisfied: openpyxl in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 16)) (3.0.5)Collecting cython_bbox Downloading https://pypi.tuna.tsinghua.edu.cn/packages/fa/b9/fc7d60e8c3b29cc0ff24a3bb3c4b7457e10b7610fbb2893741b623487b34/cython_bbox-0.1.3.tar.gz (41 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 41.3/41.3 KB 83.1 kB/s eta 0:00:00a 0:00:01 Preparing metadata (setup.py) ... doneRequirement already satisfied: requests in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.1.0->-r requirements.txt (line 3)) (2.24.0)Requirement already satisfied: pre-commit in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.1.0->-r requirements.txt (line 3)) (1.21.0)Requirement already satisfied: numpy in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.1.0->-r requirements.txt (line 3)) (1.19.5)Requirement already satisfied: Flask-Babel>=1.0.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.1.0->-r requirements.txt (line 3)) (1.0.0)Requirement already satisfied: Pillow>=7.0.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.1.0->-r requirements.txt (line 3)) (8.2.0)Requirement already satisfied: shellcheck-py in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.1.0->-r requirements.txt (line 3)) (0.7.1.1)Requirement already satisfied: flake8>=3.7.9 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.1.0->-r requirements.txt (line 3)) (4.0.1)Requirement already satisfied: bce-python-sdk in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.1.0->-r requirements.txt (line 3)) (0.8.53)Requirement already satisfied: flask>=1.1.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.1.0->-r requirements.txt (line 3)) (1.1.1)Requirement already satisfied: six>=1.14.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.1.0->-r requirements.txt (line 3)) (1.16.0)Requirement already satisfied: protobuf>=3.11.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.1.0->-r requirements.txt (line 3)) (3.14.0)Requirement already satisfied: pandas in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.1.0->-r requirements.txt (line 3)) (1.1.5)Requirement already satisfied: matplotlib in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.1.0->-r requirements.txt (line 3)) (2.2.3)Requirement already satisfied: scikit-learn in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from sklearn->-r requirements.txt (line 14)) (0.23.2)Collecting xmltodict>=0.12.0 Downloading https://pypi.tuna.tsinghua.edu.cn/packages/28/fd/30d5c1d3ac29ce229f6bdc40bbc20b28f716e8b363140c26eff19122d8a5/xmltodict-0.12.0-py2.py3-none-any.whl (9.2 kB)Collecting pytest-benchmark Downloading https://pypi.tuna.tsinghua.edu.cn/packages/2c/60/423a63fb190a0483d049786a121bd3dfd7d93bb5ff1bb5b5cd13e5df99a7/pytest_benchmark-3.4.1-py2.py3-none-any.whl (50 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 50.1/50.1 KB 143.6 kB/s eta 0:00:00a 0:00:01Collecting flake8-import-order Downloading https://pypi.tuna.tsinghua.edu.cn/packages/ab/52/cf2d6e2c505644ca06de2f6f3546f1e4f2b7be34246c9e0757c6048868f9/flake8_import_order-0.18.1-py2.py3-none-any.whl (15 kB)Collecting pytest Downloading https://pypi.tuna.tsinghua.edu.cn/packages/d2/ac/556e4410326ce77eeb1d1ec35a3e3ec847fb3e5cb30673729d2eeeffc970/pytest-7.1.1-py3-none-any.whl (297 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 297.0/297.0 KB 1.8 MB/s eta 0:00:00a 0:00:01Requirement already satisfied: jdcal in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from openpyxl->-r requirements.txt (line 16)) (1.4.1)Requirement already satisfied: et-xmlfile in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from openpyxl->-r requirements.txt (line 16)) (1.0.1)Requirement already satisfied: mccabe<0.7.0,>=0.6.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flake8>=3.7.9->visualdl>=2.1.0->-r requirements.txt (line 3)) (0.6.1)Requirement already satisfied: pyflakes<2.5.0,>=2.4.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flake8>=3.7.9->visualdl>=2.1.0->-r requirements.txt (line 3)) (2.4.0)Requirement already satisfied: pycodestyle<2.9.0,>=2.8.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flake8>=3.7.9->visualdl>=2.1.0->-r requirements.txt (line 3)) (2.8.0)Requirement already satisfied: importlib-metadata<4.3 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flake8>=3.7.9->visualdl>=2.1.0->-r requirements.txt (line 3)) (4.2.0)Requirement already satisfied: click>=5.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flask>=1.1.1->visualdl>=2.1.0->-r requirements.txt (line 3)) (7.0)Requirement already satisfied: Jinja2>=2.10.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flask>=1.1.1->visualdl>=2.1.0->-r requirements.txt (line 3)) (3.1.1)Requirement already satisfied: itsdangerous>=0.24 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flask>=1.1.1->visualdl>=2.1.0->-r requirements.txt (line 3)) (1.1.0)Requirement already satisfied: Werkzeug>=0.15 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flask>=1.1.1->visualdl>=2.1.0->-r requirements.txt (line 3)) (0.16.0)Requirement already satisfied: pytz in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from Flask-Babel>=1.0.0->visualdl>=2.1.0->-r requirements.txt (line 3)) (2022.1)Requirement already satisfied: Babel>=2.3 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from Flask-Babel>=1.0.0->visualdl>=2.1.0->-r requirements.txt (line 3)) (2.9.1)Requirement already satisfied: python-dateutil>=2.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from matplotlib->visualdl>=2.1.0->-r requirements.txt (line 3)) (2.8.2)Requirement already satisfied: cycler>=0.10 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from matplotlib->visualdl>=2.1.0->-r requirements.txt (line 3)) (0.10.0)Requirement already satisfied: kiwisolver>=1.0.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from matplotlib->visualdl>=2.1.0->-r requirements.txt (line 3)) (1.1.0)Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from matplotlib->visualdl>=2.1.0->-r requirements.txt (line 3)) (3.0.7)Requirement already satisfied: pycryptodome>=3.8.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from bce-python-sdk->visualdl>=2.1.0->-r requirements.txt (line 3)) (3.9.9)Requirement already satisfied: future>=0.6.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from bce-python-sdk->visualdl>=2.1.0->-r requirements.txt (line 3)) (0.18.0)Requirement already satisfied: toml in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from pre-commit->visualdl>=2.1.0->-r requirements.txt (line 3)) (0.10.0)Requirement already satisfied: virtualenv>=15.2 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from pre-commit->visualdl>=2.1.0->-r requirements.txt (line 3)) (16.7.9)Requirement already satisfied: aspy.yaml in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from pre-commit->visualdl>=2.1.0->-r requirements.txt (line 3)) (1.3.0)Requirement already satisfied: nodeenv>=0.11.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from pre-commit->visualdl>=2.1.0->-r requirements.txt (line 3)) (1.3.4)Requirement already satisfied: identify>=1.0.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from pre-commit->visualdl>=2.1.0->-r requirements.txt (line 3)) (1.4.10)Requirement already satisfied: cfgv>=2.0.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from pre-commit->visualdl>=2.1.0->-r requirements.txt (line 3)) (2.0.1)Collecting iniconfig Downloading https://pypi.tuna.tsinghua.edu.cn/packages/9b/dd/b3c12c6d707058fa947864b67f0c4e0c39ef8610988d7baea9578f3c48f3/iniconfig-1.1.1-py2.py3-none-any.whl (5.0 kB)Collecting tomli>=1.0.0 Downloading https://pypi.tuna.tsinghua.edu.cn/packages/97/75/10a9ebee3fd790d20926a90a2547f0bf78f371b2f13aa822c759680ca7b9/tomli-2.0.1-py3-none-any.whl (12 kB)Requirement already satisfied: packaging in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from pytest->motmetrics->-r requirements.txt (line 15)) (21.3)Requirement already satisfied: attrs>=19.2.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from pytest->motmetrics->-r requirements.txt (line 15)) (21.4.0)Collecting py>=1.8.2 Downloading https://pypi.tuna.tsinghua.edu.cn/packages/f6/f0/10642828a8dfb741e5f3fbaac830550a518a775c7fff6f04a007259b0548/py-1.11.0-py2.py3-none-any.whl (98 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 98.7/98.7 KB 1.8 MB/s eta 0:00:00a 0:00:01Requirement already satisfied: pluggy<2.0,>=0.12 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from pytest->motmetrics->-r requirements.txt (line 15)) (1.0.0)Collecting py-cpuinfo Downloading https://pypi.tuna.tsinghua.edu.cn/packages/e6/ba/77120e44cbe9719152415b97d5bfb29f4053ee987d6cb63f55ce7d50fadc/py-cpuinfo-8.0.0.tar.gz (99 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 99.8/99.8 KB 2.0 MB/s eta 0:00:00a 0:00:01 Preparing metadata (setup.py) ... doneRequirement already satisfied: certifi>=2017.4.17 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests->visualdl>=2.1.0->-r requirements.txt (line 3)) (2021.10.8)Requirement already satisfied: idna<3,>=2.5 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests->visualdl>=2.1.0->-r requirements.txt (line 3)) (2.10)Requirement already satisfied: chardet<4,>=3.0.2 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests->visualdl>=2.1.0->-r requirements.txt (line 3)) (3.0.4)Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests->visualdl>=2.1.0->-r requirements.txt (line 3)) (1.25.11)Requirement already satisfied: joblib>=0.11 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from scikit-learn->sklearn->-r requirements.txt (line 14)) (0.14.1)Requirement already satisfied: threadpoolctl>=2.0.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from scikit-learn->sklearn->-r requirements.txt (line 14)) (2.1.0)Requirement already satisfied: zipp>=0.5 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from importlib-metadata<4.3->flake8>=3.7.9->visualdl>=2.1.0->-r requirements.txt (line 3)) (3.7.0)Requirement already satisfied: typing-extensions>=3.6.4 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from importlib-metadata<4.3->flake8>=3.7.9->visualdl>=2.1.0->-r requirements.txt (line 3)) (4.1.1)Requirement already satisfied: MarkupSafe>=2.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from Jinja2>=2.10.1->flask>=1.1.1->visualdl>=2.1.0->-r requirements.txt (line 3)) (2.0.1)Building wheels for collected packages: pycocotools, lap, cython_bbox, py-cpuinfo Building wheel for pycocotools (pyproject.toml) ... done Created wheel for pycocotools: filename=pycocotools-2.0.4-cp37-cp37m-linux_x86_64.whl size=273791 sha256=fd172b501e11eb7b5cab0c7a964ea5bcdef6a9c34f6b6218f3ce1e249d525f94 Stored in directory: /home/aistudio/.cache/pip/wheels/c0/01/5f/670dfd20204fc9cc6bf843db4e014acb998f411922e3abc49f Building wheel for lap (setup.py) ... done Created wheel for lap: filename=lap-0.4.0-cp37-cp37m-linux_x86_64.whl size=1593869 sha256=e1594e0faa842d48e5298391cf6c31a524ef994237e207cffd8bd9a349b1a4d7 Stored in directory: /home/aistudio/.cache/pip/wheels/5c/d0/d2/e331d17a999666b1e2eb99743cfa1742629f9d26c55c657001 Building wheel for cython_bbox (setup.py) ... done Created wheel for cython_bbox: filename=cython_bbox-0.1.3-cp37-cp37m-linux_x86_64.whl size=61616 sha256=4b96ff009e6e57519f08ecb3933a90bb7a3fe8a5871895b2413bd2b34776d3f9 Stored in directory: /home/aistudio/.cache/pip/wheels/3e/b3/6a/aae8832326545645e65d643a2aaf223ffa3a7d01e1a1bae01b Building wheel for py-cpuinfo (setup.py) ... done Created wheel for py-cpuinfo: filename=py_cpuinfo-8.0.0-py3-none-any.whl size=22245 sha256=57e7cd6511fd6311cf3475238e062d6cce6847a86622de76be1311bf2ae4ba46 Stored in directory: /home/aistudio/.cache/pip/wheels/88/c7/d0/6309c7cc9929894c11fe8e516c3e2a0d0a53ee4e198eac48b7Successfully built pycocotools lap cython_bbox py-cpuinfoInstalling collected packages: py-cpuinfo, lap, iniconfig, cython_bbox, xmltodict, typeguard, tomli, terminaltables, shapely, py, flake8-import-order, pytest, pycocotools, pytest-benchmark, motmetricsSuccessfully installed cython_bbox-0.1.3 flake8-import-order-0.18.1 iniconfig-1.1.1 lap-0.4.0 motmetrics-1.2.0 py-1.11.0 py-cpuinfo-8.0.0 pycocotools-2.0.4 pytest-7.1.1 pytest-benchmark-3.4.1 shapely-1.8.1.post1 terminaltables-3.1.10 tomli-2.0.1 typeguard-2.13.3 xmltodict-0.12.0登录后复制

数据准备

In [15]

# 因项目数据集挂载数量的限制,使用wget进行数据下载!wget -P /home/aistudio/data https://bj.bcebos.com/v1/ai-studio-online/0c57afdf4ab44f00991b96550a84739340f6ec8232dd40b4873d94a690e17eb0?responseContentDisposition=attachment%3B%20filename%3Dsteel_bug_detect.zip登录后复制

--2022-03-31 18:15:22-- https://bj.bcebos.com/v1/ai-studio-online/0c57afdf4ab44f00991b96550a84739340f6ec8232dd40b4873d94a690e17eb0?responseContentDisposition=attachment%3B%20filename%3Dsteel_bug_detect.zip正在解析主机 bj.bcebos.com (bj.bcebos.com)... 182.61.200.195, 182.61.200.229, 2409:8c04:1001:1002:0:ff:b001:368a正在连接 bj.bcebos.com (bj.bcebos.com)|182.61.200.195|:443... 已连接。已发出 HTTP 请求,正在等待回应... 200 OK长度: 27472366 (26M) [application/octet-stream]正在保存至: “/home/aistudio/data/0c57afdf4ab44f00991b96550a84739340f6ec8232dd40b4873d94a690e17eb0?responseContentDisposition=attachment%3B%20filename%3Dsteel_bug_detect.zip”0c57afdf4ab44f00991 100%[===================>] 26.20M 25.9MB/s in 1.0s 2022-03-31 18:15:23 (25.9 MB/s) - 已保存 “/home/aistudio/data/0c57afdf4ab44f00991b96550a84739340f6ec8232dd40b4873d94a690e17eb0?responseContentDisposition=attachment%3B%20filename%3Dsteel_bug_detect.zip” [27472366/27472366])登录后复制In [16]

!unzip -oq /home/aistudio/data/0c57afdf4ab44f00991b96550a84739340f6ec8232dd40b4873d94a690e17eb0?responseContentDisposition=attachment%3B%20filename%3Dsteel_bug_detect.zip -d /home/aistudio/data/data113944/登录后复制

代码准备

In [17]

# 以下代码及配置,基于PASSL中内容,并结合cascade_rcnn_r50_fpn_1x_coco的配置进行迁移!cp /home/aistudio/work/detection/convnext.yml /home/aistudio/PaddleDetection/convnext.yml!cp /home/aistudio/work/detection/convnext.py /home/aistudio/PaddleDetection/ppdet/modeling/backbones/convnext.py!cp /home/aistudio/work/detection/__init__.py /home/aistudio/PaddleDetection/ppdet/modeling/backbones/__init__.py # 导入网络登录后复制

网络训练

In [?]

# 以test为训练集,训练cascade rcnn convnext 2 epoch!python /home/aistudio/PaddleDetection/tools/train.py -c /home/aistudio/PaddleDetection/convnext.yml --eval --fp16 --use_vdl=true -o epoch=3登录后复制

Warning: import ppdet from source directory without installing, run 'python setup.py install' to install ppdet firstlyW0331 18:16:29.811268 1844 device_context.cc:447] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 10.1, Runtime API Version: 10.1W0331 18:16:29.836920 1844 device_context.cc:465] device: 0, cuDNN Version: 7.6.[03/31 18:16:32] ppdet.utils.download INFO: Downloading convnext_tiny_1k_224.pdparams from https://passl.bj.bcebos.com/models/convnext_tiny_1k_224.pdparams100%|████████████████████████████████| 111694/111694 [00:05<00:00, 18745.04KB/s][03/31 18:16:39] ppdet.utils.checkpoint INFO: The shape [1000] in pretrained weight head.fc_cls.bias is unmatched with the shape [1] in model backbone.head.fc_cls.bias. And the weight head.fc_cls.bias will not be loaded[03/31 18:16:39] ppdet.utils.checkpoint INFO: The shape [768, 1000] in pretrained weight head.fc_cls.weight is unmatched with the shape [768, 1] in model backbone.head.fc_cls.weight. And the weight head.fc_cls.weight will not be loaded[03/31 18:16:39] ppdet.utils.checkpoint INFO: Finish loading model weights: /home/aistudio/.cache/paddle/weights/convnext_tiny_1k_224.pdparams[03/31 18:16:39] ppdet.engine INFO: Epoch: [0] [ 0/126] learning_rate: 0.000010 loss_rpn_cls: 0.868715 loss_rpn_reg: 1.379543 loss_bbox_cls_stage0: 2.675596 loss_bbox_reg_stage0: 0.007741 loss_bbox_cls_stage1: 1.309931 loss_bbox_reg_stage1: 0.010101 loss_bbox_cls_stage2: 2.300117 loss_bbox_reg_stage2: 0.009881 loss: 8.561625 eta: 0:01:12 batch_cost: 0.1926 data_cost: 0.0003 ips: 5.1914 images/s[03/31 18:16:42] ppdet.engine INFO: Epoch: [0] [ 20/126] learning_rate: 0.000210 loss_rpn_cls: 0.177607 loss_rpn_reg: 0.209631 loss_bbox_cls_stage0: 0.226774 loss_bbox_reg_stage0: 0.020316 loss_bbox_cls_stage1: 0.114375 loss_bbox_reg_stage1: 0.019034 loss_bbox_cls_stage2: 0.126810 loss_bbox_reg_stage2: 0.013394 loss: 1.188014 eta: 0:00:49 batch_cost: 0.1349 data_cost: 0.0003 ips: 7.4117 images/s[03/31 18:16:44] ppdet.engine INFO: Epoch: [0] [ 40/126] learning_rate: 0.000410 loss_rpn_cls: 0.187713 loss_rpn_reg: 0.106287 loss_bbox_cls_stage0: 0.183981 loss_bbox_reg_stage0: 0.041466 loss_bbox_cls_stage1: 0.062141 loss_bbox_reg_stage1: 0.023217 loss_bbox_cls_stage2: 0.060378 loss_bbox_reg_stage2: 0.007851 loss: 0.779464 eta: 0:00:46 batch_cost: 0.1347 data_cost: 0.0003 ips: 7.4215 images/s[03/31 18:16:47] ppdet.engine INFO: Epoch: [0] [ 60/126] learning_rate: 0.000609 loss_rpn_cls: 0.151224 loss_rpn_reg: 0.093652 loss_bbox_cls_stage0: 0.095361 loss_bbox_reg_stage0: 0.028566 loss_bbox_cls_stage1: 0.033791 loss_bbox_reg_stage1: 0.014273 loss_bbox_cls_stage2: 0.037734 loss_bbox_reg_stage2: 0.010816 loss: 0.551668 eta: 0:00:42 batch_cost: 0.1266 data_cost: 0.0003 ips: 7.8990 images/s[03/31 18:16:50] ppdet.engine INFO: Epoch: [0] [ 80/126] learning_rate: 0.000809 loss_rpn_cls: 0.121782 loss_rpn_reg: 0.047220 loss_bbox_cls_stage0: 0.093039 loss_bbox_reg_stage0: 0.053310 loss_bbox_cls_stage1: 0.048381 loss_bbox_reg_stage1: 0.032904 loss_bbox_cls_stage2: 0.033058 loss_bbox_reg_stage2: 0.014520 loss: 0.498449 eta: 0:00:39 batch_cost: 0.1245 data_cost: 0.0003 ips: 8.0348 images/s[03/31 18:16:52] ppdet.engine INFO: Epoch: [0] [100/126] learning_rate: 0.001009 loss_rpn_cls: 0.130423 loss_rpn_reg: 0.055140 loss_bbox_cls_stage0: 0.070923 loss_bbox_reg_stage0: 0.041984 loss_bbox_cls_stage1: 0.035746 loss_bbox_reg_stage1: 0.026651 loss_bbox_cls_stage2: 0.025823 loss_bbox_reg_stage2: 0.014539 loss: 0.459595 eta: 0:00:36 batch_cost: 0.1316 data_cost: 0.0003 ips: 7.5960 images/s[03/31 18:16:55] ppdet.engine INFO: Epoch: [0] [120/126] learning_rate: 0.001209 loss_rpn_cls: 0.152737 loss_rpn_reg: 0.050989 loss_bbox_cls_stage0: 0.073883 loss_bbox_reg_stage0: 0.046244 loss_bbox_cls_stage1: 0.035809 loss_bbox_reg_stage1: 0.027861 loss_bbox_cls_stage2: 0.022346 loss_bbox_reg_stage2: 0.010038 loss: 0.573754 eta: 0:00:33 batch_cost: 0.1301 data_cost: 0.0003 ips: 7.6887 images/s[03/31 18:16:57] ppdet.utils.checkpoint INFO: Save checkpoint: /home/aistudio/data/output_det/convnext[03/31 18:16:58] ppdet.engine INFO: Eval iter: 0[03/31 18:16:58] ppdet.metrics.metrics INFO: Accumulating evaluatation results...[03/31 18:16:58] ppdet.metrics.metrics INFO: mAP(0.50, 11point) = 2.77%[03/31 18:16:58] ppdet.engine INFO: Total sample number: 14, averge FPS: 14.486713457165575[03/31 18:16:58] ppdet.engine INFO: Best test bbox ap is 0.028.登录后复制In [?]

# 将推理结果转移到best_model/det下!mkdir /home/aistudio/best_model!mkdir /home/aistudio/best_model/det!cp /home/aistudio/data/output_det/convnext/best_model.pdparams /home/aistudio/best_model/det/model.pdparams登录后复制

图片推理

In [?]

# 预测结果保存在 PaddleDetection/bbox.json!python /home/aistudio/PaddleDetection/tools/infer.py -c /home/aistudio/PaddleDetection/convnext.yml --infer_dir=/home/aistudio/data/data113944/steel_bug_detect/test/IMAGES --output_dir=/home/aistudio/data/infer_det/ --draw_threshold=0.5 -o weights=/home/aistudio/best_model/det/model.pdparams --save_txt=true登录后复制

福利游戏

相关文章

更多

精选合集

更多

大家都在玩

热门话题

大家都在看

更多