资源算法pytorch-mobilenet-v2

pytorch-mobilenet-v2

2020-02-07 | |  42 |   0 |   0

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.

[NEW] Add the code to automatically download the pre-trained weights.

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.


FLOPsParametersTop1-accPretrained Model
Official TF300 M3.47 M71.8%-
Ours300.775 M3.471 M71.8%[google drive]

Usage

To use the pretrained model, run

from MobileNetV2 import mobilenet_v2

net = mobilenet_v2(pretrained=True)

Data Pre-processing

I used the following code for data pre-processing on ImageNet:

normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406],                                 std=[0.229, 0.224, 0.225])

input_size = 224train_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-SSD

下一篇:MobileNetv2-SSDLite

用户评价
全部评价

热门资源

  • Keras-ResNeXt

    Keras ResNeXt Implementation of ResNeXt models...

  • seetafaceJNI

    项目介绍 基于中科院seetaface2进行封装的JAVA...

  • spark-corenlp

    This package wraps Stanford CoreNLP annotators ...

  • capsnet-with-caps...

    CapsNet with capsule-wise convolution Project ...

  • inferno-boilerplate

    This is a very basic boilerplate example for pe...