Commit 495d9ed9 authored by limm's avatar limm
Browse files

add part code

parent 59b09903
Pipeline #2799 canceled with stages
_base_ = [
'../_base_/models/resnet50.py',
'../_base_/datasets/imagenet_bs256_rsb_a12.py',
'../_base_/schedules/imagenet_bs2048_rsb.py',
'../_base_/default_runtime.py'
]
# model settings
model = dict(
backbone=dict(
norm_cfg=dict(type='SyncBN', requires_grad=True),
drop_path_rate=0.05,
),
head=dict(
loss=dict(
type='LabelSmoothLoss',
label_smooth_val=0.1,
mode='original',
use_sigmoid=True,
)),
train_cfg=dict(augments=[
dict(type='Mixup', alpha=0.2),
dict(type='CutMix', alpha=1.0)
]),
)
# dataset settings
train_dataloader = dict(sampler=dict(type='RepeatAugSampler', shuffle=True))
# schedule settings
optim_wrapper = dict(
optimizer=dict(weight_decay=0.01),
paramwise_cfg=dict(bias_decay_mult=0., norm_decay_mult=0.),
)
param_scheduler = [
# warm up learning rate scheduler
dict(
type='LinearLR',
start_factor=0.0001,
by_epoch=True,
begin=0,
end=5,
# update by iter
convert_to_iter_based=True),
# main learning rate scheduler
dict(
type='CosineAnnealingLR',
T_max=595,
eta_min=1.0e-6,
by_epoch=True,
begin=5,
end=600)
]
train_cfg = dict(by_epoch=True, max_epochs=600)
_base_ = [
'../_base_/models/resnet50.py',
'../_base_/datasets/imagenet_bs256_rsb_a12.py',
'../_base_/schedules/imagenet_bs2048_rsb.py',
'../_base_/default_runtime.py'
]
# model settings
model = dict(
backbone=dict(
norm_cfg=dict(type='SyncBN', requires_grad=True),
drop_path_rate=0.05,
),
head=dict(loss=dict(use_sigmoid=True)),
train_cfg=dict(augments=[
dict(type='Mixup', alpha=0.1),
dict(type='CutMix', alpha=1.0)
]))
# dataset settings
train_dataloader = dict(sampler=dict(type='RepeatAugSampler', shuffle=True))
# schedule settings
optim_wrapper = dict(
paramwise_cfg=dict(bias_decay_mult=0., norm_decay_mult=0.))
param_scheduler = [
# warm up learning rate scheduler
dict(
type='LinearLR',
start_factor=0.0001,
by_epoch=True,
begin=0,
end=5,
# update by iter
convert_to_iter_based=True),
# main learning rate scheduler
dict(
type='CosineAnnealingLR',
T_max=295,
eta_min=1.0e-6,
by_epoch=True,
begin=5,
end=300)
]
train_cfg = dict(by_epoch=True, max_epochs=300)
_base_ = [
'../_base_/models/resnet50.py',
'../_base_/datasets/imagenet_bs256_rsb_a3.py',
'../_base_/schedules/imagenet_bs2048_rsb.py',
'../_base_/default_runtime.py'
]
# model settings
model = dict(
backbone=dict(norm_cfg=dict(type='SyncBN', requires_grad=True)),
head=dict(loss=dict(use_sigmoid=True)),
train_cfg=dict(augments=[
dict(type='Mixup', alpha=0.1),
dict(type='CutMix', alpha=1.0)
]),
)
# schedule settings
optim_wrapper = dict(
optimizer=dict(lr=0.008),
paramwise_cfg=dict(bias_decay_mult=0., norm_decay_mult=0.),
)
_base_ = 'resnet50_8xb32-coslr_in1k.py'
# Precise BN hook will update the bn stats, so this hook should be executed
# before CheckpointHook(priority of 'VERY_LOW') and
# EMAHook(priority of 'NORMAL') So set the priority of PreciseBNHook to
# 'ABOVENORMAL' here.
custom_hooks = [
dict(
type='PreciseBNHook',
num_samples=8192,
interval=1,
priority='ABOVE_NORMAL')
]
_base_ = [
'../_base_/models/resnet50.py', '../_base_/datasets/imagenet_bs32.py',
'../_base_/schedules/imagenet_bs256_coslr.py',
'../_base_/default_runtime.py'
]
_base_ = [
'../_base_/models/resnet50_cutmix.py',
'../_base_/datasets/imagenet_bs32.py',
'../_base_/schedules/imagenet_bs256.py', '../_base_/default_runtime.py'
]
_base_ = ['./resnet50_8xb32_in1k.py']
# schedule settings
optim_wrapper = dict(type='AmpOptimWrapper', loss_scale='dynamic')
_base_ = ['./resnet50_8xb32_in1k.py']
# schedule settings
optim_wrapper = dict(type='AmpOptimWrapper', loss_scale=512.)
_base_ = [
'../_base_/models/resnet50_label_smooth.py',
'../_base_/datasets/imagenet_bs32.py',
'../_base_/schedules/imagenet_bs256.py', '../_base_/default_runtime.py'
]
_base_ = [
'../_base_/models/resnet50_mixup.py',
'../_base_/datasets/imagenet_bs32.py',
'../_base_/schedules/imagenet_bs256.py', '../_base_/default_runtime.py'
]
_base_ = [
'../_base_/models/resnet50.py', '../_base_/datasets/imagenet_bs32.py',
'../_base_/schedules/imagenet_bs256.py', '../_base_/default_runtime.py'
]
_base_ = [
'../_base_/models/resnet50.py',
'../_base_/datasets/cub_bs8_448.py',
'../_base_/schedules/cub_bs64.py',
'../_base_/default_runtime.py',
]
# model settings
# use pre-train weight converted from https://github.com/Alibaba-MIIL/ImageNet21K # noqa
pretrained = 'https://download.openmmlab.com/mmclassification/v0/resnet/resnet50_3rdparty-mill_in21k_20220331-faac000b.pth' # noqa
model = dict(
type='ImageClassifier',
backbone=dict(
init_cfg=dict(
type='Pretrained', checkpoint=pretrained, prefix='backbone')),
head=dict(num_classes=200, ))
# runtime settings
default_hooks = dict(logger=dict(type='LoggerHook', interval=20))
_base_ = [
'../_base_/models/resnetv1c50.py',
'../_base_/datasets/imagenet_bs32_pil_resize.py',
'../_base_/schedules/imagenet_bs256.py', '../_base_/default_runtime.py'
]
model = dict(backbone=dict(depth=101))
_base_ = [
'../_base_/models/resnetv1c50.py',
'../_base_/datasets/imagenet_bs32_pil_resize.py',
'../_base_/schedules/imagenet_bs256.py', '../_base_/default_runtime.py'
]
model = dict(backbone=dict(depth=152))
_base_ = [
'../_base_/models/resnetv1c50.py',
'../_base_/datasets/imagenet_bs32_pil_resize.py',
'../_base_/schedules/imagenet_bs256.py', '../_base_/default_runtime.py'
]
_base_ = [
'../_base_/models/resnetv1d101.py',
'../_base_/datasets/imagenet_bs32_pil_resize.py',
'../_base_/schedules/imagenet_bs256.py', '../_base_/default_runtime.py'
]
_base_ = [
'../_base_/models/resnetv1d152.py',
'../_base_/datasets/imagenet_bs32_pil_resize.py',
'../_base_/schedules/imagenet_bs256.py', '../_base_/default_runtime.py'
]
_base_ = [
'../_base_/models/resnetv1d50.py',
'../_base_/datasets/imagenet_bs32_pil_resize.py',
'../_base_/schedules/imagenet_bs256.py', '../_base_/default_runtime.py'
]
# ResNeXt
> [Aggregated Residual Transformations for Deep Neural Networks](https://openaccess.thecvf.com/content_cvpr_2017/html/Xie_Aggregated_Residual_Transformations_CVPR_2017_paper.html)
<!-- [ALGORITHM] -->
## Abstract
We present a simple, highly modularized network architecture for image classification. Our network is constructed by repeating a building block that aggregates a set of transformations with the same topology. Our simple design results in a homogeneous, multi-branch architecture that has only a few hyper-parameters to set. This strategy exposes a new dimension, which we call "cardinality" (the size of the set of transformations), as an essential factor in addition to the dimensions of depth and width. On the ImageNet-1K dataset, we empirically show that even under the restricted condition of maintaining complexity, increasing cardinality is able to improve classification accuracy. Moreover, increasing cardinality is more effective than going deeper or wider when we increase the capacity. Our models, named ResNeXt, are the foundations of our entry to the ILSVRC 2016 classification task in which we secured 2nd place. We further investigate ResNeXt on an ImageNet-5K set and the COCO detection set, also showing better results than its ResNet counterpart. The code and models are publicly available online.
<div align=center>
<img src="https://user-images.githubusercontent.com/26739999/142574479-21fb00a2-e63e-4bc6-a9f2-989cd6e15528.png" width="70%"/>
</div>
## How to use it?
<!-- [TABS-BEGIN] -->
**Predict image**
```python
from mmpretrain import inference_model
predict = inference_model('resnext50-32x4d_8xb32_in1k', 'demo/bird.JPEG')
print(predict['pred_class'])
print(predict['pred_score'])
```
**Use the model**
```python
import torch
from mmpretrain import get_model
model = get_model('resnext50-32x4d_8xb32_in1k', pretrained=True)
inputs = torch.rand(1, 3, 224, 224)
out = model(inputs)
print(type(out))
# To extract features.
feats = model.extract_feat(inputs)
print(type(feats))
```
**Train/Test Command**
Prepare your dataset according to the [docs](https://mmpretrain.readthedocs.io/en/latest/user_guides/dataset_prepare.html#prepare-dataset).
Train:
```shell
python tools/train.py configs/resnext/resnext50-32x4d_8xb32_in1k.py
```
Test:
```shell
python tools/test.py configs/resnext/resnext50-32x4d_8xb32_in1k.py https://download.openmmlab.com/mmclassification/v0/resnext/resnext50_32x4d_b32x8_imagenet_20210429-56066e27.pth
```
<!-- [TABS-END] -->
## Models and results
### Image Classification on ImageNet-1k
| Model | Pretrain | Params (M) | Flops (G) | Top-1 (%) | Top-5 (%) | Config | Download |
| :---------------------------- | :----------: | :--------: | :-------: | :-------: | :-------: | :--------------------------------------: | :--------------------------------------------------------------------------------: |
| `resnext50-32x4d_8xb32_in1k` | From scratch | 25.03 | 4.27 | 77.90 | 93.66 | [config](resnext50-32x4d_8xb32_in1k.py) | [model](https://download.openmmlab.com/mmclassification/v0/resnext/resnext50_32x4d_b32x8_imagenet_20210429-56066e27.pth) \| [log](https://download.openmmlab.com/mmclassification/v0/resnext/resnext50_32x4d_b32x8_imagenet_20210429-56066e27.json) |
| `resnext101-32x4d_8xb32_in1k` | From scratch | 44.18 | 8.03 | 78.61 | 94.17 | [config](resnext101-32x4d_8xb32_in1k.py) | [model](https://download.openmmlab.com/mmclassification/v0/resnext/resnext101_32x4d_b32x8_imagenet_20210506-e0fa3dd5.pth) \| [log](https://download.openmmlab.com/mmclassification/v0/resnext/resnext101_32x4d_b32x8_imagenet_20210506-e0fa3dd5.json) |
| `resnext101-32x8d_8xb32_in1k` | From scratch | 88.79 | 16.50 | 79.27 | 94.58 | [config](resnext101-32x8d_8xb32_in1k.py) | [model](https://download.openmmlab.com/mmclassification/v0/resnext/resnext101_32x8d_b32x8_imagenet_20210506-23a247d5.pth) \| [log](https://download.openmmlab.com/mmclassification/v0/resnext/resnext101_32x8d_b32x8_imagenet_20210506-23a247d5.json) |
| `resnext152-32x4d_8xb32_in1k` | From scratch | 59.95 | 11.80 | 78.88 | 94.33 | [config](resnext152-32x4d_8xb32_in1k.py) | [model](https://download.openmmlab.com/mmclassification/v0/resnext/resnext152_32x4d_b32x8_imagenet_20210524-927787be.pth) \| [log](https://download.openmmlab.com/mmclassification/v0/resnext/resnext152_32x4d_b32x8_imagenet_20210524-927787be.json) |
## Citation
```bibtex
@inproceedings{xie2017aggregated,
title={Aggregated residual transformations for deep neural networks},
author={Xie, Saining and Girshick, Ross and Doll{\'a}r, Piotr and Tu, Zhuowen and He, Kaiming},
booktitle={Proceedings of the IEEE conference on computer vision and pattern recognition},
pages={1492--1500},
year={2017}
}
```
Collections:
- Name: ResNeXt
Metadata:
Training Data: ImageNet-1k
Training Techniques:
- SGD with Momentum
- Weight Decay
Training Resources: 8x V100 GPUs
Epochs: 100
Batch Size: 256
Architecture:
- ResNeXt
Paper:
URL: https://openaccess.thecvf.com/content_cvpr_2017/html/Xie_Aggregated_Residual_Transformations_CVPR_2017_paper.html
Title: "Aggregated Residual Transformations for Deep Neural Networks"
README: configs/resnext/README.md
Code:
URL: https://github.com/open-mmlab/mmpretrain/blob/v0.15.0/mmcls/models/backbones/resnext.py#L90
Version: v0.15.0
Models:
- Name: resnext50-32x4d_8xb32_in1k
Metadata:
FLOPs: 4270000000
Parameters: 25030000
In Collection: ResNeXt
Results:
- Dataset: ImageNet-1k
Metrics:
Top 1 Accuracy: 77.90
Top 5 Accuracy: 93.66
Task: Image Classification
Weights: https://download.openmmlab.com/mmclassification/v0/resnext/resnext50_32x4d_b32x8_imagenet_20210429-56066e27.pth
Config: configs/resnext/resnext50-32x4d_8xb32_in1k.py
- Name: resnext101-32x4d_8xb32_in1k
Metadata:
FLOPs: 8030000000
Parameters: 44180000
In Collection: ResNeXt
Results:
- Dataset: ImageNet-1k
Metrics:
Top 1 Accuracy: 78.61
Top 5 Accuracy: 94.17
Task: Image Classification
Weights: https://download.openmmlab.com/mmclassification/v0/resnext/resnext101_32x4d_b32x8_imagenet_20210506-e0fa3dd5.pth
Config: configs/resnext/resnext101-32x4d_8xb32_in1k.py
- Name: resnext101-32x8d_8xb32_in1k
Metadata:
FLOPs: 16500000000
Parameters: 88790000
In Collection: ResNeXt
Results:
- Dataset: ImageNet-1k
Metrics:
Top 1 Accuracy: 79.27
Top 5 Accuracy: 94.58
Task: Image Classification
Weights: https://download.openmmlab.com/mmclassification/v0/resnext/resnext101_32x8d_b32x8_imagenet_20210506-23a247d5.pth
Config: configs/resnext/resnext101-32x8d_8xb32_in1k.py
- Name: resnext152-32x4d_8xb32_in1k
Metadata:
FLOPs: 11800000000
Parameters: 59950000
In Collection: ResNeXt
Results:
- Dataset: ImageNet-1k
Metrics:
Top 1 Accuracy: 78.88
Top 5 Accuracy: 94.33
Task: Image Classification
Weights: https://download.openmmlab.com/mmclassification/v0/resnext/resnext152_32x4d_b32x8_imagenet_20210524-927787be.pth
Config: configs/resnext/resnext152-32x4d_8xb32_in1k.py
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment