Skip to content

Commit

Permalink
readme, usage for mobilenetv2
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Zhang authored and Richard Zhang committed Jun 5, 2019
1 parent f51f98d commit ca246f4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -50,7 +50,7 @@ model = models_lpf.resnet.resnet50(filter_size=3)
model.load_state_dict(torch.load('weights/resnet50_lpf3.pth.tar')['state_dict'])
```

We also provide weights for antialiased `AlexNet`, `VGG16(bn)`, `Resnet18,34,50,101`, `Densenet121` (see [example_usage.py](example_usage.py)).
We also provide weights for antialiased `AlexNet`, `VGG16(bn)`, `Resnet18,34,50,101`, `Densenet121`, and `MobileNetv2` (see [example_usage.py](example_usage.py)).

## (2) Antialias your own architecture

Expand Down
5 changes: 4 additions & 1 deletion README_IMAGENET.md
Expand Up @@ -10,7 +10,7 @@ We describe how to evaluate models for shift-invariance.

## (1) Evaluating models

We provide models with filter sizes 2,3,5 for AlexNet, VGG16, VGG16bn, ResNet18,34,50,101 and DenseNet121.
We provide models with filter sizes 2,3,5 for AlexNet, VGG16, VGG16bn, ResNet18,34,50,101, DenseNet121, and MobileNetv2.

### Evaluating accuracy

Expand All @@ -23,6 +23,7 @@ python main.py --data /PTH/TO/ILSVRC2012 -e -f 3 -a resnet34_lpf --weights ./wei
python main.py --data /PTH/TO/ILSVRC2012 -e -f 3 -a resnet50_lpf --weights ./weights/resnet50_lpf3.pth.tar
python main.py --data /PTH/TO/ILSVRC2012 -e -f 3 -a resnet101_lpf --weights ./weights/resnet101_lpf3.pth.tar
python main.py --data /PTH/TO/ILSVRC2012 -e -f 3 -a densenet121_lpf --weights ./weights/densenet121_lpf3.pth.tar
python main.py --data /PTH/TO/ILSVRC2012 -e -f 3 -a mobilenet_v2_lpf --weights ./weights/mobilenet_v2_lpf3.pth.tar
```

### Evaluating consistency
Expand All @@ -38,6 +39,7 @@ python main.py --data /PTH/TO/ILSVRC2012 -es -b 8 -f 3 -a resnet34_lpf --weights
python main.py --data /PTH/TO/ILSVRC2012 -es -b 8 -f 3 -a resnet50_lpf --weights ./weights/resnet50_lpf3.pth.tar
python main.py --data /PTH/TO/ILSVRC2012 -es -b 8 -f 3 -a resnet101_lpf --weights ./weights/resnet101_lpf3.pth.tar
python main.py --data /PTH/TO/ILSVRC2012 -es -b 8 -f 3 -a densenet121_lpf --weights ./weights/densenet121_lpf3.pth.tar
python main.py --data /PTH/TO/ILSVRC2012 -es -b 8 -f 3 -a mobilenet_v2_lpf --weights ./weights/mobilenet_v2_lpf3.pth.tar
```

Some notes:
Expand All @@ -64,6 +66,7 @@ Some notes:
- As suggested by the official repository, AlexNet and VGG16 require lower learning rates of `0.01` (default is `0.1`).
- VGG16_bn also required a slightly lower learning rate of `0.05`.
- I train AlexNet on a single GPU (the network is fast, so preprocessing becomes the limiting factor if multiple GPUs are used).
- MobileNet was trained with the training recipe from [here](https://github.com/tonylins/pytorch-mobilenet-v2#training-recipe), which is not currently supported in this repo.
- Default batch size is `256`. Some extra memory is added for the antialiasing layers, so the default batchsize may no longer fit in memory. To get around this, we simply accumulate gradients over 2 smaller batches `-b 128` with flag `--ba 2`. You may find this useful, even for the default models, if you are training with smaller/fewer GPUs. It is not exactly identical to training with a large batch, as the batchnorm statistics will be computed with a smaller batch.

Checkpoint vs weights:
Expand Down
5 changes: 5 additions & 0 deletions example_usage.py
Expand Up @@ -40,3 +40,8 @@
import models_lpf.densenet
model = models_lpf.densenet.densenet121(filter_size=filter_size)
model.load_state_dict(torch.load('weights/densenet121_lpf%i.pth.tar'%filter_size)['state_dict'])

import models_lpf.mobilenet
model = models_lpf.mobilenet.mobilenet_v2(filter_size=filter_size)
model.load_state_dict(torch.load('weights/mobilenet_v2_lpf%i.pth.tar'%filter_size)['state_dict'])

0 comments on commit ca246f4

Please sign in to comment.