Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
5356f2e0
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 2 年 前同步成功
通知
2325
Star
20933
Fork
5424
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
5356f2e0
编写于
8月 17, 2023
作者:
C
cyberslack_lee
提交者:
GitHub
8月 17, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[xdoctest] reformat example code with google style in No.150-160 (#56178)
* test=docs_preview * test=docs_preview
上级
dcfe2f1a
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
315 addition
and
288 deletion
+315
-288
python/paddle/text/datasets/wmt16.py
python/paddle/text/datasets/wmt16.py
+37
-30
python/paddle/text/viterbi_decode.py
python/paddle/text/viterbi_decode.py
+38
-24
python/paddle/vision/models/_utils.py
python/paddle/vision/models/_utils.py
+16
-13
python/paddle/vision/models/alexnet.py
python/paddle/vision/models/alexnet.py
+19
-21
python/paddle/vision/models/densenet.py
python/paddle/vision/models/densenet.py
+66
-59
python/paddle/vision/models/googlenet.py
python/paddle/vision/models/googlenet.py
+20
-20
python/paddle/vision/models/inceptionv3.py
python/paddle/vision/models/inceptionv3.py
+19
-19
python/paddle/vision/models/lenet.py
python/paddle/vision/models/lenet.py
+8
-8
python/paddle/vision/models/mobilenetv1.py
python/paddle/vision/models/mobilenetv1.py
+21
-21
python/paddle/vision/models/mobilenetv2.py
python/paddle/vision/models/mobilenetv2.py
+21
-22
python/paddle/vision/models/mobilenetv3.py
python/paddle/vision/models/mobilenetv3.py
+50
-51
未找到文件。
python/paddle/text/datasets/wmt16.py
浏览文件 @
5356f2e0
...
@@ -59,13 +59,13 @@ class WMT16(Dataset):
...
@@ -59,13 +59,13 @@ class WMT16(Dataset):
Args:
Args:
data_file(str): path to data tar file, can be set None if
data_file(str): path to data tar file, can be set None if
:attr:`download` is True. Default None
:attr:`download` is True. Default None
.
mode(str): 'train', 'test' or 'val'. Default 'train'
mode(str): 'train', 'test' or 'val'. Default 'train'
.
src_dict_size(int): word dictionary size for source language word. Default -1.
src_dict_size(int): word dictionary size for source language word. Default -1.
trg_dict_size(int): word dictionary size for target language word. Default -1.
trg_dict_size(int): word dictionary size for target language word. Default -1.
lang(str): source language, 'en' or 'de'. Default 'en'.
lang(str): source language, 'en' or 'de'. Default 'en'.
download(bool): whether to download dataset automatically if
download(bool): whether to download dataset automatically if
:attr:`data_file` is not set. Default True
:attr:`data_file` is not set. Default True
.
Returns:
Returns:
Dataset: Instance of WMT16 dataset. The instance of dataset has 3 fields:
Dataset: Instance of WMT16 dataset. The instance of dataset has 3 fields:
...
@@ -77,30 +77,37 @@ class WMT16(Dataset):
...
@@ -77,30 +77,37 @@ class WMT16(Dataset):
.. code-block:: python
.. code-block:: python
import paddle
>>> import paddle
from paddle.text.datasets import WMT16
>>> from paddle.text.datasets import WMT16
class SimpleNet(paddle.nn.Layer):
>>> class SimpleNet(paddle.nn.Layer):
def __init__(self):
... def __init__(self):
super().__init__()
... super().__init__()
...
def forward(self, src_ids, trg_ids, trg_ids_next):
... def forward(self, src_ids, trg_ids, trg_ids_next):
return paddle.sum(src_ids), paddle.sum(trg_ids), paddle.sum(trg_ids_next)
... return paddle.sum(src_ids), paddle.sum(trg_ids), paddle.sum(trg_ids_next)
paddle.disable_static()
>>> wmt16 = WMT16(mode='train', src_dict_size=50, trg_dict_size=50)
wmt16 = WMT16(mode='train', src_dict_size=50, trg_dict_size=50)
>>> for i in range(10):
... src_ids, trg_ids, trg_ids_next = wmt16[i]
for i in range(10):
... src_ids = paddle.to_tensor(src_ids)
src_ids, trg_ids, trg_ids_next = wmt16[i]
... trg_ids = paddle.to_tensor(trg_ids)
src_ids = paddle.to_tensor(src_ids)
... trg_ids_next = paddle.to_tensor(trg_ids_next)
trg_ids = paddle.to_tensor(trg_ids)
...
trg_ids_next = paddle.to_tensor(trg_ids_next)
... model = SimpleNet()
... src_ids, trg_ids, trg_ids_next = model(src_ids, trg_ids, trg_ids_next)
model = SimpleNet()
... print(src_ids.item(), trg_ids.item(), trg_ids_next.item())
src_ids, trg_ids, trg_ids_next = model(src_ids, trg_ids, trg_ids_next)
89 32 33
print(src_ids.numpy(), trg_ids.numpy(), trg_ids_next.numpy())
79 18 19
55 26 27
147 36 37
106 22 23
135 50 51
54 43 44
217 30 31
146 51 52
55 24 25
"""
"""
def
__init__
(
def
__init__
(
...
@@ -257,9 +264,9 @@ class WMT16(Dataset):
...
@@ -257,9 +264,9 @@ class WMT16(Dataset):
.. code-block:: python
.. code-block:: python
from paddle.text.datasets import WMT16
>>>
from paddle.text.datasets import WMT16
wmt16 = WMT16(mode='train', src_dict_size=50, trg_dict_size=50)
>>>
wmt16 = WMT16(mode='train', src_dict_size=50, trg_dict_size=50)
en_dict = wmt16.get_dict('en')
>>>
en_dict = wmt16.get_dict('en')
"""
"""
dict_size
=
(
dict_size
=
(
...
...
python/paddle/text/viterbi_decode.py
浏览文件 @
5356f2e0
...
@@ -42,20 +42,27 @@ def viterbi_decode(
...
@@ -42,20 +42,27 @@ def viterbi_decode(
Returns:
Returns:
scores(Tensor): The output tensor containing the score for the Viterbi sequence. The shape is [batch_size]
scores(Tensor): The output tensor containing the score for the Viterbi sequence. The shape is [batch_size]
and the data type is float32 or float64.
and the data type is float32 or float64.
paths(Tensor): The output tensor containing the highest scoring tag indices.
The shape is [batch_size, sequence_length]
paths(Tensor): The output tensor containing the highest scoring tag indices. The shape is [batch_size, sequence_length]
and
the data type is int64.
and the data type is int64.
Example:
Example
s
:
.. code-block:: python
.. code-block:: python
import paddle
>>> import paddle
paddle.seed(102)
>>> paddle.seed(2023)
batch_size, seq_len, num_tags = 2, 4, 3
>>> batch_size, seq_len, num_tags = 2, 4, 3
emission = paddle.rand((batch_size, seq_len, num_tags), dtype='float32')
>>> emission = paddle.rand((batch_size, seq_len, num_tags), dtype='float32')
length = paddle.randint(1, seq_len + 1, [batch_size])
>>> length = paddle.randint(1, seq_len + 1, [batch_size])
tags = paddle.randint(0, num_tags, [batch_size, seq_len])
>>> tags = paddle.randint(0, num_tags, [batch_size, seq_len])
transition = paddle.rand((num_tags, num_tags), dtype='float32')
>>> transition = paddle.rand((num_tags, num_tags), dtype='float32')
scores, path = paddle.text.viterbi_decode(emission, transition, length, False) # scores: [3.37089300, 1.56825531], path: [[1, 0, 0], [1, 1, 0]]
>>> scores, path = paddle.text.viterbi_decode(emission, transition, length, False)
>>> print(scores)
Tensor(shape=[2], dtype=float32, place=Place(cpu), stop_gradient=True,
[2.57385254, 2.04533720])
>>> print(path)
Tensor(shape=[2, 2], dtype=int64, place=Place(cpu), stop_gradient=True,
[[0, 0],
[1, 1]])
"""
"""
if
in_dygraph_mode
():
if
in_dygraph_mode
():
return
_C_ops
.
viterbi_decode
(
return
_C_ops
.
viterbi_decode
(
...
@@ -95,7 +102,7 @@ class ViterbiDecoder(Layer):
...
@@ -95,7 +102,7 @@ class ViterbiDecoder(Layer):
Decode the highest scoring sequence of tags computed by transitions and potentials and get the viterbi path.
Decode the highest scoring sequence of tags computed by transitions and potentials and get the viterbi path.
Args:
Args:
transitions (`Tensor`): The transition matrix.
Its dtype is float32 and has a shape of `[num_tags, num_tags]`.
transitions (`Tensor`): The transition matrix. Its dtype is float32 and has a shape of `[num_tags, num_tags]`.
include_bos_eos_tag (`bool`, optional): If set to True, the last row and the last column of transitions will be considered
include_bos_eos_tag (`bool`, optional): If set to True, the last row and the last column of transitions will be considered
as start tag, the second to last row and the second to last column of transitions will be considered as stop tag. Defaults to ``True``.
as start tag, the second to last row and the second to last column of transitions will be considered as stop tag. Defaults to ``True``.
name (str, optional): The default value is None. Normally there is no need for user to set this property. For more information, please
name (str, optional): The default value is None. Normally there is no need for user to set this property. For more information, please
...
@@ -104,27 +111,34 @@ class ViterbiDecoder(Layer):
...
@@ -104,27 +111,34 @@ class ViterbiDecoder(Layer):
Shape:
Shape:
potentials (Tensor): The input tensor of unary emission. This is a 3-D tensor with shape of
potentials (Tensor): The input tensor of unary emission. This is a 3-D tensor with shape of
[batch_size, sequence_length, num_tags]. The data type is float32 or float64.
[batch_size, sequence_length, num_tags]. The data type is float32 or float64.
lengths (Tensor):
The input tensor of length of each sequence. This is a 1-D tensor with shape of
lengths (Tensor): The input tensor of length of each sequence. This is a 1-D tensor with shape of
[batch_size]. The data type is int64.
[batch_size]. The data type is int64.
Returns:
Returns:
scores(Tensor): The output tensor containing the score for the Viterbi sequence. The shape is [batch_size]
scores(Tensor): The output tensor containing the score for the Viterbi sequence. The shape is [batch_size]
and the data type is float32 or float64.
and the data type is float32 or float64.
paths(Tensor): The output tensor containing the highest scoring tag indices.
The shape is [batch_size, sequence_length]
paths(Tensor): The output tensor containing the highest scoring tag indices. The shape is [batch_size, sequence_length]
and the data type is int64.
and the data type is int64.
Example:
Example
s
:
.. code-block:: python
.. code-block:: python
import paddle
>>> import paddle
paddle.seed(102)
>>> paddle.seed(2023)
batch_size, seq_len, num_tags = 2, 4, 3
>>> batch_size, seq_len, num_tags = 2, 4, 3
emission = paddle.rand((batch_size, seq_len, num_tags), dtype='float32')
>>> emission = paddle.rand((batch_size, seq_len, num_tags), dtype='float32')
length = paddle.randint(1, seq_len + 1, [batch_size])
>>> length = paddle.randint(1, seq_len + 1, [batch_size])
tags = paddle.randint(0, num_tags, [batch_size, seq_len])
>>> tags = paddle.randint(0, num_tags, [batch_size, seq_len])
transition = paddle.rand((num_tags, num_tags), dtype='float32')
>>> transition = paddle.rand((num_tags, num_tags), dtype='float32')
decoder = paddle.text.ViterbiDecoder(transition, include_bos_eos_tag=False)
>>> decoder = paddle.text.ViterbiDecoder(transition, include_bos_eos_tag=False)
scores, path = decoder(emission, length) # scores: [3.37089300, 1.56825531], path: [[1, 0, 0], [1, 1, 0]]
>>> scores, path = decoder(emission, length)
>>> print(scores)
Tensor(shape=[2], dtype=float32, place=Place(cpu), stop_gradient=True,
[2.57385254, 2.04533720])
>>> print(path)
Tensor(shape=[2, 2], dtype=int64, place=Place(cpu), stop_gradient=True,
[[0, 0],
[1, 1]])
"""
"""
def
__init__
(
self
,
transitions
,
include_bos_eos_tag
=
True
,
name
=
None
):
def
__init__
(
self
,
transitions
,
include_bos_eos_tag
=
True
,
name
=
None
):
...
...
python/paddle/vision/models/_utils.py
浏览文件 @
5356f2e0
...
@@ -21,13 +21,13 @@ from paddle import nn
...
@@ -21,13 +21,13 @@ from paddle import nn
def
_make_divisible
(
v
,
divisor
=
8
,
min_value
=
None
):
def
_make_divisible
(
v
,
divisor
=
8
,
min_value
=
None
):
"""
"""
This function ensures that all layers have a channel number that is divisible by divisor
This function ensures that all layers have a channel number that is divisible by divisor
.
You can also see at https://github.com/keras-team/keras/blob/8ecef127f70db723c158dbe9ed3268b3d610ab55/keras/applications/mobilenet_v2.py#L505
You can also see at https://github.com/keras-team/keras/blob/8ecef127f70db723c158dbe9ed3268b3d610ab55/keras/applications/mobilenet_v2.py#L505
Args:
Args:
divisor (int): The divisor for number of channels. Default: 8.
divisor (int
, optional
): The divisor for number of channels. Default: 8.
min_value (int, optional): The minimum value of number of channels, if it is None,
min_value (int, optional): The minimum value of number of channels, if it is None,
the default is divisor. Default: None.
the default is divisor. Default: None.
"""
"""
if
min_value
is
None
:
if
min_value
is
None
:
min_value
=
divisor
min_value
=
divisor
...
@@ -50,22 +50,25 @@ class IntermediateLayerGetter(nn.LayerDict):
...
@@ -50,22 +50,25 @@ class IntermediateLayerGetter(nn.LayerDict):
So if `model` is passed, `model.feature1` can be returned, but not `model.feature1.layer2`.
So if `model` is passed, `model.feature1` can be returned, but not `model.feature1.layer2`.
Args:
Args:
model (nn.Layer): model on which we will extract the features
return_layers (Dict[name, new_name]): a dict containing the names of the layers for
model (nn.Layer): Model on which we will extract the features.
return_layers (Dict[name, new_name]): A dict containing the names of the layers for
which the activations will be returned as the key of the dict, and the value of the
which the activations will be returned as the key of the dict, and the value of the
dict is the name of the returned activation (which the user can specify).
dict is the name of the returned activation (which the user can specify).
Examples:
Examples:
.. code-block:: python
.. code-block:: python
import paddle
>>> import paddle
m = paddle.vision.models.resnet18(pretrained=False)
>>> m = paddle.vision.models.resnet18(pretrained=False)
# extract layer1 and layer3, giving as names `feat1` and feat2`
new_m = paddle.vision.models._utils.IntermediateLayerGetter(m,
>>> # extract layer1 and layer3, giving as names `feat1` and feat2`
{'layer1': 'feat1', 'layer3': 'feat2'})
>>> new_m = paddle.vision.models._utils.IntermediateLayerGetter(m,
out = new_m(paddle.rand([1, 3, 224, 224]))
... {'layer1': 'feat1', 'layer3': 'feat2'})
print([(k, v.shape) for k, v in out.items()])
>>> out = new_m(paddle.rand([1, 3, 224, 224]))
# [('feat1', [1, 64, 56, 56]), ('feat2', [1, 256, 14, 14])]
>>> print([(k, v.shape) for k, v in out.items()])
[('feat1', [1, 64, 56, 56]), ('feat2', [1, 256, 14, 14])]
"""
"""
__annotations__
=
{
__annotations__
=
{
...
...
python/paddle/vision/models/alexnet.py
浏览文件 @
5356f2e0
...
@@ -75,7 +75,7 @@ class AlexNet(nn.Layer):
...
@@ -75,7 +75,7 @@ class AlexNet(nn.Layer):
Args:
Args:
num_classes (int, optional): Output dim of last fc layer. If num_classes <= 0, last fc layer
num_classes (int, optional): Output dim of last fc layer. If num_classes <= 0, last fc layer
will not be defined. Default: 1000.
will not be defined. Default: 1000.
Returns:
Returns:
:ref:`api_paddle_nn_Layer`. An instance of AlexNet model.
:ref:`api_paddle_nn_Layer`. An instance of AlexNet model.
...
@@ -83,16 +83,14 @@ class AlexNet(nn.Layer):
...
@@ -83,16 +83,14 @@ class AlexNet(nn.Layer):
Examples:
Examples:
.. code-block:: python
.. code-block:: python
import paddle
>>>
import paddle
from paddle.vision.models import AlexNet
>>>
from paddle.vision.models import AlexNet
alexnet = AlexNet()
>>> alexnet = AlexNet()
>>> x = paddle.rand([1, 3, 224, 224])
x = paddle.rand([1, 3, 224, 224])
>>> out = alexnet(x)
out = alexnet(x)
>>> print(out.shape)
[1, 1000]
print(out.shape)
# [1, 1000]
"""
"""
def
__init__
(
self
,
num_classes
=
1000
):
def
__init__
(
self
,
num_classes
=
1000
):
...
@@ -197,7 +195,7 @@ def alexnet(pretrained=False, **kwargs):
...
@@ -197,7 +195,7 @@ def alexnet(pretrained=False, **kwargs):
Args:
Args:
pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained
pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained
on ImageNet. Default: False.
on ImageNet. Default: False.
**kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`AlexNet <api_paddle_vision_AlexNet>`.
**kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`AlexNet <api_paddle_vision_AlexNet>`.
Returns:
Returns:
...
@@ -206,19 +204,19 @@ def alexnet(pretrained=False, **kwargs):
...
@@ -206,19 +204,19 @@ def alexnet(pretrained=False, **kwargs):
Examples:
Examples:
.. code-block:: python
.. code-block:: python
import paddle
>>>
import paddle
from paddle.vision.models import alexnet
>>>
from paddle.vision.models import alexnet
# b
uild model
>>> # B
uild model
model = alexnet()
>>>
model = alexnet()
# b
uild model and load imagenet pretrained weight
>>> # B
uild model and load imagenet pretrained weight
# model = alexnet(pretrained=True)
>>>
# model = alexnet(pretrained=True)
x = paddle.rand([1, 3, 224, 224])
>>>
x = paddle.rand([1, 3, 224, 224])
out = model(x)
>>>
out = model(x)
print(out.shape)
>>>
print(out.shape)
#
[1, 1000]
[1, 1000]
"""
"""
return
_alexnet
(
'alexnet'
,
pretrained
,
**
kwargs
)
return
_alexnet
(
'alexnet'
,
pretrained
,
**
kwargs
)
python/paddle/vision/models/densenet.py
浏览文件 @
5356f2e0
...
@@ -209,7 +209,7 @@ class DenseNet(nn.Layer):
...
@@ -209,7 +209,7 @@ class DenseNet(nn.Layer):
bn_size (int, optional): Expansion of growth rate in the middle layer. Default: 4.
bn_size (int, optional): Expansion of growth rate in the middle layer. Default: 4.
dropout (float, optional): Dropout rate. Default: :math:`0.0`.
dropout (float, optional): Dropout rate. Default: :math:`0.0`.
num_classes (int, optional): Output dim of last fc layer. If num_classes <= 0, last fc layer
num_classes (int, optional): Output dim of last fc layer. If num_classes <= 0, last fc layer
will not be defined. Default: 1000.
will not be defined. Default: 1000.
with_pool (bool, optional): Use pool before the last fc layer or not. Default: True.
with_pool (bool, optional): Use pool before the last fc layer or not. Default: True.
Returns:
Returns:
...
@@ -218,17 +218,17 @@ class DenseNet(nn.Layer):
...
@@ -218,17 +218,17 @@ class DenseNet(nn.Layer):
Examples:
Examples:
.. code-block:: python
.. code-block:: python
import paddle
>>>
import paddle
from paddle.vision.models import DenseNet
>>>
from paddle.vision.models import DenseNet
# b
uild model
>>> # B
uild model
densenet = DenseNet()
>>>
densenet = DenseNet()
x = paddle.rand([1, 3, 224, 224])
>>>
x = paddle.rand([1, 3, 224, 224])
out = densenet(x)
>>>
out = densenet(x)
print(out.shape)
>>>
print(out.shape)
#
[1, 1000]
[1, 1000]
"""
"""
def
__init__
(
def
__init__
(
...
@@ -360,7 +360,7 @@ def densenet121(pretrained=False, **kwargs):
...
@@ -360,7 +360,7 @@ def densenet121(pretrained=False, **kwargs):
Args:
Args:
pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained
pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained
on ImageNet. Default: False.
on ImageNet. Default: False.
**kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`DenseNet <api_paddle_vision_DenseNet>`.
**kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`DenseNet <api_paddle_vision_DenseNet>`.
Returns:
Returns:
...
@@ -369,20 +369,20 @@ def densenet121(pretrained=False, **kwargs):
...
@@ -369,20 +369,20 @@ def densenet121(pretrained=False, **kwargs):
Examples:
Examples:
.. code-block:: python
.. code-block:: python
import paddle
>>>
import paddle
from paddle.vision.models import densenet121
>>>
from paddle.vision.models import densenet121
# b
uild model
>>> # B
uild model
model = densenet121()
>>>
model = densenet121()
# b
uild model and load imagenet pretrained weight
>>> # B
uild model and load imagenet pretrained weight
# model = densenet121(pretrained=True)
>>>
# model = densenet121(pretrained=True)
x = paddle.rand([1, 3, 224, 224])
>>>
x = paddle.rand([1, 3, 224, 224])
out = model(x)
>>>
out = model(x)
print(out.shape)
>>>
print(out.shape)
#
[1, 1000]
[1, 1000]
"""
"""
return
_densenet
(
'densenet121'
,
121
,
pretrained
,
**
kwargs
)
return
_densenet
(
'densenet121'
,
121
,
pretrained
,
**
kwargs
)
...
@@ -393,7 +393,7 @@ def densenet161(pretrained=False, **kwargs):
...
@@ -393,7 +393,7 @@ def densenet161(pretrained=False, **kwargs):
Args:
Args:
pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained
pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained
on ImageNet. Default: False.
on ImageNet. Default: False.
**kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`DenseNet <api_paddle_vision_DenseNet>`.
**kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`DenseNet <api_paddle_vision_DenseNet>`.
Returns:
Returns:
...
@@ -402,13 +402,20 @@ def densenet161(pretrained=False, **kwargs):
...
@@ -402,13 +402,20 @@ def densenet161(pretrained=False, **kwargs):
Examples:
Examples:
.. code-block:: python
.. code-block:: python
from paddle.vision.models import densenet161
>>> import paddle
>>> from paddle.vision.models import densenet161
# b
uild model
>>> # B
uild model
model = densenet161()
>>>
model = densenet161()
# build model and load imagenet pretrained weight
>>> # Build model and load imagenet pretrained weight
# model = densenet161(pretrained=True)
>>> # model = densenet161(pretrained=True)
>>> x = paddle.rand([1, 3, 224, 224])
>>> out = model(x)
>>> print(out.shape)
[1, 1000]
"""
"""
return
_densenet
(
'densenet161'
,
161
,
pretrained
,
**
kwargs
)
return
_densenet
(
'densenet161'
,
161
,
pretrained
,
**
kwargs
)
...
@@ -419,7 +426,7 @@ def densenet169(pretrained=False, **kwargs):
...
@@ -419,7 +426,7 @@ def densenet169(pretrained=False, **kwargs):
Args:
Args:
pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained
pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained
on ImageNet. Default: False.
on ImageNet. Default: False.
**kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`DenseNet <api_paddle_vision_DenseNet>`.
**kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`DenseNet <api_paddle_vision_DenseNet>`.
Returns:
Returns:
...
@@ -428,20 +435,20 @@ def densenet169(pretrained=False, **kwargs):
...
@@ -428,20 +435,20 @@ def densenet169(pretrained=False, **kwargs):
Examples:
Examples:
.. code-block:: python
.. code-block:: python
import paddle
>>>
import paddle
from paddle.vision.models import densenet169
>>>
from paddle.vision.models import densenet169
# b
uild model
>>> # B
uild model
model = densenet169()
>>>
model = densenet169()
# b
uild model and load imagenet pretrained weight
>>> # B
uild model and load imagenet pretrained weight
# model = densenet169(pretrained=True)
>>>
# model = densenet169(pretrained=True)
x = paddle.rand([1, 3, 224, 224])
>>>
x = paddle.rand([1, 3, 224, 224])
out = model(x)
>>>
out = model(x)
print(out.shape)
>>>
print(out.shape)
#
[1, 1000]
[1, 1000]
"""
"""
return
_densenet
(
'densenet169'
,
169
,
pretrained
,
**
kwargs
)
return
_densenet
(
'densenet169'
,
169
,
pretrained
,
**
kwargs
)
...
@@ -452,7 +459,7 @@ def densenet201(pretrained=False, **kwargs):
...
@@ -452,7 +459,7 @@ def densenet201(pretrained=False, **kwargs):
Args:
Args:
pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained
pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained
on ImageNet. Default: False.
on ImageNet. Default: False.
**kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`DenseNet <api_paddle_vision_DenseNet>`.
**kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`DenseNet <api_paddle_vision_DenseNet>`.
Returns:
Returns:
...
@@ -461,19 +468,19 @@ def densenet201(pretrained=False, **kwargs):
...
@@ -461,19 +468,19 @@ def densenet201(pretrained=False, **kwargs):
Examples:
Examples:
.. code-block:: python
.. code-block:: python
import paddle
>>>
import paddle
from paddle.vision.models import densenet201
>>>
from paddle.vision.models import densenet201
# b
uild model
>>> # B
uild model
model = densenet201()
>>>
model = densenet201()
# b
uild model and load imagenet pretrained weight
>>> # B
uild model and load imagenet pretrained weight
# model = densenet201(pretrained=True)
>>>
# model = densenet201(pretrained=True)
x = paddle.rand([1, 3, 224, 224])
>>>
x = paddle.rand([1, 3, 224, 224])
out = model(x)
>>>
out = model(x)
print(out.shape)
>>>
print(out.shape)
#
[1, 1000]
[1, 1000]
"""
"""
return
_densenet
(
'densenet201'
,
201
,
pretrained
,
**
kwargs
)
return
_densenet
(
'densenet201'
,
201
,
pretrained
,
**
kwargs
)
...
@@ -484,7 +491,7 @@ def densenet264(pretrained=False, **kwargs):
...
@@ -484,7 +491,7 @@ def densenet264(pretrained=False, **kwargs):
Args:
Args:
pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained
pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained
on ImageNet. Default: False.
on ImageNet. Default: False.
**kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`DenseNet <api_paddle_vision_DenseNet>`.
**kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`DenseNet <api_paddle_vision_DenseNet>`.
Returns:
Returns:
...
@@ -493,19 +500,19 @@ def densenet264(pretrained=False, **kwargs):
...
@@ -493,19 +500,19 @@ def densenet264(pretrained=False, **kwargs):
Examples:
Examples:
.. code-block:: python
.. code-block:: python
import paddle
>>>
import paddle
from paddle.vision.models import densenet264
>>>
from paddle.vision.models import densenet264
# b
uild model
>>> # B
uild model
model = densenet264()
>>>
model = densenet264()
# b
uild model and load imagenet pretrained weight
>>> # B
uild model and load imagenet pretrained weight
# model = densenet264(pretrained=True)
>>>
# model = densenet264(pretrained=True)
x = paddle.rand([1, 3, 224, 224])
>>>
x = paddle.rand([1, 3, 224, 224])
out = model(x)
>>>
out = model(x)
print(out.shape)
>>>
print(out.shape)
#
[1, 1000]
[1, 1000]
"""
"""
return
_densenet
(
'densenet264'
,
264
,
pretrained
,
**
kwargs
)
return
_densenet
(
'densenet264'
,
264
,
pretrained
,
**
kwargs
)
python/paddle/vision/models/googlenet.py
浏览文件 @
5356f2e0
...
@@ -110,7 +110,7 @@ class GoogLeNet(nn.Layer):
...
@@ -110,7 +110,7 @@ class GoogLeNet(nn.Layer):
Args:
Args:
num_classes (int, optional): Output dim of last fc layer. If num_classes <= 0, last fc layer
num_classes (int, optional): Output dim of last fc layer. If num_classes <= 0, last fc layer
will not be defined. Default: 1000.
will not be defined. Default: 1000.
with_pool (bool, optional): Use pool before the last fc layer or not. Default: True.
with_pool (bool, optional): Use pool before the last fc layer or not. Default: True.
Returns:
Returns:
...
@@ -119,17 +119,17 @@ class GoogLeNet(nn.Layer):
...
@@ -119,17 +119,17 @@ class GoogLeNet(nn.Layer):
Examples:
Examples:
.. code-block:: python
.. code-block:: python
import paddle
>>>
import paddle
from paddle.vision.models import GoogLeNet
>>>
from paddle.vision.models import GoogLeNet
# b
uild model
>>> # B
uild model
model = GoogLeNet()
>>>
model = GoogLeNet()
x = paddle.rand([1, 3, 224, 224])
>>>
x = paddle.rand([1, 3, 224, 224])
out, out1, out2 = model(x)
>>>
out, out1, out2 = model(x)
print(out.shape, out1.shape, out2.shape)
>>>
print(out.shape, out1.shape, out2.shape)
#
[1, 1000] [1, 1000] [1, 1000]
[1, 1000] [1, 1000] [1, 1000]
"""
"""
def
__init__
(
self
,
num_classes
=
1000
,
with_pool
=
True
):
def
__init__
(
self
,
num_classes
=
1000
,
with_pool
=
True
):
...
@@ -236,7 +236,7 @@ def googlenet(pretrained=False, **kwargs):
...
@@ -236,7 +236,7 @@ def googlenet(pretrained=False, **kwargs):
Args:
Args:
pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained
pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained
on ImageNet. Default: False.
on ImageNet. Default: False.
**kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`GoogLeNet <api_paddle_vision_GoogLeNet>`.
**kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`GoogLeNet <api_paddle_vision_GoogLeNet>`.
Returns:
Returns:
...
@@ -245,20 +245,20 @@ def googlenet(pretrained=False, **kwargs):
...
@@ -245,20 +245,20 @@ def googlenet(pretrained=False, **kwargs):
Examples:
Examples:
.. code-block:: python
.. code-block:: python
import paddle
>>>
import paddle
from paddle.vision.models import googlenet
>>>
from paddle.vision.models import googlenet
# b
uild model
>>> # B
uild model
model = googlenet()
>>>
model = googlenet()
# b
uild model and load imagenet pretrained weight
>>> # B
uild model and load imagenet pretrained weight
# model = googlenet(pretrained=True)
>>>
# model = googlenet(pretrained=True)
x = paddle.rand([1, 3, 224, 224])
>>>
x = paddle.rand([1, 3, 224, 224])
out, out1, out2 = model(x)
>>>
out, out1, out2 = model(x)
print(out.shape, out1.shape, out2.shape)
>>>
print(out.shape, out1.shape, out2.shape)
#
[1, 1000] [1, 1000] [1, 1000]
[1, 1000] [1, 1000] [1, 1000]
"""
"""
model
=
GoogLeNet
(
**
kwargs
)
model
=
GoogLeNet
(
**
kwargs
)
arch
=
"googlenet"
arch
=
"googlenet"
...
...
python/paddle/vision/models/inceptionv3.py
浏览文件 @
5356f2e0
...
@@ -491,7 +491,7 @@ class InceptionV3(nn.Layer):
...
@@ -491,7 +491,7 @@ class InceptionV3(nn.Layer):
Args:
Args:
num_classes (int, optional): Output dim of last fc layer. If num_classes <= 0, last fc layer
num_classes (int, optional): Output dim of last fc layer. If num_classes <= 0, last fc layer
will not be defined. Default: 1000.
will not be defined. Default: 1000.
with_pool (bool, optional): Use pool before the last fc layer or not. Default: True.
with_pool (bool, optional): Use pool before the last fc layer or not. Default: True.
Returns:
Returns:
...
@@ -500,16 +500,16 @@ class InceptionV3(nn.Layer):
...
@@ -500,16 +500,16 @@ class InceptionV3(nn.Layer):
Examples:
Examples:
.. code-block:: python
.. code-block:: python
import paddle
>>>
import paddle
from paddle.vision.models import InceptionV3
>>>
from paddle.vision.models import InceptionV3
inception_v3 = InceptionV3()
>>>
inception_v3 = InceptionV3()
x = paddle.rand([1, 3, 299, 299])
>>>
x = paddle.rand([1, 3, 299, 299])
out = inception_v3(x)
>>>
out = inception_v3(x)
print(out.shape)
>>>
print(out.shape)
#
[1, 1000]
[1, 1000]
"""
"""
def
__init__
(
self
,
num_classes
=
1000
,
with_pool
=
True
):
def
__init__
(
self
,
num_classes
=
1000
,
with_pool
=
True
):
...
@@ -591,7 +591,7 @@ def inception_v3(pretrained=False, **kwargs):
...
@@ -591,7 +591,7 @@ def inception_v3(pretrained=False, **kwargs):
Args:
Args:
pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained
pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained
on ImageNet. Default: False.
on ImageNet. Default: False.
**kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`InceptionV3 <api_paddle_vision_InceptionV3>`.
**kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`InceptionV3 <api_paddle_vision_InceptionV3>`.
Returns:
Returns:
...
@@ -600,20 +600,20 @@ def inception_v3(pretrained=False, **kwargs):
...
@@ -600,20 +600,20 @@ def inception_v3(pretrained=False, **kwargs):
Examples:
Examples:
.. code-block:: python
.. code-block:: python
import paddle
>>>
import paddle
from paddle.vision.models import inception_v3
>>>
from paddle.vision.models import inception_v3
# b
uild model
>>> # B
uild model
model = inception_v3()
>>>
model = inception_v3()
# b
uild model and load imagenet pretrained weight
>>> # B
uild model and load imagenet pretrained weight
# model = inception_v3(pretrained=True)
>>>
# model = inception_v3(pretrained=True)
x = paddle.rand([1, 3, 299, 299])
>>>
x = paddle.rand([1, 3, 299, 299])
out = model(x)
>>>
out = model(x)
print(out.shape)
>>>
print(out.shape)
#
[1, 1000]
[1, 1000]
"""
"""
model
=
InceptionV3
(
**
kwargs
)
model
=
InceptionV3
(
**
kwargs
)
arch
=
"inception_v3"
arch
=
"inception_v3"
...
...
python/paddle/vision/models/lenet.py
浏览文件 @
5356f2e0
...
@@ -24,7 +24,7 @@ class LeNet(nn.Layer):
...
@@ -24,7 +24,7 @@ class LeNet(nn.Layer):
Args:
Args:
num_classes (int, optional): Output dim of last fc layer. If num_classes <= 0, last fc layer
num_classes (int, optional): Output dim of last fc layer. If num_classes <= 0, last fc layer
will not be defined. Default: 10.
will not be defined. Default: 10.
Returns:
Returns:
:ref:`api_paddle_nn_Layer`. An instance of LeNet model.
:ref:`api_paddle_nn_Layer`. An instance of LeNet model.
...
@@ -32,16 +32,16 @@ class LeNet(nn.Layer):
...
@@ -32,16 +32,16 @@ class LeNet(nn.Layer):
Examples:
Examples:
.. code-block:: python
.. code-block:: python
import paddle
>>>
import paddle
from paddle.vision.models import LeNet
>>>
from paddle.vision.models import LeNet
model = LeNet()
>>>
model = LeNet()
x = paddle.rand([1, 1, 28, 28])
>>>
x = paddle.rand([1, 1, 28, 28])
out = model(x)
>>>
out = model(x)
print(out.shape)
>>>
print(out.shape)
#
[1, 10]
[1, 10]
"""
"""
def
__init__
(
self
,
num_classes
=
10
):
def
__init__
(
self
,
num_classes
=
10
):
...
...
python/paddle/vision/models/mobilenetv1.py
浏览文件 @
5356f2e0
...
@@ -70,7 +70,7 @@ class MobileNetV1(nn.Layer):
...
@@ -70,7 +70,7 @@ class MobileNetV1(nn.Layer):
Args:
Args:
scale (float, optional): Scale of channels in each layer. Default: 1.0.
scale (float, optional): Scale of channels in each layer. Default: 1.0.
num_classes (int, optional): Output dim of last fc layer. If num_classes <= 0, last fc layer
num_classes (int, optional): Output dim of last fc layer. If num_classes <= 0, last fc layer
will not be defined. Default: 1000.
will not be defined. Default: 1000.
with_pool (bool, optional): Use pool before the last fc layer or not. Default: True.
with_pool (bool, optional): Use pool before the last fc layer or not. Default: True.
Returns:
Returns:
...
@@ -79,16 +79,16 @@ class MobileNetV1(nn.Layer):
...
@@ -79,16 +79,16 @@ class MobileNetV1(nn.Layer):
Examples:
Examples:
.. code-block:: python
.. code-block:: python
import paddle
>>>
import paddle
from paddle.vision.models import MobileNetV1
>>>
from paddle.vision.models import MobileNetV1
model = MobileNetV1()
>>>
model = MobileNetV1()
x = paddle.rand([1, 3, 224, 224])
>>>
x = paddle.rand([1, 3, 224, 224])
out = model(x)
>>>
out = model(x)
print(out.shape)
>>>
print(out.shape)
#
[1, 1000]
[1, 1000]
"""
"""
def
__init__
(
self
,
scale
=
1.0
,
num_classes
=
1000
,
with_pool
=
True
):
def
__init__
(
self
,
scale
=
1.0
,
num_classes
=
1000
,
with_pool
=
True
):
...
@@ -268,7 +268,7 @@ def mobilenet_v1(pretrained=False, scale=1.0, **kwargs):
...
@@ -268,7 +268,7 @@ def mobilenet_v1(pretrained=False, scale=1.0, **kwargs):
Args:
Args:
pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained
pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained
on ImageNet. Default: False.
on ImageNet. Default: False.
scale (float, optional): Scale of channels in each layer. Default: 1.0.
scale (float, optional): Scale of channels in each layer. Default: 1.0.
**kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`MobileNetV1 <api_paddle_vision_MobileNetV1>`.
**kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`MobileNetV1 <api_paddle_vision_MobileNetV1>`.
...
@@ -278,23 +278,23 @@ def mobilenet_v1(pretrained=False, scale=1.0, **kwargs):
...
@@ -278,23 +278,23 @@ def mobilenet_v1(pretrained=False, scale=1.0, **kwargs):
Examples:
Examples:
.. code-block:: python
.. code-block:: python
import paddle
>>>
import paddle
from paddle.vision.models import mobilenet_v1
>>>
from paddle.vision.models import mobilenet_v1
# b
uild model
>>> # B
uild model
model = mobilenet_v1()
>>>
model = mobilenet_v1()
# b
uild model and load imagenet pretrained weight
>>> # B
uild model and load imagenet pretrained weight
# model = mobilenet_v1(pretrained=True)
>>>
# model = mobilenet_v1(pretrained=True)
# build mobilenet v1 with scale=0.5
>>>
# build mobilenet v1 with scale=0.5
model_scale = mobilenet_v1(scale=0.5)
>>>
model_scale = mobilenet_v1(scale=0.5)
x = paddle.rand([1, 3, 224, 224])
>>>
x = paddle.rand([1, 3, 224, 224])
out = model(x)
>>>
out = model(x)
print(out.shape)
>>>
print(out.shape)
#
[1, 1000]
[1, 1000]
"""
"""
model
=
_mobilenet
(
model
=
_mobilenet
(
'mobilenetv1_'
+
str
(
scale
),
pretrained
,
scale
=
scale
,
**
kwargs
'mobilenetv1_'
+
str
(
scale
),
pretrained
,
scale
=
scale
,
**
kwargs
...
...
python/paddle/vision/models/mobilenetv2.py
浏览文件 @
5356f2e0
...
@@ -81,7 +81,7 @@ class MobileNetV2(nn.Layer):
...
@@ -81,7 +81,7 @@ class MobileNetV2(nn.Layer):
Args:
Args:
scale (float, optional): Scale of channels in each layer. Default: 1.0.
scale (float, optional): Scale of channels in each layer. Default: 1.0.
num_classes (int, optional): Output dim of last fc layer. If num_classes <= 0, last fc layer
num_classes (int, optional): Output dim of last fc layer. If num_classes <= 0, last fc layer
will not be defined. Default: 1000.
will not be defined. Default: 1000.
with_pool (bool, optional): Use pool before the last fc layer or not. Default: True.
with_pool (bool, optional): Use pool before the last fc layer or not. Default: True.
Returns:
Returns:
...
@@ -90,16 +90,16 @@ class MobileNetV2(nn.Layer):
...
@@ -90,16 +90,16 @@ class MobileNetV2(nn.Layer):
Examples:
Examples:
.. code-block:: python
.. code-block:: python
import paddle
>>>
import paddle
from paddle.vision.models import MobileNetV2
>>>
from paddle.vision.models import MobileNetV2
model = MobileNetV2()
>>>
model = MobileNetV2()
x = paddle.rand([1, 3, 224, 224])
>>>
x = paddle.rand([1, 3, 224, 224])
out = model(x)
>>>
out = model(x)
print(out.shape)
>>>
print(out.shape)
#
[1, 1000]
[1, 1000]
"""
"""
def
__init__
(
self
,
scale
=
1.0
,
num_classes
=
1000
,
with_pool
=
True
):
def
__init__
(
self
,
scale
=
1.0
,
num_classes
=
1000
,
with_pool
=
True
):
...
@@ -206,8 +206,7 @@ def mobilenet_v2(pretrained=False, scale=1.0, **kwargs):
...
@@ -206,8 +206,7 @@ def mobilenet_v2(pretrained=False, scale=1.0, **kwargs):
`"MobileNetV2: Inverted Residuals and Linear Bottlenecks" <https://arxiv.org/abs/1801.04381>`_.
`"MobileNetV2: Inverted Residuals and Linear Bottlenecks" <https://arxiv.org/abs/1801.04381>`_.
Args:
Args:
pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained
pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained on ImageNet. Default: False.
on ImageNet. Default: False.
scale (float, optional): Scale of channels in each layer. Default: 1.0.
scale (float, optional): Scale of channels in each layer. Default: 1.0.
**kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`MobileNetV2 <api_paddle_vision_MobileNetV2>`.
**kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`MobileNetV2 <api_paddle_vision_MobileNetV2>`.
...
@@ -217,23 +216,23 @@ def mobilenet_v2(pretrained=False, scale=1.0, **kwargs):
...
@@ -217,23 +216,23 @@ def mobilenet_v2(pretrained=False, scale=1.0, **kwargs):
Examples:
Examples:
.. code-block:: python
.. code-block:: python
import paddle
>>>
import paddle
from paddle.vision.models import mobilenet_v2
>>>
from paddle.vision.models import mobilenet_v2
# b
uild model
>>> # B
uild model
model = mobilenet_v2()
>>>
model = mobilenet_v2()
# b
uild model and load imagenet pretrained weight
>>> # B
uild model and load imagenet pretrained weight
# model = mobilenet_v2(pretrained=True)
>>>
# model = mobilenet_v2(pretrained=True)
# b
uild mobilenet v2 with scale=0.5
>>> # B
uild mobilenet v2 with scale=0.5
model = mobilenet_v2(scale=0.5)
>>>
model = mobilenet_v2(scale=0.5)
x = paddle.rand([1, 3, 224, 224])
>>>
x = paddle.rand([1, 3, 224, 224])
out = model(x)
>>>
out = model(x)
print(out.shape)
>>>
print(out.shape)
#
[1, 1000]
[1, 1000]
"""
"""
model
=
_mobilenet
(
model
=
_mobilenet
(
'mobilenetv2_'
+
str
(
scale
),
pretrained
,
scale
=
scale
,
**
kwargs
'mobilenetv2_'
+
str
(
scale
),
pretrained
,
scale
=
scale
,
**
kwargs
...
...
python/paddle/vision/models/mobilenetv3.py
浏览文件 @
5356f2e0
...
@@ -41,11 +41,12 @@ class SqueezeExcitation(nn.Layer):
...
@@ -41,11 +41,12 @@ class SqueezeExcitation(nn.Layer):
Parameters ``activation``, and ``scale_activation`` correspond to ``delta`` and ``sigma`` in eq. 3.
Parameters ``activation``, and ``scale_activation`` correspond to ``delta`` and ``sigma`` in eq. 3.
This code is based on the torchvision code with modifications.
This code is based on the torchvision code with modifications.
You can also see at https://github.com/pytorch/vision/blob/main/torchvision/ops/misc.py#L127
You can also see at https://github.com/pytorch/vision/blob/main/torchvision/ops/misc.py#L127
Args:
Args:
input_channels (int): Number of channels in the input image
input_channels (int): Number of channels in the input image
.
squeeze_channels (int): Number of squeeze channels
squeeze_channels (int): Number of squeeze channels
.
activation (Callable[..., paddle.nn.Layer], optional): ``delta`` activation. Default: ``paddle.nn.ReLU``
activation (Callable[..., paddle.nn.Layer], optional): ``delta`` activation. Default: ``paddle.nn.ReLU``
.
scale_activation (Callable[..., paddle.nn.Layer]): ``sigma`` activation. Default: ``paddle.nn.Sigmoid``
scale_activation (Callable[..., paddle.nn.Layer]): ``sigma`` activation. Default: ``paddle.nn.Sigmoid``
.
"""
"""
def
__init__
(
def
__init__
(
...
@@ -190,7 +191,7 @@ class MobileNetV3(nn.Layer):
...
@@ -190,7 +191,7 @@ class MobileNetV3(nn.Layer):
last_channel (int): The number of channels on the penultimate layer.
last_channel (int): The number of channels on the penultimate layer.
scale (float, optional): Scale of channels in each layer. Default: 1.0.
scale (float, optional): Scale of channels in each layer. Default: 1.0.
num_classes (int, optional): Output dim of last fc layer. If num_classes <=0, last fc layer
num_classes (int, optional): Output dim of last fc layer. If num_classes <=0, last fc layer
will not be defined. Default: 1000.
will not be defined. Default: 1000.
with_pool (bool, optional): Use pool before the last fc layer or not. Default: True.
with_pool (bool, optional): Use pool before the last fc layer or not. Default: True.
"""
"""
...
@@ -280,7 +281,7 @@ class MobileNetV3Small(MobileNetV3):
...
@@ -280,7 +281,7 @@ class MobileNetV3Small(MobileNetV3):
Args:
Args:
scale (float, optional): Scale of channels in each layer. Default: 1.0.
scale (float, optional): Scale of channels in each layer. Default: 1.0.
num_classes (int, optional): Output dim of last fc layer. If num_classes <= 0, last fc layer
num_classes (int, optional): Output dim of last fc layer. If num_classes <= 0, last fc layer
will not be defined. Default: 1000.
will not be defined. Default: 1000.
with_pool (bool, optional): Use pool before the last fc layer or not. Default: True.
with_pool (bool, optional): Use pool before the last fc layer or not. Default: True.
Returns:
Returns:
...
@@ -289,17 +290,17 @@ class MobileNetV3Small(MobileNetV3):
...
@@ -289,17 +290,17 @@ class MobileNetV3Small(MobileNetV3):
Examples:
Examples:
.. code-block:: python
.. code-block:: python
import paddle
>>>
import paddle
from paddle.vision.models import MobileNetV3Small
>>>
from paddle.vision.models import MobileNetV3Small
# b
uild model
>>> # B
uild model
model = MobileNetV3Small(scale=1.0)
>>>
model = MobileNetV3Small(scale=1.0)
x = paddle.rand([1, 3, 224, 224])
>>>
x = paddle.rand([1, 3, 224, 224])
out = model(x)
>>>
out = model(x)
print(out.shape)
>>>
print(out.shape)
#
[1, 1000]
[1, 1000]
"""
"""
def
__init__
(
self
,
scale
=
1.0
,
num_classes
=
1000
,
with_pool
=
True
):
def
__init__
(
self
,
scale
=
1.0
,
num_classes
=
1000
,
with_pool
=
True
):
...
@@ -333,7 +334,7 @@ class MobileNetV3Large(MobileNetV3):
...
@@ -333,7 +334,7 @@ class MobileNetV3Large(MobileNetV3):
Args:
Args:
scale (float, optional): Scale of channels in each layer. Default: 1.0.
scale (float, optional): Scale of channels in each layer. Default: 1.0.
num_classes (int, optional): Output dim of last fc layer. If num_classes <= 0, last fc layer
num_classes (int, optional): Output dim of last fc layer. If num_classes <= 0, last fc layer
will not be defined. Default: 1000.
will not be defined. Default: 1000.
with_pool (bool, optional): Use pool before the last fc layer or not. Default: True.
with_pool (bool, optional): Use pool before the last fc layer or not. Default: True.
Returns:
Returns:
...
@@ -342,17 +343,17 @@ class MobileNetV3Large(MobileNetV3):
...
@@ -342,17 +343,17 @@ class MobileNetV3Large(MobileNetV3):
Examples:
Examples:
.. code-block:: python
.. code-block:: python
import paddle
>>>
import paddle
from paddle.vision.models import MobileNetV3Large
>>>
from paddle.vision.models import MobileNetV3Large
# b
uild model
>>> # B
uild model
model = MobileNetV3Large(scale=1.0)
>>>
model = MobileNetV3Large(scale=1.0)
x = paddle.rand([1, 3, 224, 224])
>>>
x = paddle.rand([1, 3, 224, 224])
out = model(x)
>>>
out = model(x)
print(out.shape)
>>>
print(out.shape)
#
[1, 1000]
[1, 1000]
"""
"""
def
__init__
(
self
,
scale
=
1.0
,
num_classes
=
1000
,
with_pool
=
True
):
def
__init__
(
self
,
scale
=
1.0
,
num_classes
=
1000
,
with_pool
=
True
):
...
@@ -427,8 +428,7 @@ def mobilenet_v3_small(pretrained=False, scale=1.0, **kwargs):
...
@@ -427,8 +428,7 @@ def mobilenet_v3_small(pretrained=False, scale=1.0, **kwargs):
`"Searching for MobileNetV3" <https://arxiv.org/abs/1905.02244>`_.
`"Searching for MobileNetV3" <https://arxiv.org/abs/1905.02244>`_.
Args:
Args:
pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained
pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained on ImageNet. Default: False.
on ImageNet. Default: False.
scale (float, optional): Scale of channels in each layer. Default: 1.0.
scale (float, optional): Scale of channels in each layer. Default: 1.0.
**kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`MobileNetV3Small <api_paddle_vision_MobileNetV3Small>`.
**kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`MobileNetV3Small <api_paddle_vision_MobileNetV3Small>`.
...
@@ -438,23 +438,23 @@ def mobilenet_v3_small(pretrained=False, scale=1.0, **kwargs):
...
@@ -438,23 +438,23 @@ def mobilenet_v3_small(pretrained=False, scale=1.0, **kwargs):
Examples:
Examples:
.. code-block:: python
.. code-block:: python
import paddle
>>>
import paddle
from paddle.vision.models import mobilenet_v3_small
>>>
from paddle.vision.models import mobilenet_v3_small
# b
uild model
>>> # B
uild model
model = mobilenet_v3_small()
>>>
model = mobilenet_v3_small()
# b
uild model and load imagenet pretrained weight
>>> # B
uild model and load imagenet pretrained weight
# model = mobilenet_v3_small(pretrained=True)
>>>
# model = mobilenet_v3_small(pretrained=True)
# b
uild mobilenet v3 small model with scale=0.5
>>> # B
uild mobilenet v3 small model with scale=0.5
model = mobilenet_v3_small(scale=0.5)
>>>
model = mobilenet_v3_small(scale=0.5)
x = paddle.rand([1, 3, 224, 224])
>>>
x = paddle.rand([1, 3, 224, 224])
out = model(x)
>>>
out = model(x)
print(out.shape)
>>>
print(out.shape)
#
[1, 1000]
[1, 1000]
"""
"""
model
=
_mobilenet_v3
(
model
=
_mobilenet_v3
(
"mobilenet_v3_small"
,
scale
=
scale
,
pretrained
=
pretrained
,
**
kwargs
"mobilenet_v3_small"
,
scale
=
scale
,
pretrained
=
pretrained
,
**
kwargs
...
@@ -467,8 +467,7 @@ def mobilenet_v3_large(pretrained=False, scale=1.0, **kwargs):
...
@@ -467,8 +467,7 @@ def mobilenet_v3_large(pretrained=False, scale=1.0, **kwargs):
`"Searching for MobileNetV3" <https://arxiv.org/abs/1905.02244>`_.
`"Searching for MobileNetV3" <https://arxiv.org/abs/1905.02244>`_.
Args:
Args:
pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained
pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained on ImageNet. Default: False.
on ImageNet. Default: False.
scale (float, optional): Scale of channels in each layer. Default: 1.0.
scale (float, optional): Scale of channels in each layer. Default: 1.0.
**kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`MobileNetV3Large <api_paddle_vision_MobileNetV3Large>`.
**kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`MobileNetV3Large <api_paddle_vision_MobileNetV3Large>`.
...
@@ -478,23 +477,23 @@ def mobilenet_v3_large(pretrained=False, scale=1.0, **kwargs):
...
@@ -478,23 +477,23 @@ def mobilenet_v3_large(pretrained=False, scale=1.0, **kwargs):
Examples:
Examples:
.. code-block:: python
.. code-block:: python
import paddle
>>>
import paddle
from paddle.vision.models import mobilenet_v3_large
>>>
from paddle.vision.models import mobilenet_v3_large
# b
uild model
>>> # B
uild model
model = mobilenet_v3_large()
>>>
model = mobilenet_v3_large()
# b
uild model and load imagenet pretrained weight
>>> # B
uild model and load imagenet pretrained weight
# model = mobilenet_v3_large(pretrained=True)
>>>
# model = mobilenet_v3_large(pretrained=True)
# b
uild mobilenet v3 large model with scale=0.5
>>> # B
uild mobilenet v3 large model with scale=0.5
model = mobilenet_v3_large(scale=0.5)
>>>
model = mobilenet_v3_large(scale=0.5)
x = paddle.rand([1, 3, 224, 224])
>>>
x = paddle.rand([1, 3, 224, 224])
out = model(x)
>>>
out = model(x)
print(out.shape)
>>>
print(out.shape)
#
[1, 1000]
[1, 1000]
"""
"""
model
=
_mobilenet_v3
(
model
=
_mobilenet_v3
(
"mobilenet_v3_large"
,
scale
=
scale
,
pretrained
=
pretrained
,
**
kwargs
"mobilenet_v3_large"
,
scale
=
scale
,
pretrained
=
pretrained
,
**
kwargs
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录