Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
8395f573
P
Paddle
项目概览
机器未来
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
8395f573
编写于
11月 11, 2021
作者:
N
Nyakku Shigure
提交者:
GitHub
11月 11, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[PaddlePaddle Hackathon] add WideResNet (#36952)
* add wide resnet * update pretrained weights link
上级
498dbfa8
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
149 addition
and
17 deletion
+149
-17
python/paddle/tests/test_pretrained_model.py
python/paddle/tests/test_pretrained_model.py
+1
-1
python/paddle/tests/test_vision_models.py
python/paddle/tests/test_vision_models.py
+6
-0
python/paddle/vision/__init__.py
python/paddle/vision/__init__.py
+2
-0
python/paddle/vision/models/__init__.py
python/paddle/vision/models/__init__.py
+4
-0
python/paddle/vision/models/resnet.py
python/paddle/vision/models/resnet.py
+136
-16
未找到文件。
python/paddle/tests/test_pretrained_model.py
浏览文件 @
8395f573
...
...
@@ -56,7 +56,7 @@ class TestPretrainedModel(unittest.TestCase):
'mobilenet_v1'
,
'mobilenet_v2'
,
'resnet18'
,
'vgg16'
,
'alexnet'
,
'resnext50_32x4d'
,
'inception_v3'
,
'densenet121'
,
'squeezenet1_0'
,
'squeezenet1_1'
,
'googlenet'
,
'shufflenet_v2_x0_25'
,
'shufflenet_v2_swish'
'shufflenet_v2_swish'
,
'wide_resnet50_2'
,
'wide_resnet101_2'
]
for
arch
in
arches
:
self
.
infer
(
arch
)
...
...
python/paddle/tests/test_vision_models.py
浏览文件 @
8395f573
...
...
@@ -70,6 +70,12 @@ class TestVisonModels(unittest.TestCase):
def
test_resnet152
(
self
):
self
.
models_infer
(
'resnet152'
)
def
test_wide_resnet50_2
(
self
):
self
.
models_infer
(
'wide_resnet50_2'
)
def
test_wide_resnet101_2
(
self
):
self
.
models_infer
(
'wide_resnet101_2'
)
def
test_densenet121
(
self
):
self
.
models_infer
(
'densenet121'
)
...
...
python/paddle/vision/__init__.py
浏览文件 @
8395f573
...
...
@@ -34,6 +34,8 @@ from .models import resnet34 # noqa: F401
from
.models
import
resnet50
# noqa: F401
from
.models
import
resnet101
# noqa: F401
from
.models
import
resnet152
# noqa: F401
from
.models
import
wide_resnet50_2
# noqa: F401
from
.models
import
wide_resnet101_2
# noqa: F401
from
.models
import
MobileNetV1
# noqa: F401
from
.models
import
mobilenet_v1
# noqa: F401
from
.models
import
MobileNetV2
# noqa: F401
...
...
python/paddle/vision/models/__init__.py
浏览文件 @
8395f573
...
...
@@ -18,6 +18,8 @@ from .resnet import resnet34 # noqa: F401
from
.resnet
import
resnet50
# noqa: F401
from
.resnet
import
resnet101
# noqa: F401
from
.resnet
import
resnet152
# noqa: F401
from
.resnet
import
wide_resnet50_2
# noqa: F401
from
.resnet
import
wide_resnet101_2
# noqa: F401
from
.mobilenetv1
import
MobileNetV1
# noqa: F401
from
.mobilenetv1
import
mobilenet_v1
# noqa: F401
from
.mobilenetv2
import
MobileNetV2
# noqa: F401
...
...
@@ -66,6 +68,8 @@ __all__ = [ #noqa
'resnet50'
,
'resnet101'
,
'resnet152'
,
'wide_resnet50_2'
,
'wide_resnet101_2'
,
'VGG'
,
'vgg11'
,
'vgg13'
,
...
...
python/paddle/vision/models/resnet.py
浏览文件 @
8395f573
...
...
@@ -33,6 +33,12 @@ model_urls = {
'02f35f034ca3858e1e54d4036443c92d'
),
'resnet152'
:
(
'https://paddle-hapi.bj.bcebos.com/models/resnet152.pdparams'
,
'7ad16a2f1e7333859ff986138630fd7a'
),
'wide_resnet50_2'
:
(
'https://paddle-hapi.bj.bcebos.com/models/wide_resnet50_2.pdparams'
,
'0282f804d73debdab289bd9fea3fa6dc'
),
'wide_resnet101_2'
:
(
'https://paddle-hapi.bj.bcebos.com/models/wide_resnet101_2.pdparams'
,
'd4360a2d23657f059216f5d5a1a9ac93'
),
}
...
...
@@ -153,23 +159,37 @@ class ResNet(nn.Layer):
Args:
Block (BasicBlock|BottleneckBlock): block module of model.
depth (int): layers of resnet, default: 50.
num_classes (int): output dim of last fc layer. If num_classes <=0, last fc layer
width (int): base width of resnet, default: 64.
num_classes (int): output dim of last fc layer. If num_classes <=0, last fc layer
will not be defined. Default: 1000.
with_pool (bool): use pool before the last fc layer or not. Default: True.
Examples:
.. code-block:: python
import paddle
from paddle.vision.models import ResNet
from paddle.vision.models.resnet import BottleneckBlock, BasicBlock
resnet50 = ResNet(BottleneckBlock, 50)
wide_resnet50_2 = ResNet(BottleneckBlock, 50, width=64*2)
resnet18 = ResNet(BasicBlock, 18)
x = paddle.rand([1, 3, 224, 224])
out = resnet18(x)
print(out.shape)
"""
def
__init__
(
self
,
block
,
depth
,
num_classes
=
1000
,
with_pool
=
True
):
def
__init__
(
self
,
block
,
depth
=
50
,
width
=
64
,
num_classes
=
1000
,
with_pool
=
True
):
super
(
ResNet
,
self
).
__init__
()
layer_cfg
=
{
18
:
[
2
,
2
,
2
,
2
],
...
...
@@ -179,6 +199,8 @@ class ResNet(nn.Layer):
152
:
[
3
,
8
,
36
,
3
]
}
layers
=
layer_cfg
[
depth
]
self
.
groups
=
1
self
.
base_width
=
width
self
.
num_classes
=
num_classes
self
.
with_pool
=
with_pool
self
.
_norm_layer
=
nn
.
BatchNorm2D
...
...
@@ -225,11 +247,17 @@ class ResNet(nn.Layer):
layers
=
[]
layers
.
append
(
block
(
self
.
inplanes
,
planes
,
stride
,
downsample
,
1
,
64
,
previous_dilation
,
norm_layer
))
block
(
self
.
inplanes
,
planes
,
stride
,
downsample
,
self
.
groups
,
self
.
base_width
,
previous_dilation
,
norm_layer
))
self
.
inplanes
=
planes
*
block
.
expansion
for
_
in
range
(
1
,
blocks
):
layers
.
append
(
block
(
self
.
inplanes
,
planes
,
norm_layer
=
norm_layer
))
layers
.
append
(
block
(
self
.
inplanes
,
planes
,
groups
=
self
.
groups
,
base_width
=
self
.
base_width
,
norm_layer
=
norm_layer
))
return
nn
.
Sequential
(
*
layers
)
...
...
@@ -268,14 +296,16 @@ def _resnet(arch, Block, depth, pretrained, **kwargs):
def
resnet18
(
pretrained
=
False
,
**
kwargs
):
"""ResNet 18-layer model
"""ResNet 18-layer model from
`"Deep Residual Learning for Image Recognition" <https://arxiv.org/pdf/1512.03385.pdf>`_
Args:
pretrained (bool): If True, returns a model pre-trained on ImageNet
Examples:
.. code-block:: python
import paddle
from paddle.vision.models import resnet18
# build model
...
...
@@ -283,19 +313,26 @@ def resnet18(pretrained=False, **kwargs):
# build model and load imagenet pretrained weight
# model = resnet18(pretrained=True)
x = paddle.rand([1, 3, 224, 224])
out = model(x)
print(out.shape)
"""
return
_resnet
(
'resnet18'
,
BasicBlock
,
18
,
pretrained
,
**
kwargs
)
def
resnet34
(
pretrained
=
False
,
**
kwargs
):
"""ResNet 34-layer model
"""ResNet 34-layer model from
`"Deep Residual Learning for Image Recognition" <https://arxiv.org/pdf/1512.03385.pdf>`_
Args:
pretrained (bool): If True, returns a model pre-trained on ImageNet
Examples:
.. code-block:: python
import paddle
from paddle.vision.models import resnet34
# build model
...
...
@@ -303,19 +340,26 @@ def resnet34(pretrained=False, **kwargs):
# build model and load imagenet pretrained weight
# model = resnet34(pretrained=True)
x = paddle.rand([1, 3, 224, 224])
out = model(x)
print(out.shape)
"""
return
_resnet
(
'resnet34'
,
BasicBlock
,
34
,
pretrained
,
**
kwargs
)
def
resnet50
(
pretrained
=
False
,
**
kwargs
):
"""ResNet 50-layer model
"""ResNet 50-layer model from
`"Deep Residual Learning for Image Recognition" <https://arxiv.org/pdf/1512.03385.pdf>`_
Args:
pretrained (bool): If True, returns a model pre-trained on ImageNet
Examples:
.. code-block:: python
import paddle
from paddle.vision.models import resnet50
# build model
...
...
@@ -323,19 +367,26 @@ def resnet50(pretrained=False, **kwargs):
# build model and load imagenet pretrained weight
# model = resnet50(pretrained=True)
x = paddle.rand([1, 3, 224, 224])
out = model(x)
print(out.shape)
"""
return
_resnet
(
'resnet50'
,
BottleneckBlock
,
50
,
pretrained
,
**
kwargs
)
def
resnet101
(
pretrained
=
False
,
**
kwargs
):
"""ResNet 101-layer model
"""ResNet 101-layer model from
`"Deep Residual Learning for Image Recognition" <https://arxiv.org/pdf/1512.03385.pdf>`_
Args:
pretrained (bool): If True, returns a model pre-trained on ImageNet
Examples:
.. code-block:: python
import paddle
from paddle.vision.models import resnet101
# build model
...
...
@@ -343,19 +394,26 @@ def resnet101(pretrained=False, **kwargs):
# build model and load imagenet pretrained weight
# model = resnet101(pretrained=True)
x = paddle.rand([1, 3, 224, 224])
out = model(x)
print(out.shape)
"""
return
_resnet
(
'resnet101'
,
BottleneckBlock
,
101
,
pretrained
,
**
kwargs
)
def
resnet152
(
pretrained
=
False
,
**
kwargs
):
"""ResNet 152-layer model
"""ResNet 152-layer model from
`"Deep Residual Learning for Image Recognition" <https://arxiv.org/pdf/1512.03385.pdf>`_
Args:
pretrained (bool): If True, returns a model pre-trained on ImageNet
Examples:
.. code-block:: python
import paddle
from paddle.vision.models import resnet152
# build model
...
...
@@ -363,5 +421,67 @@ def resnet152(pretrained=False, **kwargs):
# build model and load imagenet pretrained weight
# model = resnet152(pretrained=True)
x = paddle.rand([1, 3, 224, 224])
out = model(x)
print(out.shape)
"""
return
_resnet
(
'resnet152'
,
BottleneckBlock
,
152
,
pretrained
,
**
kwargs
)
def
wide_resnet50_2
(
pretrained
=
False
,
**
kwargs
):
"""Wide ResNet-50-2 model from
`"Wide Residual Networks" <https://arxiv.org/pdf/1605.07146.pdf>`_.
Args:
pretrained (bool): If True, returns a model pre-trained on ImageNet
Examples:
.. code-block:: python
import paddle
from paddle.vision.models import wide_resnet50_2
# build model
model = wide_resnet50_2()
# build model and load imagenet pretrained weight
# model = wide_resnet50_2(pretrained=True)
x = paddle.rand([1, 3, 224, 224])
out = model(x)
print(out.shape)
"""
kwargs
[
'width'
]
=
64
*
2
return
_resnet
(
'wide_resnet50_2'
,
BottleneckBlock
,
50
,
pretrained
,
**
kwargs
)
def
wide_resnet101_2
(
pretrained
=
False
,
**
kwargs
):
"""Wide ResNet-101-2 model from
`"Wide Residual Networks" <https://arxiv.org/pdf/1605.07146.pdf>`_.
Args:
pretrained (bool): If True, returns a model pre-trained on ImageNet
Examples:
.. code-block:: python
import paddle
from paddle.vision.models import wide_resnet101_2
# build model
model = wide_resnet101_2()
# build model and load imagenet pretrained weight
# model = wide_resnet101_2(pretrained=True)
x = paddle.rand([1, 3, 224, 224])
out = model(x)
print(out.shape)
"""
kwargs
[
'width'
]
=
64
*
2
return
_resnet
(
'wide_resnet101_2'
,
BottleneckBlock
,
101
,
pretrained
,
**
kwargs
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录