---
title: MobileNetV2-PyTorch-模型库-ModelZoo-昇腾社区
description: MobileNetV2在MobileNetV1的基础上新提出了Linear Bottleneck 和 Inverted Residuals两种方法，使能在保持类似精度的条件下显著的减少模型参数和计算量。
keywords: MobileNetV,PyTorch,模型库,ModelZoo,昇腾社区,概述,简述,准备训练环境
url: https://www.hiascend.com/software/modelzoo/models/detail/4927bc8a6a5f4ce5a4f3a1abd9f89f0a
section: (其他)
---

# MobileNetV2-PyTorch-模型库-ModelZoo-昇腾社区

URL: https://www.hiascend.com/software/modelzoo/models/detail/4927bc8a6a5f4ce5a4f3a1abd9f89f0a
描述: MobileNetV2在MobileNetV1的基础上新提出了Linear Bottleneck 和 Inverted Residuals两种方法，使能在保持类似精度的条件下显著的减少模型参数和计算量。
关键词: MobileNetV,PyTorch,模型库,ModelZoo,昇腾社区,概述,简述,准备训练环境

ModelZoo主页

主页 [了解详情](https://www.hiascend.com/software/modelzoo)大模型 [了解详情](https://www.hiascend.com/software/modelzoo/big-models)模型库 [了解详情](https://www.hiascend.com/software/modelzoo/models)工具库 [了解详情](https://www.hiascend.com/software/modelzoo/tools)权重库 [了解详情](https://www.hiascend.com/software/modelzoo/datasets)ModelShow [了解详情](https://www.hiascend.com/software/modelzoo/modelshow)DeepSeek专区HOT [了解详情](https://www.hiascend.com/developer/deepseek)文档中心 [了解详情](https://www.hiascend.com/document/detail/zh/ModelZoo/Documentation/overview/overview_0001.html)论坛交流 [了解详情](https://www.hiascend.com/forum/forum-0140120119986591009-1.html)

主页 [了解详情](https://www.hiascend.com/software/modelzoo)大模型 [了解详情](https://www.hiascend.com/software/modelzoo/big-models)模型库 [了解详情](https://www.hiascend.com/software/modelzoo/models)工具库 [了解详情](https://www.hiascend.com/software/modelzoo/tools)权重库 [了解详情](https://www.hiascend.com/software/modelzoo/datasets)ModelShow [了解详情](https://www.hiascend.com/software/modelzoo/modelshow)DeepSeek专区HOT [了解详情](https://www.hiascend.com/developer/deepseek)文档中心 [了解详情](https://www.hiascend.com/document/detail/zh/ModelZoo/Documentation/overview/overview_0001.html)论坛交流 [了解详情](https://www.hiascend.com/forum/forum-0140120119986591009-1.html)

模型库 [了解详情](https://www.hiascend.com/software/modelzoo/models)

MobileNetV2-PyTorch

## MobileNetV2-PyTorch

视觉分类PyTorch训练350次浏览2025/12/29更新

5.0

获取源码

MobileNetV2-PyTorch

查看模型源码

模型使用

版本信息

模型使用

版本信息

...

# 概述

## 简述

MobileNetv2在MobileNetv1的基础上新提出了Linear Bottleneck 和 Inverted Residuals两种方法，使能在保持类似精度的条件下显著的减少模型参数和计算量。

- 参考实现：

```
url=https://github.com/pytorch/examples/tree/main/imagenet
commit_id=f5bb60f8e6b2881be3a2ea8c9a3d43e676aa2340
```
- 适配昇腾 AI 处理器的实现：

```
url=https://gitee.com/ascend/ModelZoo-PyTorch.git
code_path=PyTorch/built-in/cv/classification
```

# 准备训练环境

## 准备环境

- 当前模型支持的 PyTorch 版本和已知三方库依赖如下表所示。

表 1版本支持表

| Torch_Version | 三方库依赖版本 |
| --- | ---|
| PyTorch 1.5 | torchvision==0.6.0 |
| PyTorch 1.8 | torchvision==0.9.1 |
| PyTorch 1.11 | torchvision==0.12.0 |
| PyTorch 2.1 | torchvision==0.16.0 |
- 环境准备指导。

请参考《Pytorch框架训练环境准备 [了解详情](https://www.hiascend.com/document/detail/zh/ModelZoo/pytorchframework/ptes)》。
- 安装依赖。

在模型源码包根目录下执行命令，安装模型对应PyTorch版本需要的依赖。

```
pip install -r 1.5_requirements.txt  # PyTorch1.5版本

pip install -r 1.8_requirements.txt  # PyTorch1.8版本

pip install -r 1.11_requirements.txt  # PyTorch1.11版本

pip install -r 2.1_requirements.txt  # PyTorch2.1版本
```

说明：只需执行一条对应的PyTorch版本依赖安装命令。

## 准备数据集

1. 获取数据集。

用户自行下载`ImageNet`数据集，将数据集上传到服务器任意路径下并解压。

数据集目录结构参考如下所示。

```
├── ImageNet
      ├──train
           ├──类别1
                 │──图片1
                 │──图片2
                 │   ...       
           ├──类别2
                 │──图片1
                 │──图片2
                 │   ...   
           ├──...                     
      ├──val  
           ├──类别1
                 │──图片1
                 │──图片2
                 │   ...       
           ├──类别2
                 │──图片1
                 │──图片2
                 │   ...              
```

说明：该数据集的训练过程脚本只作为一种参考示例。

# 开始训练

## 训练模型

1. 进入解压后的源码包根目录。

```
cd /${模型文件夹名称} 
```
2. 运行训练脚本。

该模型支持单机单卡训练和单机8卡训练。

- 单机单卡训练

启动单卡训练。

```
bash ./test/train_full_1p.sh --data_path=/data/xxx/   # 单卡精度 

bash ./test/train_performance_1p.sh --data_path=/data/xxx/  # 单卡性能
```
- 单机8卡训练

启动8卡训练。

```
bash ./test/train_full_8p.sh --data_path=/data/xxx/   # 8卡精度

bash ./test/train_performance_8p.sh --data_path=/data/xxx/ # 8卡性能
```
- 多机多卡性能数据获取流程

```
 1. 准备多机环境
 2. 开始训练，每个机器请按下面提示进行配置
     bash ./test/train_performance_multinodes.sh --data_path=数据集路径 --batch_size=单卡batch_size*单机卡数 --nnodes=机器总数量 --node_rank=当前机器rank(0,1,2..) --local_addr=当前机器IP(需要和master_addr处于同一网段) --master_addr=主节点IP
```

--data_path参数填写数据集路径，需写到数据集的一级目录。

模型训练脚本参数说明如下。

```
公共参数：
--addr                            // 节点ip
--seed                             // 随机数种子
--workers                          // 工作线程数
--lr                               // 学习率
--print-freq                       // 多久一次打印
--eval-freq 1                      // 多久一次验证
--dist-url                         // 分布式节点url
--dist-backend                     // 分布式所用后台
--multiprocessing-distributed   // 是否使用分布式
--world-size                    // 总共进程数
--class-nums                    //  类别数量
--batch-size                    // 一次训练多少图片
--epochs                        // 训练多少轮
--rank                          // 当前进程排名
--device-list                   //  使用哪些卡
--amp                           // 混合精度
--benchmark 0                   // 是否启用benchmark
--data                          // 数据路径
```

训练完成后，权重文件保存在当前路径下，并输出模型训练精度和性能信息。

# 训练结果展示

表 2训练结果展示表

| NAME | Acc@1 | FPS | Epochs | AMP_Type | Torch_Version |
| --- | --- | --- | --- | --- | ---|
| 1p-NPU(ARM) | - | 2789.13 | 1 | O2 | 1.8 |
| 8p-NPU(ARM) | 71.3 | 13477.3 | 600 | O2 | 1.8 |
| 1p-NPU(非ARM) | - | 2807.02 | 1 | O2 | 1.8 |
| 8p-NPU(非ARM) | - | 9190.41 | 600 | O2 | 1.8 |

## 版本说明

## 变更

2023.04.24：更新torch1.8版本，重新发布。

2020.12.19：首次发布。

## FAQ

1. 在ARM平台上，安装0.6.0版本的torchvision，需进行源码编译安装，可以参考源码readme进行安装。

```
https://github.com/pytorch/vision
```

# 公网地址说明

代码涉及公网地址参考 public_address_statement.md

| 版本 | 更新时间 | 精度 | 处理器 | CANN版本 | 操作 |
| --- | --- | --- | --- | --- | ---|
| 5.0.RC3 | 2023/11/02 | Mixed | Ascend 910 | 7.0.RC1 | modelzoo |

使用模型资源和服务前，请您仔细阅读并理解透彻《昇腾深度学习模型许可协议 3.0》 [了解详情](https://www.hiascend.com/legal/modelzoo_models_license)
