# A PyTorch implementation of MobileNetV2
This is a PyTorch implementation of MobileNetV2 architecture as described in the paper [Inverted Residuals and Linear Bottlenecks: Mobile Networks for Classification, Detection and Segmentation](https://arxiv.org/pdf/1801.04381).
<u>**[NEW]** Add the code to automatically download the pre-trained weights.</u>
## Training Recipe
Recently I have figured out a good training setting:
1. number of epochs: 150
2. learning rate schedule: cosine learning rate, initial lr=0.05
3. weight decay: 4e-5
4. remove dropout
You should get >72% top-1 accuracy with this training recipe!
## Accuracy & Statistics
Here is a comparison of statistics against the official TensorFlow [implementation](https://github.com/tensorflow/models/tree/master/research/slim/nets/mobilenet).
| | FLOPs | Parameters | Top1-acc | Pretrained Model |
| ----------- | --------- | ---------- | --------- | ------------------------------------------------------------ |
| Official TF | 300 M | 3.47 M | 71.8% | - |
| Ours | 300.775 M | 3.471 M | **71.8%** | [[google drive](https://drive.google.com/open?id=1jlto6HRVD3ipNkAl1lNhDbkBp7HylaqR)] |
## Usage
To use the pretrained model, run
```python
from MobileNetV2 import mobilenet_v2
net = mobilenet_v2(pretrained=True)
```
## Data Pre-processing
I used the following code for data pre-processing on ImageNet:
```python
normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406],
std=[0.229, 0.224, 0.225])
input_size = 224
train_dataset = datasets.ImageFolder(
traindir,
transforms.Compose([
transforms.RandomResizedCrop(input_size, scale=(0.2, 1.0)),
transforms.RandomHorizontalFlip(),
transforms.ToTensor(),
normalize,
]))
train_loader = torch.utils.data.DataLoader(
train_dataset, batch_size=batch_size, shuffle=True,
num_workers=n_worker, pin_memory=True)
val_loader = torch.utils.data.DataLoader(
datasets.ImageFolder(valdir, transforms.Compose([
transforms.Resize(int(input_size/0.875)),
transforms.CenterCrop(input_size),
transforms.ToTensor(),
normalize,
])),
batch_size=batch_size, shuffle=False,
num_workers=n_worker, pin_memory=True)
```
MobileNet V2体系结构和预训练模型的PyTorch实现。-Python开发
需积分: 11 77 浏览量
2021-05-25
15:25:44
上传
评论
收藏 7KB ZIP 举报
大白兔奶棠
- 粉丝: 26
- 资源: 4661
最新资源
- 嵌入式基础学习资料0000
- content_1714465331721.xls
- HM3401-VB一款P-Channel沟道SOT23的MOSFET晶体管参数介绍与应用说明
- Chainbase+Web3+APi+Data warehouse
- HM3401D-VB一款P-Channel沟道SOT23的MOSFET晶体管参数介绍与应用说明
- GEE案例-1990-2023年计算某个区域的NDVI时序变化轨迹(以徐州市为例)含全部代码.pdf
- HM3401C-VB一款P-Channel沟道SOT23的MOSFET晶体管参数介绍与应用说明
- 沈丘盛世龙门图纸符合规范化
- 基于51单片机带LCD1602显示+温度补偿的超声波测距仪设计软硬设计+仿真+文档资料.zip
- 一、K210是什么? K210全称为堪智K210,是嘉楠科技自主研发的一款采用RISC-V处理器架构,具备视听一体、自主IP内核
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈