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


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

☞☞☞AI 智能聊天, 问答助手, AI 智能搜索, 免费无限量使用 DeepSeek R1 模型☜☜☜

项目背景

本项目首先摘抄了ConvNeXt论文的观点内容


然后通过代码实现了:

  • ConvNeXt嵌入到PaddleClas、PaddleSeg、PaddleDetection等工具包中,
  • 加载预训练参数
  • 快速进行训练少量轮数
  • 推理得到预测结果

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

《A ConvNet for the 2025s》

time:

release in 2025.01

read in 2025.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%)√:

  • 300epoch
  • adamw
  • mixup
  • cutmix
  • randaugment
  • random erasing
  • label smoothing
  • Stochastic Depth

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倍

如上图,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模块、瓶颈倒置模块、深度卷积提前模块

这一操作也显著降低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%)√

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对比通道架构的Swin处理速度略快,精度高

此外还附有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/simple
Requirement 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/PaddleClas
fatal: 一个分支名 'release/2.3' 已经存在。
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Requirement 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:01
Requirement 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:01
Requirement 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:01
Requirement 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)) (2025.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)) (2025.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.2
Successfully 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!
[2025/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      ==
===========================================================

[2025/03/31 18:04:25] root INFO: Arch : 
[2025/03/31 18:04:25] root INFO:     class_num : 12
[2025/03/31 18:04:25] root INFO:     name : ConvNeXt_Tiny
[2025/03/31 18:04:25] root INFO: DataLoader : 
[2025/03/31 18:04:25] root INFO:     Eval : 
[2025/03/31 18:04:25] root INFO:         dataset : 
[2025/03/31 18:04:25] root INFO:             cls_label_path : /home/aistudio/data/data10954/val_list.txt
[2025/03/31 18:04:25] root INFO:             image_root : /home/aistudio/data/data10954/
[2025/03/31 18:04:25] root INFO:             name : ImageNetDataset
[2025/03/31 18:04:25] root INFO:             transform_ops : 
[2025/03/31 18:04:25] root INFO:                 DecodeImage : 
[2025/03/31 18:04:25] root INFO:                     channel_first : False
[2025/03/31 18:04:25] root INFO:                     to_rgb : True
[2025/03/31 18:04:25] root INFO:                 ResizeImage : 
[2025/03/31 18:04:25] root INFO:                     resize_short : 256
[2025/03/31 18:04:25] root INFO:                 CropImage : 
[2025/03/31 18:04:25] root INFO:                     size : 224
[2025/03/31 18:04:25] root INFO:                 NormalizeImage : 
[2025/03/31 18:04:25] root INFO:                     mean : [0.485, 0.456, 0.406]
[2025/03/31 18:04:25] root INFO:                     order : 
[2025/03/31 18:04:25] root INFO:                     scale : 1.0/255.0
[2025/03/31 18:04:25] root INFO:                     std : [0.229, 0.224, 0.225]
[2025/03/31 18:04:25] root INFO:         loader : 
[2025/03/31 18:04:25] root INFO:             num_workers : 4
[2025/03/31 18:04:25] root INFO:             use_shared_memory : True
[2025/03/31 18:04:25] root INFO:         sampler : 
[2025/03/31 18:04:25] root INFO:             batch_size : 128
[2025/03/31 18:04:25] root INFO:             drop_last : False
[2025/03/31 18:04:25] root INFO:             name : DistributedBatchSampler
[2025/03/31 18:04:25] root INFO:             shuffle : False
[2025/03/31 18:04:25] root INFO:     Train : 
[2025/03/31 18:04:25] root INFO:         dataset : 
[2025/03/31 18:04:25] root INFO:             cls_label_path : /home/aistudio/data/data10954/train_list.txt
[2025/03/31 18:04:25] root INFO:             image_root : /home/aistudio/data/data10954/
[2025/03/31 18:04:25] root INFO:             name : ImageNetDataset
[2025/03/31 18:04:25] root INFO:             transform_ops : 
[2025/03/31 18:04:25] root INFO:                 DecodeImage : 
[2025/03/31 18:04:25] root INFO:                     channel_first : False
[2025/03/31 18:04:25] root INFO:                     to_rgb : True
[2025/03/31 18:04:25] root INFO:                 RandomResizedCrop : 
[2025/03/31 18:04:25] root INFO:                     interpolation : bicubic
[2025/03/31 18:04:25] root INFO:                     ratio : [1.0, 1.0]
[2025/03/31 18:04:25] root INFO:                     scale : [0.75, 1.0]
[2025/03/31 18:04:25] root INFO:                     size : 224
[2025/03/31 18:04:25] root INFO:                 NormalizeImage : 
[2025/03/31 18:04:25] root INFO:                     mean : [0.485, 0.456, 0.406]
[2025/03/31 18:04:25] root INFO:                     order : 
[2025/03/31 18:04:25] root INFO:                     scale : 1.0/255.0
[2025/03/31 18:04:25] root INFO:                     std : [0.229, 0.224, 0.225]
[2025/03/31 18:04:25] root INFO:         loader : 
[2025/03/31 18:04:25] root INFO:             num_workers : 4
[2025/03/31 18:04:25] root INFO:             use_shared_memory : True
[2025/03/31 18:04:25] root INFO:         sampler : 
[2025/03/31 18:04:25] root INFO:             batch_size : 64
[2025/03/31 18:04:25] root INFO:             drop_last : False
[2025/03/31 18:04:25] root INFO:             name : DistributedBatchSampler
[2025/03/31 18:04:25] root INFO:             shuffle : True
[2025/03/31 18:04:25] root INFO: Global : 
[2025/03/31 18:04:25] root INFO:     checkpoints : None
[2025/03/31 18:04:25] root INFO:     device : gpu
[2025/03/31 18:04:25] root INFO:     epochs : 5
[2025/03/31 18:04:25] root INFO:     eval_during_train : True
[2025/03/31 18:04:25] root INFO:     eval_interval : 1
[2025/03/31 18:04:25] root INFO:     image_shape : [3, 300, 300]
[2025/03/31 18:04:25] root INFO:     output_dir : /home/aistudio/data/output_class/
[2025/03/31 18:04:25] root INFO:     pretrained_model : https://passl.bj.bcebos.com/models/convnext_tiny_1k_224.pdparams
[2025/03/31 18:04:25] root INFO:     print_batch_step : 10
[2025/03/31 18:04:25] root INFO:     save_inference_dir : /home/aistudio/data/inference
[2025/03/31 18:04:25] root INFO:     save_interval : 1
[2025/03/31 18:04:25] root INFO:     use_visualdl : False
[2025/03/31 18:04:25] root INFO: Infer : 
[2025/03/31 18:04:25] root INFO:     PostProcess : 
[2025/03/31 18:04:25] root INFO:         class_id_map_file : /home/aistudio/work/class/label_list.txt
[2025/03/31 18:04:25] root INFO:         name : Topk
[2025/03/31 18:04:25] root INFO:         topk : 5
[2025/03/31 18:04:25] root INFO:     batch_size : 100
[2025/03/31 18:04:25] root INFO:     infer_imgs : docs/images/inference_deployment/whl_demo.jpg
[2025/03/31 18:04:25] root INFO:     transforms : 
[2025/03/31 18:04:25] root INFO:         DecodeImage : 
[2025/03/31 18:04:25] root INFO:             channel_first : False
[2025/03/31 18:04:25] root INFO:             to_rgb : True
[2025/03/31 18:04:25] root INFO:         ResizeImage : 
[2025/03/31 18:04:25] root INFO:             resize_short : 256
[2025/03/31 18:04:25] root INFO:         CropImage : 
[2025/03/31 18:04:25] root INFO:             size : 224
[2025/03/31 18:04:25] root INFO:         NormalizeImage : 
[2025/03/31 18:04:25] root INFO:             mean : [0.485, 0.456, 0.406]
[2025/03/31 18:04:25] root INFO:             order : 
[2025/03/31 18:04:25] root INFO:             scale : 1.0/255.0
[2025/03/31 18:04:25] root INFO:             std : [0.229, 0.224, 0.225]
[2025/03/31 18:04:25] root INFO:         ToCHWImage : None
[2025/03/31 18:04:25] root INFO: Loss : 
[2025/03/31 18:04:25] root INFO:     Eval : 
[2025/03/31 18:04:25] root INFO:         CELoss : 
[2025/03/31 18:04:25] root INFO:             weight : 1.0
[2025/03/31 18:04:25] root INFO:     Train : 
[2025/03/31 18:04:25] root INFO:         CELoss : 
[2025/03/31 18:04:25] root INFO:             epsilon : 0.1
[2025/03/31 18:04:25] root INFO:             weight : 1.0
[2025/03/31 18:04:25] root INFO: Metric : 
[2025/03/31 18:04:25] root INFO:     Eval : 
[2025/03/31 18:04:25] root INFO:         TopkAcc : 
[2025/03/31 18:04:25] root INFO:             topk : [1, 5]
[2025/03/31 18:04:25] root INFO:     Train : 
[2025/03/31 18:04:25] root INFO:         TopkAcc : 
[2025/03/31 18:04:25] root INFO:             topk : [1, 5]
[2025/03/31 18:04:25] root INFO: Optimizer : 
[2025/03/31 18:04:25] root INFO:     beta1 : 0.9
[2025/03/31 18:04:25] root INFO:     beta2 : 0.999
[2025/03/31 18:04:25] root INFO:     lr : 
[2025/03/31 18:04:25] root INFO:         epoch : 5
[2025/03/31 18:04:25] root INFO:         epochs : 300
[2025/03/31 18:04:25] root INFO:         eta_min : 1e-05
[2025/03/31 18:04:25] root INFO:         learning_rate : 0.000125
[2025/03/31 18:04:25] root INFO:         name : Cosine
[2025/03/31 18:04:25] root INFO:         step_each_epoch : 32
[2025/03/31 18:04:25] root INFO:         warmup_epoch : 1
[2025/03/31 18:04:25] root INFO:         warmup_start_lr : 1e-06
[2025/03/31 18:04:25] root INFO:     name : AdamW
[2025/03/31 18:04:25] root INFO:     weight_decay : 0.05
[2025/03/31 18:04:25] root INFO: profiler_options : None
[2025/03/31 18:04:25] root INFO: train with paddle 2.2.2 and device CUDAPlace(0)
[2025/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.1
W0331 18:04:25.974506   303 device_context.cc:465] device: 0, cuDNN Version: 7.6.
[2025/03/31 18:04:30] root INFO: unique_endpoints {''}
[2025/03/31 18:04:30] root INFO: Downloading convnext_tiny_1k_224.pdparams from https://passl.bj.bcebos.com/models/convnext_tiny_1k_224.pdparams
100%|████████████████████████████████| 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.31241246s, 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.31241246s, 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
[2025/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      ==
===========================================================

[2025/03/31 18:05:53] root INFO: Arch : 
[2025/03/31 18:05:53] root INFO:     class_num : 12
[2025/03/31 18:05:53] root INFO:     name : ConvNeXt_Tiny
[2025/03/31 18:05:53] root INFO: DataLoader : 
[2025/03/31 18:05:53] root INFO:     Eval : 
[2025/03/31 18:05:53] root INFO:         dataset : 
[2025/03/31 18:05:53] root INFO:             cls_label_path : /home/aistudio/data/data10954/val_list.txt
[2025/03/31 18:05:53] root INFO:             image_root : /home/aistudio/data/data10954/
[2025/03/31 18:05:53] root INFO:             name : ImageNetDataset
[2025/03/31 18:05:53] root INFO:             transform_ops : 
[2025/03/31 18:05:53] root INFO:                 DecodeImage : 
[2025/03/31 18:05:53] root INFO:                     channel_first : False
[2025/03/31 18:05:53] root INFO:                     to_rgb : True
[2025/03/31 18:05:53] root INFO:                 ResizeImage : 
[2025/03/31 18:05:53] root INFO:                     resize_short : 256
[2025/03/31 18:05:53] root INFO:                 CropImage : 
[2025/03/31 18:05:53] root INFO:                     size : 224
[2025/03/31 18:05:53] root INFO:                 NormalizeImage : 
[2025/03/31 18:05:53] root INFO:                     mean : [0.485, 0.456, 0.406]
[2025/03/31 18:05:53] root INFO:                     order : 
[2025/03/31 18:05:53] root INFO:                     scale : 1.0/255.0
[2025/03/31 18:05:53] root INFO:                     std : [0.229, 0.224, 0.225]
[2025/03/31 18:05:53] root INFO:         loader : 
[2025/03/31 18:05:53] root INFO:             num_workers : 4
[2025/03/31 18:05:53] root INFO:             use_shared_memory : True
[2025/03/31 18:05:53] root INFO:         sampler : 
[2025/03/31 18:05:53] root INFO:             batch_size : 128
[2025/03/31 18:05:53] root INFO:             drop_last : False
[2025/03/31 18:05:53] root INFO:             name : DistributedBatchSampler
[2025/03/31 18:05:53] root INFO:             shuffle : False
[2025/03/31 18:05:53] root INFO:     Train : 
[2025/03/31 18:05:53] root INFO:         dataset : 
[2025/03/31 18:05:53] root INFO:             cls_label_path : /home/aistudio/data/data10954/train_list.txt
[2025/03/31 18:05:53] root INFO:             image_root : /home/aistudio/data/data10954/
[2025/03/31 18:05:53] root INFO:             name : ImageNetDataset
[2025/03/31 18:05:53] root INFO:             transform_ops : 
[2025/03/31 18:05:53] root INFO:                 DecodeImage : 
[2025/03/31 18:05:53] root INFO:                     channel_first : False
[2025/03/31 18:05:53] root INFO:                     to_rgb : True
[2025/03/31 18:05:53] root INFO:                 RandomResizedCrop : 
[2025/03/31 18:05:53] root INFO:                     interpolation : bicubic
[2025/03/31 18:05:53] root INFO:                     ratio : [1.0, 1.0]
[2025/03/31 18:05:53] root INFO:                     scale : [0.75, 1.0]
[2025/03/31 18:05:53] root INFO:                     size : 224
[2025/03/31 18:05:53] root INFO:                 NormalizeImage : 
[2025/03/31 18:05:53] root INFO:                     mean : [0.485, 0.456, 0.406]
[2025/03/31 18:05:53] root INFO:                     order : 
[2025/03/31 18:05:53] root INFO:                     scale : 1.0/255.0
[2025/03/31 18:05:53] root INFO:                     std : [0.229, 0.224, 0.225]
[2025/03/31 18:05:53] root INFO:         loader : 
[2025/03/31 18:05:53] root INFO:             num_workers : 4
[2025/03/31 18:05:53] root INFO:             use_shared_memory : True
[2025/03/31 18:05:53] root INFO:         sampler : 
[2025/03/31 18:05:53] root INFO:             batch_size : 128
[2025/03/31 18:05:53] root INFO:             drop_last : False
[2025/03/31 18:05:53] root INFO:             name : DistributedBatchSampler
[2025/03/31 18:05:53] root INFO:             shuffle : True
[2025/03/31 18:05:53] root INFO: Global : 
[2025/03/31 18:05:53] root INFO:     checkpoints : None
[2025/03/31 18:05:53] root INFO:     device : gpu
[2025/03/31 18:05:53] root INFO:     epochs : 300
[2025/03/31 18:05:53] root INFO:     eval_during_train : True
[2025/03/31 18:05:53] root INFO:     eval_interval : 1
[2025/03/31 18:05:53] root INFO:     image_shape : [3, 300, 300]
[2025/03/31 18:05:53] root INFO:     output_dir : /home/aistudio/data/output_class/
[2025/03/31 18:05:53] root INFO:     pretrained_model : /home/aistudio/best_model/class/model.pdparams
[2025/03/31 18:05:53] root INFO:     print_batch_step : 10
[2025/03/31 18:05:53] root INFO:     save_inference_dir : /home/aistudio/data/inference
[2025/03/31 18:05:53] root INFO:     save_interval : 1
[2025/03/31 18:05:53] root INFO:     use_visualdl : False
[2025/03/31 18:05:53] root INFO: Infer : 
[2025/03/31 18:05:53] root INFO:     PostProcess : 
[2025/03/31 18:05:53] root INFO:         class_id_map_file : /home/aistudio/work/class/label_list.txt
[2025/03/31 18:05:53] root INFO:         name : Topk
[2025/03/31 18:05:53] root INFO:         topk : 5
[2025/03/31 18:05:53] root INFO:     batch_size : 100
[2025/03/31 18:05:53] root INFO:     infer_imgs : /home/aistudio/data/data10954/cat_12_test/
[2025/03/31 18:05:53] root INFO:     transforms : 
[2025/03/31 18:05:53] root INFO:         DecodeImage : 
[2025/03/31 18:05:53] root INFO:             channel_first : False
[2025/03/31 18:05:53] root INFO:             to_rgb : True
[2025/03/31 18:05:53] root INFO:         ResizeImage : 
[2025/03/31 18:05:53] root INFO:             resize_short : 256
[2025/03/31 18:05:53] root INFO:         CropImage : 
[2025/03/31 18:05:53] root INFO:             size : 224
[2025/03/31 18:05:53] root INFO:         NormalizeImage : 
[2025/03/31 18:05:53] root INFO:             mean : [0.485, 0.456, 0.406]
[2025/03/31 18:05:53] root INFO:             order : 
[2025/03/31 18:05:53] root INFO:             scale : 1.0/255.0
[2025/03/31 18:05:53] root INFO:             std : [0.229, 0.224, 0.225]
[2025/03/31 18:05:53] root INFO:         ToCHWImage : None
[2025/03/31 18:05:53] root INFO: Loss : 
[2025/03/31 18:05:53] root INFO:     Eval : 
[2025/03/31 18:05:53] root INFO:         CELoss : 
[2025/03/31 18:05:53] root INFO:             weight : 1.0
[2025/03/31 18:05:53] root INFO:     Train : 
[2025/03/31 18:05:53] root INFO:         CELoss : 
[2025/03/31 18:05:53] root INFO:             epsilon : 0.1
[2025/03/31 18:05:53] root INFO:             weight : 1.0
[2025/03/31 18:05:53] root INFO: Metric : 
[2025/03/31 18:05:53] root INFO:     Eval : 
[2025/03/31 18:05:53] root INFO:         TopkAcc : 
[2025/03/31 18:05:53] root INFO:             topk : [1, 5]
[2025/03/31 18:05:53] root INFO:     Train : 
[2025/03/31 18:05:53] root INFO:         TopkAcc : 
[2025/03/31 18:05:53] root INFO:             topk : [1, 5]
[2025/03/31 18:05:53] root INFO: Optimizer : 
[2025/03/31 18:05:53] root INFO:     beta1 : 0.9
[2025/03/31 18:05:53] root INFO:     beta2 : 0.999
[2025/03/31 18:05:53] root INFO:     lr : 
[2025/03/31 18:05:53] root INFO:         epochs : 300
[2025/03/31 18:05:53] root INFO:         eta_min : 1e-05
[2025/03/31 18:05:53] root INFO:         learning_rate : 0.000125
[2025/03/31 18:05:53] root INFO:         name : Cosine
[2025/03/31 18:05:53] root INFO:         step_each_epoch : 1000
[2025/03/31 18:05:53] root INFO:         warmup_epoch : 20
[2025/03/31 18:05:53] root INFO:         warmup_start_lr : 1e-06
[2025/03/31 18:05:53] root INFO:     name : AdamW
[2025/03/31 18:05:53] root INFO:     weight_decay : 0.05
[2025/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.1
W0331 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/simple
Requirement 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/simple
Requirement 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)) (2025.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)) (2025.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
  """
2025-03-31 18:07:33 [INFO]	
------------Environment Information-------------
platform: Linux-4.4.0-150-generic-x86_64-with-debian-stretch-sid
Python: 3.7.4 (default, Aug 13 2019, 20:35:49) [GCC 7.3.0]
Paddle compiled with cuda: True
NVCC: Cuda compilation tools, release 10.1, V10.1.243
cudnn: 7.6
GPUs used: 1
CUDA_VISIBLE_DEVICES: None
GPU: ['GPU 0: Tesla V100-SXM2-16GB']
GCC: gcc (Ubuntu 7.5.0-3ubuntu1~16.04) 7.5.0
PaddlePaddle: 2.2.2
OpenCV: 4.4.0
------------------------------------------------
2025-03-31 18:07:33 [INFO]	
---------------Config Information---------------
batch_size: 64
iters: 300
loss:
  coef:
  - 1
  - 0.4
  types:
  - ignore_index: 255
    type: CrossEntropyLoss
  - ignore_index: 255
    type: CrossEntropyLoss
lr_scheduler:
  learning_rate: 0.00125
  power: 0.9
  type: PolynomialDecay
model:
  backbone:
    class_num: 6
    pretrained: https://passl.bj.bcebos.com/models/convnext_tiny_1k_224.pdparams
    type: ConvNeXt_Tiny
  backbone_indices:
  - 0
  type: OCRNet
optimizer:
  type: sgd
train_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: Dataset
val_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.1
W0331 18:07:34.499097   829 device_context.cc:465] device: 0, cuDNN Version: 7.6.
2025-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))
2025-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:49
2025-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:31
2025-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:17
2025-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:04
2025-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:54
2025-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-04
2025-03-31 18:09:09 [INFO]	[EVAL] #Images: 1334 mIoU: 0.1310 Acc: 0.4490 Kappa: 0.2189 
2025-03-31 18:09:09 [INFO]	[EVAL] Class IoU: 
[0.3424 0.3964 0.1779 0.     0.     0.     0.    ]
2025-03-31 18:09:09 [INFO]	[EVAL] Class Acc: 
[0.4389 0.5091 0.3204 0.     0.     0.     0.    ]
2025-03-31 18:09:10 [INFO]	[EVAL] The model with the best validation mIoU (0.1310) was saved at iter 100.
2025-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:30
2025-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:33
2025-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:20
2025-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:09
2025-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:59
2025-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-05
2025-03-31 18:10:39 [INFO]	[EVAL] #Images: 1334 mIoU: 0.1478 Acc: 0.4874 Kappa: 0.2597 
2025-03-31 18:10:39 [INFO]	[EVAL] Class IoU: 
[0.3592 0.422  0.0859 0.1673 0.     0.     0.    ]
2025-03-31 18:10:39 [INFO]	[EVAL] Class Acc: 
[0.4692 0.4845 0.5087 0.6331 0.     0.     0.    ]
2025-03-31 18:10:39 [INFO]	[EVAL] The model with the best validation mIoU (0.1478) was saved at iter 200.
2025-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:40
2025-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:35
2025-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:23
2025-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:12
2025-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:00
2025-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-05
2025-03-31 18:12:11 [INFO]	[EVAL] #Images: 1334 mIoU: 0.1765 Acc: 0.5187 Kappa: 0.3205 
2025-03-31 18:12:11 [INFO]	[EVAL] Class IoU: 
[0.361  0.4712 0.2135 0.1899 0.     0.     0.    ]
2025-03-31 18:12:11 [INFO]	[EVAL] Class Acc: 
[0.4795 0.5663 0.4366 0.5706 0.     0.     0.    ]
2025-03-31 18:12:11 [INFO]	[EVAL] The model with the best validation mIoU (0.1765) was saved at iter 300.
's flops has been counted
Cannot find suitable count function for . Treat it as zero FLOPs.
's flops has been counted
Cannot find suitable count function for . Treat it as zero FLOPs.
Cannot find suitable count function for . Treat it as zero FLOPs.
Cannot find suitable count function for . Treat it as zero FLOPs.
Cannot find suitable count function for . Treat it as zero FLOPs.
Cannot find suitable count function for . Treat it as zero FLOPs.
's flops has been counted
's flops has been counted
Cannot find suitable count function for . 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
2025-03-31 18:12:15 [INFO]	
---------------Config Information---------------
batch_size: 4
iters: 15000
loss:
  coef:
  - 1
  - 0.4
  types:
  - type: CrossEntropyLoss
  - type: CrossEntropyLoss
lr_scheduler:
  learning_rate: 0.00125
  power: 0.9
  type: PolynomialDecay
model:
  backbone:
    class_num: 6
    pretrained: https://passl.bj.bcebos.com/models/convnext_tiny_1k_224.pdparams
    type: ConvNeXt_Tiny
  backbone_indices:
  - 0
  type: OCRNet
optimizer:
  type: sgd
train_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: Dataset
val_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.1
W0331 18:12:16.364699  1223 device_context.cc:465] device: 0, cuDNN Version: 7.6.
2025-03-31 18:12:20 [INFO]	Number of predict images = 4608
2025-03-31 18:12:20 [INFO]	Loading pretrained model from /home/aistudio/best_model/seg/model.pdparams
2025-03-31 18:12:20 [INFO]	There are 240/240 variables loaded into OCRNet.
2025-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/simple
Requirement 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/PaddleDetection
fatal: 一个分支名 'release/2.3' 已经存在。
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Requirement 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:01
Requirement 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) ... done
Requirement 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) ... done
Requirement 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) ... done
Requirement 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)) (2025.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) ... done
Requirement 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)) (2025.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/670dfd20254fc9cc6bf843db4e014acb998f411922e3abc49f
  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/6309c7cc9929894c11fe8e516c3e2a0d0a53ee4e198eac48b7
Successfully built pycocotools lap cython_bbox py-cpuinfo
Installing collected packages: py-cpuinfo, lap, iniconfig, cython_bbox, xmltodict, typeguard, tomli, terminaltables, shapely, py, flake8-import-order, pytest, pycocotools, pytest-benchmark, motmetrics
Successfully 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
--2025-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    

2025-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 firstly
W0331 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.1
W0331 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.pdparams
100%|████████████████████████████████| 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.1241245 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


# cnn  # 加载  # 一大  # 提出了  # 象中  # 不需要  # 使用了  # 只在  # 的是  # 切换到  # 为例  # transformer  # linux  # for  # 架构  # red  # pip升级  # yy  # cos  # ai  # 工具  # cad  # git  # python 


相关栏目: 【 Google疑问12 】 【 Facebook疑问10 】 【 网络优化91478 】 【 技术知识72672 】 【 云计算0 】 【 GEO优化84317 】 【 优选文章0 】 【 营销推广36048 】 【 网络运营41350 】 【 案例网站102563 】 【 AI智能45237


相关推荐: Depseek怎么生成员工成长总结_Depseek成长维度提取与案例整合【方法】  EdrawMax AI:项目管理和创意专业人士的终极图表工具  Mermaid Playground: AI驱动的图表秒速创建指南  通义千问怎样优化提示词更口语化_通义千问口语化技巧【教程】  AI绘画工具怎么用_AI绘画工具使用方法详细指南【教程】  小型邮件列表的终极指南:使用AI最大化营销效果  EdrawMax全面评测:使用AI轻松绘制流程图和思维导图  AI社交媒体自动化:n8n与HeyGen打造个性化内容引擎  Claude怎么用新功能表格生成_Claude表格生成使用【攻略】  AI代码助手的崛起:软件工程的未来展望与实用指南  雷小兔ai智能写作如何生成文案_雷小兔ai智能写作文案生成场景选择【攻略】  美图秀秀AI抠图如何换背景_美图秀秀AI背景替换与贴纸添加【攻略】  通义千问怎样优化提示词效果_通义千问提示词优化技巧【攻略】  135编辑器AI排版怎样快速上手_135编辑器AI排版新手入门与功能介绍【教程】  都灵裹尸布之谜:AI揭示耶稣基督的真实面貌?  讯飞星火怎么一键生成|直播|话术_讯飞星火话术生成与节奏把控【教程】  雷小兔ai智能写作怎么设置写作风格_雷小兔ai智能写作风格选择方法【指南】  教你用AI将长视频内容切片,并自动生成短视频文案  Kling AI 2.5 Turbo:视频生成领域的颠覆者,深度评测与对比  Midjourney怎么用一键生成壁纸_Midjourney壁纸生成教程【教程】  AI图像生成偏见:克服与优化,打造更真实的数字形象  构建卓越AI代理:端到端Agentic RAG解决方案详解  3步教你用AI自动分类文件,整理电脑告别杂乱  腾讯混元图像3.0上线LiblibAI,80B参数助力创作者高效出图  C3.ai深度解析:投资者必知的关键洞察  告别噪音:使用Adobe Podcast提升录音质量  百度输入法ai模式怎么关 百度输入法恢复普通模式  通义千问怎样写文案_通义千问文案写作教程【指南】  电脑硬件升级指南:旧电脑的回收利用与性能提升  AI 3D建模革命:免费生成高质量模型和纹理  掌握写作技巧:小说情节设计的核心要素解析  Talvix AI:AI驱动的招聘平台,提升招聘效率和质量  Canva AI工具教程:动漫化图像、生成艺术与定制QR码  ChatGPT 4.0赋能室内设计:20+实用技巧提升工作效率  AI赋能科研探索:Google Research创新加速科学发现  Jasper AI如何做SEO优化 Jasper AI结合SurferSEO用法【教程】  如何利用 ChatGPT 进行深度行业竞品分析  AI猴子视频制作终极指南:从入门到网红,轻松上手!  AI学习秘籍:3个高效黑科技,解锁智能学习新时代  百度AI助手聊天入口 文心一言对话窗口入口  利用豆包 AI 进行个性化旅行 Vlog 脚本设计  Claude怎样用提示词控制输出长度_Claude输出长度设置【教程】  雷小兔ai智能写作如何生成日记_雷小兔ai智能写作日记模板调用【步骤】  Claude怎样写引导型提示词_Claude引导提示词写法【方法】  豆包AI里的智能体有什么用_不同类型智能体使用场景介绍  AI驱动的医学影像器官分割与3D可视化:临床应用的未来  百度ai助手任务栏怎么关 百度ai助手任务栏图标隐藏  AI音乐创作:颠覆传统,开启音乐新纪元  如何通过 DeepSeek 进行深度神经网络超参数搜索  11月问界汽车哪里卖的多?成都力压北上广深位居第一 

 2025-07-17

了解您产品搜索量及市场趋势,制定营销计划

同行竞争及网站分析保障您的广告效果

点击免费数据支持

提交您的需求,1小时内享受我们的专业解答。

南京市珐之弘网络技术有限公司


南京市珐之弘网络技术有限公司

南京市珐之弘网络技术有限公司专注海外推广十年,是谷歌推广.Facebook广告全球合作伙伴,我们精英化的技术团队为企业提供谷歌海外推广+外贸网站建设+网站维护运营+Google SEO优化+社交营销为您提供一站式海外营销服务。

 87067657

 13565296790

 87067657@qq.com

Notice

We and selected third parties use cookies or similar technologies for technical purposes and, with your consent, for other purposes as specified in the cookie policy.
You can consent to the use of such technologies by closing this notice, by interacting with any link or button outside of this notice or by continuing to browse otherwise.