Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
5356f2e0
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
Star
20931
Fork
5422
代码
文件
提交
分支
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看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
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):
Args:
data_file(str): path to data tar file, can be set None if
:attr:`download` is True. Default None
mode(str): 'train', 'test' or 'val'. Default 'train'
:attr:`download` is True. Default None
.
mode(str): 'train', 'test' or 'val'. Default 'train'
.
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.
lang(str): source language, 'en' or 'de'. Default 'en'.
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:
Dataset: Instance of WMT16 dataset. The instance of dataset has 3 fields:
...
...
@@ -77,30 +77,37 @@ class WMT16(Dataset):
.. code-block:: python
import paddle
from paddle.text.datasets import WMT16
class SimpleNet(paddle.nn.Layer):
def __init__(self):
super().__init__()
def forward(self, src_ids, trg_ids, 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)
for i in range(10):
src_ids, trg_ids, trg_ids_next = wmt16[i]
src_ids = paddle.to_tensor(src_ids)
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)
print(src_ids.numpy(), trg_ids.numpy(), trg_ids_next.numpy())
>>> import paddle
>>> from paddle.text.datasets import WMT16
>>> class SimpleNet(paddle.nn.Layer):
... def __init__(self):
... super().__init__()
...
... def forward(self, src_ids, trg_ids, trg_ids_next):
... return paddle.sum(src_ids), paddle.sum(trg_ids), paddle.sum(trg_ids_next)
>>> 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]
... src_ids = paddle.to_tensor(src_ids)
... 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)
... print(src_ids.item(), trg_ids.item(), trg_ids_next.item())
89 32 33
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__
(
...
...
@@ -257,9 +264,9 @@ class WMT16(Dataset):
.. code-block:: python
from paddle.text.datasets import WMT16
wmt16 = WMT16(mode='train', src_dict_size=50, trg_dict_size=50)
en_dict = wmt16.get_dict('en')
>>>
from paddle.text.datasets import WMT16
>>>
wmt16 = WMT16(mode='train', src_dict_size=50, trg_dict_size=50)
>>>
en_dict = wmt16.get_dict('en')
"""
dict_size
=
(
...
...
python/paddle/text/viterbi_decode.py
浏览文件 @
5356f2e0
...
...
@@ -42,20 +42,27 @@ def viterbi_decode(
Returns:
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.
paths(Tensor): The output tensor containing the highest scoring tag indices.
The shape is [batch_size, sequence_length]
and
the data type is int64.
paths(Tensor): The output tensor containing the highest scoring tag indices. The shape is [batch_size, sequence_length]
and the data type is int64.
Example:
Example
s
:
.. code-block:: python
import paddle
paddle.seed(102)
batch_size, seq_len, num_tags = 2, 4, 3
emission = paddle.rand((batch_size, seq_len, num_tags), dtype='float32')
length = paddle.randint(1, seq_len + 1, [batch_size])
tags = paddle.randint(0, num_tags, [batch_size, seq_len])
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]]
>>> import paddle
>>> paddle.seed(2023)
>>> batch_size, seq_len, num_tags = 2, 4, 3
>>> emission = paddle.rand((batch_size, seq_len, num_tags), dtype='float32')
>>> length = paddle.randint(1, seq_len + 1, [batch_size])
>>> tags = paddle.randint(0, num_tags, [batch_size, seq_len])
>>> transition = paddle.rand((num_tags, num_tags), dtype='float32')
>>> 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
():
return
_C_ops
.
viterbi_decode
(
...
...
@@ -95,7 +102,7 @@ class ViterbiDecoder(Layer):
Decode the highest scoring sequence of tags computed by transitions and potentials and get the viterbi path.
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
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
...
...
@@ -104,27 +111,34 @@ class ViterbiDecoder(Layer):
Shape:
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.
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.
Returns:
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.
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.
Example:
Example
s
:
.. code-block:: python
import paddle
paddle.seed(102)
batch_size, seq_len, num_tags = 2, 4, 3
emission = paddle.rand((batch_size, seq_len, num_tags), dtype='float32')
length = paddle.randint(1, seq_len + 1, [batch_size])
tags = paddle.randint(0, num_tags, [batch_size, seq_len])
transition = paddle.rand((num_tags, num_tags), dtype='float32')
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]]
>>> import paddle
>>> paddle.seed(2023)
>>> batch_size, seq_len, num_tags = 2, 4, 3
>>> emission = paddle.rand((batch_size, seq_len, num_tags), dtype='float32')
>>> length = paddle.randint(1, seq_len + 1, [batch_size])
>>> tags = paddle.randint(0, num_tags, [batch_size, seq_len])
>>> transition = paddle.rand((num_tags, num_tags), dtype='float32')
>>> decoder = paddle.text.ViterbiDecoder(transition, include_bos_eos_tag=False)
>>> 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
):
...
...
python/paddle/vision/models/_utils.py
浏览文件 @
5356f2e0
...
...
@@ -21,13 +21,13 @@ from paddle import nn
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
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,
the default is divisor. Default: None.
the default is divisor. Default: None.
"""
if
min_value
is
None
:
min_value
=
divisor
...
...
@@ -50,22 +50,25 @@ class IntermediateLayerGetter(nn.LayerDict):
So if `model` is passed, `model.feature1` can be returned, but not `model.feature1.layer2`.
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
dict is the name of the returned activation (which the user can specify).
Examples:
.. code-block:: python
import paddle
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,
{'layer1': 'feat1', 'layer3': 'feat2'})
out = new_m(paddle.rand([1, 3, 224, 224]))
print([(k, v.shape) for k, v in out.items()])
# [('feat1', [1, 64, 56, 56]), ('feat2', [1, 256, 14, 14])]
>>> import paddle
>>> 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,
... {'layer1': 'feat1', 'layer3': 'feat2'})
>>> out = new_m(paddle.rand([1, 3, 224, 224]))
>>> print([(k, v.shape) for k, v in out.items()])
[('feat1', [1, 64, 56, 56]), ('feat2', [1, 256, 14, 14])]
"""
__annotations__
=
{
...
...
python/paddle/vision/models/alexnet.py
浏览文件 @
5356f2e0
...
...
@@ -75,7 +75,7 @@ class AlexNet(nn.Layer):
Args:
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:
:ref:`api_paddle_nn_Layer`. An instance of AlexNet model.
...
...
@@ -83,16 +83,14 @@ class AlexNet(nn.Layer):
Examples:
.. code-block:: python
import paddle
from paddle.vision.models import AlexNet
>>>
import paddle
>>>
from paddle.vision.models import AlexNet
alexnet = AlexNet()
x = paddle.rand([1, 3, 224, 224])
out = alexnet(x)
print(out.shape)
# [1, 1000]
>>> alexnet = AlexNet()
>>> x = paddle.rand([1, 3, 224, 224])
>>> out = alexnet(x)
>>> print(out.shape)
[1, 1000]
"""
def
__init__
(
self
,
num_classes
=
1000
):
...
...
@@ -197,7 +195,7 @@ def alexnet(pretrained=False, **kwargs):
Args:
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>`.
Returns:
...
...
@@ -206,19 +204,19 @@ def alexnet(pretrained=False, **kwargs):
Examples:
.. code-block:: python
import paddle
from paddle.vision.models import alexnet
>>>
import paddle
>>>
from paddle.vision.models import alexnet
# b
uild model
model = alexnet()
>>> # B
uild model
>>>
model = alexnet()
# b
uild model and load imagenet pretrained weight
# model = alexnet(pretrained=True)
>>> # B
uild model and load imagenet pretrained weight
>>>
# model = alexnet(pretrained=True)
x = paddle.rand([1, 3, 224, 224])
out = model(x)
>>>
x = paddle.rand([1, 3, 224, 224])
>>>
out = model(x)
print(out.shape)
#
[1, 1000]
>>>
print(out.shape)
[1, 1000]
"""
return
_alexnet
(
'alexnet'
,
pretrained
,
**
kwargs
)
python/paddle/vision/models/densenet.py
浏览文件 @
5356f2e0
...
...
@@ -209,7 +209,7 @@ class DenseNet(nn.Layer):
bn_size (int, optional): Expansion of growth rate in the middle layer. Default: 4.
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
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.
Returns:
...
...
@@ -218,17 +218,17 @@ class DenseNet(nn.Layer):
Examples:
.. code-block:: python
import paddle
from paddle.vision.models import DenseNet
>>>
import paddle
>>>
from paddle.vision.models import DenseNet
# b
uild model
densenet = DenseNet()
>>> # B
uild model
>>>
densenet = DenseNet()
x = paddle.rand([1, 3, 224, 224])
out = densenet(x)
>>>
x = paddle.rand([1, 3, 224, 224])
>>>
out = densenet(x)
print(out.shape)
#
[1, 1000]
>>>
print(out.shape)
[1, 1000]
"""
def
__init__
(
...
...
@@ -360,7 +360,7 @@ def densenet121(pretrained=False, **kwargs):
Args:
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>`.
Returns:
...
...
@@ -369,20 +369,20 @@ def densenet121(pretrained=False, **kwargs):
Examples:
.. code-block:: python
import paddle
from paddle.vision.models import densenet121
>>>
import paddle
>>>
from paddle.vision.models import densenet121
# b
uild model
model = densenet121()
>>> # B
uild model
>>>
model = densenet121()
# b
uild model and load imagenet pretrained weight
# model = densenet121(pretrained=True)
>>> # B
uild model and load imagenet pretrained weight
>>>
# model = densenet121(pretrained=True)
x = paddle.rand([1, 3, 224, 224])
out = model(x)
>>>
x = paddle.rand([1, 3, 224, 224])
>>>
out = model(x)
print(out.shape)
#
[1, 1000]
>>>
print(out.shape)
[1, 1000]
"""
return
_densenet
(
'densenet121'
,
121
,
pretrained
,
**
kwargs
)
...
...
@@ -393,7 +393,7 @@ def densenet161(pretrained=False, **kwargs):
Args:
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>`.
Returns:
...
...
@@ -402,13 +402,20 @@ def densenet161(pretrained=False, **kwargs):
Examples:
.. code-block:: python
from paddle.vision.models import densenet161
>>> import paddle
>>> from paddle.vision.models import densenet161
# b
uild model
model = densenet161()
>>> # B
uild model
>>>
model = densenet161()
# build model and load imagenet pretrained weight
# model = densenet161(pretrained=True)
>>> # Build model and load imagenet pretrained weight
>>> # 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
)
...
...
@@ -419,7 +426,7 @@ def densenet169(pretrained=False, **kwargs):
Args:
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>`.
Returns:
...
...
@@ -428,20 +435,20 @@ def densenet169(pretrained=False, **kwargs):
Examples:
.. code-block:: python
import paddle
from paddle.vision.models import densenet169
>>>
import paddle
>>>
from paddle.vision.models import densenet169
# b
uild model
model = densenet169()
>>> # B
uild model
>>>
model = densenet169()
# b
uild model and load imagenet pretrained weight
# model = densenet169(pretrained=True)
>>> # B
uild model and load imagenet pretrained weight
>>>
# model = densenet169(pretrained=True)
x = paddle.rand([1, 3, 224, 224])
out = model(x)
>>>
x = paddle.rand([1, 3, 224, 224])
>>>
out = model(x)
print(out.shape)
#
[1, 1000]
>>>
print(out.shape)
[1, 1000]
"""
return
_densenet
(
'densenet169'
,
169
,
pretrained
,
**
kwargs
)
...
...
@@ -452,7 +459,7 @@ def densenet201(pretrained=False, **kwargs):
Args:
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>`.
Returns:
...
...
@@ -461,19 +468,19 @@ def densenet201(pretrained=False, **kwargs):
Examples:
.. code-block:: python
import paddle
from paddle.vision.models import densenet201
>>>
import paddle
>>>
from paddle.vision.models import densenet201
# b
uild model
model = densenet201()
>>> # B
uild model
>>>
model = densenet201()
# b
uild model and load imagenet pretrained weight
# model = densenet201(pretrained=True)
x = paddle.rand([1, 3, 224, 224])
out = model(x)
>>> # B
uild model and load imagenet pretrained weight
>>>
# model = densenet201(pretrained=True)
>>>
x = paddle.rand([1, 3, 224, 224])
>>>
out = model(x)
print(out.shape)
#
[1, 1000]
>>>
print(out.shape)
[1, 1000]
"""
return
_densenet
(
'densenet201'
,
201
,
pretrained
,
**
kwargs
)
...
...
@@ -484,7 +491,7 @@ def densenet264(pretrained=False, **kwargs):
Args:
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>`.
Returns:
...
...
@@ -493,19 +500,19 @@ def densenet264(pretrained=False, **kwargs):
Examples:
.. code-block:: python
import paddle
from paddle.vision.models import densenet264
>>>
import paddle
>>>
from paddle.vision.models import densenet264
# b
uild model
model = densenet264()
>>> # B
uild model
>>>
model = densenet264()
# b
uild model and load imagenet pretrained weight
# model = densenet264(pretrained=True)
>>> # B
uild model and load imagenet pretrained weight
>>>
# model = densenet264(pretrained=True)
x = paddle.rand([1, 3, 224, 224])
out = model(x)
>>>
x = paddle.rand([1, 3, 224, 224])
>>>
out = model(x)
print(out.shape)
#
[1, 1000]
>>>
print(out.shape)
[1, 1000]
"""
return
_densenet
(
'densenet264'
,
264
,
pretrained
,
**
kwargs
)
python/paddle/vision/models/googlenet.py
浏览文件 @
5356f2e0
...
...
@@ -110,7 +110,7 @@ class GoogLeNet(nn.Layer):
Args:
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.
Returns:
...
...
@@ -119,17 +119,17 @@ class GoogLeNet(nn.Layer):
Examples:
.. code-block:: python
import paddle
from paddle.vision.models import GoogLeNet
>>>
import paddle
>>>
from paddle.vision.models import GoogLeNet
# b
uild model
model = GoogLeNet()
>>> # B
uild model
>>>
model = GoogLeNet()
x = paddle.rand([1, 3, 224, 224])
out, out1, out2 = model(x)
>>>
x = paddle.rand([1, 3, 224, 224])
>>>
out, out1, out2 = model(x)
print(out.shape, out1.shape, out2.shape)
#
[1, 1000] [1, 1000] [1, 1000]
>>>
print(out.shape, out1.shape, out2.shape)
[1, 1000] [1, 1000] [1, 1000]
"""
def
__init__
(
self
,
num_classes
=
1000
,
with_pool
=
True
):
...
...
@@ -236,7 +236,7 @@ def googlenet(pretrained=False, **kwargs):
Args:
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>`.
Returns:
...
...
@@ -245,20 +245,20 @@ def googlenet(pretrained=False, **kwargs):
Examples:
.. code-block:: python
import paddle
from paddle.vision.models import googlenet
>>>
import paddle
>>>
from paddle.vision.models import googlenet
# b
uild model
model = googlenet()
>>> # B
uild model
>>>
model = googlenet()
# b
uild model and load imagenet pretrained weight
# model = googlenet(pretrained=True)
>>> # B
uild model and load imagenet pretrained weight
>>>
# model = googlenet(pretrained=True)
x = paddle.rand([1, 3, 224, 224])
out, out1, out2 = model(x)
>>>
x = paddle.rand([1, 3, 224, 224])
>>>
out, out1, out2 = model(x)
print(out.shape, out1.shape, out2.shape)
#
[1, 1000] [1, 1000] [1, 1000]
>>>
print(out.shape, out1.shape, out2.shape)
[1, 1000] [1, 1000] [1, 1000]
"""
model
=
GoogLeNet
(
**
kwargs
)
arch
=
"googlenet"
...
...
python/paddle/vision/models/inceptionv3.py
浏览文件 @
5356f2e0
...
...
@@ -491,7 +491,7 @@ class InceptionV3(nn.Layer):
Args:
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.
Returns:
...
...
@@ -500,16 +500,16 @@ class InceptionV3(nn.Layer):
Examples:
.. code-block:: python
import paddle
from paddle.vision.models import InceptionV3
>>>
import paddle
>>>
from paddle.vision.models import InceptionV3
inception_v3 = InceptionV3()
>>>
inception_v3 = InceptionV3()
x = paddle.rand([1, 3, 299, 299])
out = inception_v3(x)
>>>
x = paddle.rand([1, 3, 299, 299])
>>>
out = inception_v3(x)
print(out.shape)
#
[1, 1000]
>>>
print(out.shape)
[1, 1000]
"""
def
__init__
(
self
,
num_classes
=
1000
,
with_pool
=
True
):
...
...
@@ -591,7 +591,7 @@ def inception_v3(pretrained=False, **kwargs):
Args:
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>`.
Returns:
...
...
@@ -600,20 +600,20 @@ def inception_v3(pretrained=False, **kwargs):
Examples:
.. code-block:: python
import paddle
from paddle.vision.models import inception_v3
>>>
import paddle
>>>
from paddle.vision.models import inception_v3
# b
uild model
model = inception_v3()
>>> # B
uild model
>>>
model = inception_v3()
# b
uild model and load imagenet pretrained weight
# model = inception_v3(pretrained=True)
>>> # B
uild model and load imagenet pretrained weight
>>>
# model = inception_v3(pretrained=True)
x = paddle.rand([1, 3, 299, 299])
out = model(x)
>>>
x = paddle.rand([1, 3, 299, 299])
>>>
out = model(x)
print(out.shape)
#
[1, 1000]
>>>
print(out.shape)
[1, 1000]
"""
model
=
InceptionV3
(
**
kwargs
)
arch
=
"inception_v3"
...
...
python/paddle/vision/models/lenet.py
浏览文件 @
5356f2e0
...
...
@@ -24,7 +24,7 @@ class LeNet(nn.Layer):
Args:
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:
:ref:`api_paddle_nn_Layer`. An instance of LeNet model.
...
...
@@ -32,16 +32,16 @@ class LeNet(nn.Layer):
Examples:
.. code-block:: python
import paddle
from paddle.vision.models import LeNet
>>>
import paddle
>>>
from paddle.vision.models import LeNet
model = LeNet()
>>>
model = LeNet()
x = paddle.rand([1, 1, 28, 28])
out = model(x)
>>>
x = paddle.rand([1, 1, 28, 28])
>>>
out = model(x)
print(out.shape)
#
[1, 10]
>>>
print(out.shape)
[1, 10]
"""
def
__init__
(
self
,
num_classes
=
10
):
...
...
python/paddle/vision/models/mobilenetv1.py
浏览文件 @
5356f2e0
...
...
@@ -70,7 +70,7 @@ class MobileNetV1(nn.Layer):
Args:
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
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.
Returns:
...
...
@@ -79,16 +79,16 @@ class MobileNetV1(nn.Layer):
Examples:
.. code-block:: python
import paddle
from paddle.vision.models import MobileNetV1
>>>
import paddle
>>>
from paddle.vision.models import MobileNetV1
model = MobileNetV1()
>>>
model = MobileNetV1()
x = paddle.rand([1, 3, 224, 224])
out = model(x)
>>>
x = paddle.rand([1, 3, 224, 224])
>>>
out = model(x)
print(out.shape)
#
[1, 1000]
>>>
print(out.shape)
[1, 1000]
"""
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):
Args:
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.
**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):
Examples:
.. code-block:: python
import paddle
from paddle.vision.models import mobilenet_v1
>>>
import paddle
>>>
from paddle.vision.models import mobilenet_v1
# b
uild model
model = mobilenet_v1()
>>> # B
uild model
>>>
model = mobilenet_v1()
# b
uild model and load imagenet pretrained weight
# model = mobilenet_v1(pretrained=True)
>>> # B
uild model and load imagenet pretrained weight
>>>
# model = mobilenet_v1(pretrained=True)
# build mobilenet v1 with scale=0.5
model_scale = mobilenet_v1(scale=0.5)
>>>
# build mobilenet v1 with scale=0.5
>>>
model_scale = mobilenet_v1(scale=0.5)
x = paddle.rand([1, 3, 224, 224])
out = model(x)
>>>
x = paddle.rand([1, 3, 224, 224])
>>>
out = model(x)
print(out.shape)
#
[1, 1000]
>>>
print(out.shape)
[1, 1000]
"""
model
=
_mobilenet
(
'mobilenetv1_'
+
str
(
scale
),
pretrained
,
scale
=
scale
,
**
kwargs
...
...
python/paddle/vision/models/mobilenetv2.py
浏览文件 @
5356f2e0
...
...
@@ -81,7 +81,7 @@ class MobileNetV2(nn.Layer):
Args:
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
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.
Returns:
...
...
@@ -90,16 +90,16 @@ class MobileNetV2(nn.Layer):
Examples:
.. code-block:: python
import paddle
from paddle.vision.models import MobileNetV2
>>>
import paddle
>>>
from paddle.vision.models import MobileNetV2
model = MobileNetV2()
>>>
model = MobileNetV2()
x = paddle.rand([1, 3, 224, 224])
out = model(x)
>>>
x = paddle.rand([1, 3, 224, 224])
>>>
out = model(x)
print(out.shape)
#
[1, 1000]
>>>
print(out.shape)
[1, 1000]
"""
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):
`"MobileNetV2: Inverted Residuals and Linear Bottlenecks" <https://arxiv.org/abs/1801.04381>`_.
Args:
pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained
on ImageNet. Default: False.
pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained on ImageNet. Default: False.
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>`.
...
...
@@ -217,23 +216,23 @@ def mobilenet_v2(pretrained=False, scale=1.0, **kwargs):
Examples:
.. code-block:: python
import paddle
from paddle.vision.models import mobilenet_v2
>>>
import paddle
>>>
from paddle.vision.models import mobilenet_v2
# b
uild model
model = mobilenet_v2()
>>> # B
uild model
>>>
model = mobilenet_v2()
# b
uild model and load imagenet pretrained weight
# model = mobilenet_v2(pretrained=True)
>>> # B
uild model and load imagenet pretrained weight
>>>
# model = mobilenet_v2(pretrained=True)
# b
uild mobilenet v2 with scale=0.5
model = mobilenet_v2(scale=0.5)
>>> # B
uild mobilenet v2 with scale=0.5
>>>
model = mobilenet_v2(scale=0.5)
x = paddle.rand([1, 3, 224, 224])
out = model(x)
>>>
x = paddle.rand([1, 3, 224, 224])
>>>
out = model(x)
print(out.shape)
#
[1, 1000]
>>>
print(out.shape)
[1, 1000]
"""
model
=
_mobilenet
(
'mobilenetv2_'
+
str
(
scale
),
pretrained
,
scale
=
scale
,
**
kwargs
...
...
python/paddle/vision/models/mobilenetv3.py
浏览文件 @
5356f2e0
...
...
@@ -41,11 +41,12 @@ class SqueezeExcitation(nn.Layer):
Parameters ``activation``, and ``scale_activation`` correspond to ``delta`` and ``sigma`` in eq. 3.
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
Args:
input_channels (int): Number of channels in the input image
squeeze_channels (int): Number of squeeze channels
activation (Callable[..., paddle.nn.Layer], optional): ``delta`` activation. Default: ``paddle.nn.ReLU``
scale_activation (Callable[..., paddle.nn.Layer]): ``sigma`` activation. Default: ``paddle.nn.Sigmoid``
input_channels (int): Number of channels in the input image
.
squeeze_channels (int): Number of squeeze channels
.
activation (Callable[..., paddle.nn.Layer], optional): ``delta`` activation. Default: ``paddle.nn.ReLU``
.
scale_activation (Callable[..., paddle.nn.Layer]): ``sigma`` activation. Default: ``paddle.nn.Sigmoid``
.
"""
def
__init__
(
...
...
@@ -190,7 +191,7 @@ class MobileNetV3(nn.Layer):
last_channel (int): The number of channels on the penultimate layer.
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
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.
"""
...
...
@@ -280,7 +281,7 @@ class MobileNetV3Small(MobileNetV3):
Args:
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
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.
Returns:
...
...
@@ -289,17 +290,17 @@ class MobileNetV3Small(MobileNetV3):
Examples:
.. code-block:: python
import paddle
from paddle.vision.models import MobileNetV3Small
>>>
import paddle
>>>
from paddle.vision.models import MobileNetV3Small
# b
uild model
model = MobileNetV3Small(scale=1.0)
>>> # B
uild model
>>>
model = MobileNetV3Small(scale=1.0)
x = paddle.rand([1, 3, 224, 224])
out = model(x)
>>>
x = paddle.rand([1, 3, 224, 224])
>>>
out = model(x)
print(out.shape)
#
[1, 1000]
>>>
print(out.shape)
[1, 1000]
"""
def
__init__
(
self
,
scale
=
1.0
,
num_classes
=
1000
,
with_pool
=
True
):
...
...
@@ -333,7 +334,7 @@ class MobileNetV3Large(MobileNetV3):
Args:
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
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.
Returns:
...
...
@@ -342,17 +343,17 @@ class MobileNetV3Large(MobileNetV3):
Examples:
.. code-block:: python
import paddle
from paddle.vision.models import MobileNetV3Large
>>>
import paddle
>>>
from paddle.vision.models import MobileNetV3Large
# b
uild model
model = MobileNetV3Large(scale=1.0)
>>> # B
uild model
>>>
model = MobileNetV3Large(scale=1.0)
x = paddle.rand([1, 3, 224, 224])
out = model(x)
>>>
x = paddle.rand([1, 3, 224, 224])
>>>
out = model(x)
print(out.shape)
#
[1, 1000]
>>>
print(out.shape)
[1, 1000]
"""
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):
`"Searching for MobileNetV3" <https://arxiv.org/abs/1905.02244>`_.
Args:
pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained
on ImageNet. Default: False.
pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained on ImageNet. Default: False.
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>`.
...
...
@@ -438,23 +438,23 @@ def mobilenet_v3_small(pretrained=False, scale=1.0, **kwargs):
Examples:
.. code-block:: python
import paddle
from paddle.vision.models import mobilenet_v3_small
>>>
import paddle
>>>
from paddle.vision.models import mobilenet_v3_small
# b
uild model
model = mobilenet_v3_small()
>>> # B
uild model
>>>
model = mobilenet_v3_small()
# b
uild model and load imagenet pretrained weight
# model = mobilenet_v3_small(pretrained=True)
>>> # B
uild model and load imagenet pretrained weight
>>>
# model = mobilenet_v3_small(pretrained=True)
# b
uild mobilenet v3 small model with scale=0.5
model = mobilenet_v3_small(scale=0.5)
>>> # B
uild mobilenet v3 small model with scale=0.5
>>>
model = mobilenet_v3_small(scale=0.5)
x = paddle.rand([1, 3, 224, 224])
out = model(x)
>>>
x = paddle.rand([1, 3, 224, 224])
>>>
out = model(x)
print(out.shape)
#
[1, 1000]
>>>
print(out.shape)
[1, 1000]
"""
model
=
_mobilenet_v3
(
"mobilenet_v3_small"
,
scale
=
scale
,
pretrained
=
pretrained
,
**
kwargs
...
...
@@ -467,8 +467,7 @@ def mobilenet_v3_large(pretrained=False, scale=1.0, **kwargs):
`"Searching for MobileNetV3" <https://arxiv.org/abs/1905.02244>`_.
Args:
pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained
on ImageNet. Default: False.
pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained on ImageNet. Default: False.
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>`.
...
...
@@ -478,23 +477,23 @@ def mobilenet_v3_large(pretrained=False, scale=1.0, **kwargs):
Examples:
.. code-block:: python
import paddle
from paddle.vision.models import mobilenet_v3_large
>>>
import paddle
>>>
from paddle.vision.models import mobilenet_v3_large
# b
uild model
model = mobilenet_v3_large()
>>> # B
uild model
>>>
model = mobilenet_v3_large()
# b
uild model and load imagenet pretrained weight
# model = mobilenet_v3_large(pretrained=True)
>>> # B
uild model and load imagenet pretrained weight
>>>
# model = mobilenet_v3_large(pretrained=True)
# b
uild mobilenet v3 large model with scale=0.5
model = mobilenet_v3_large(scale=0.5)
>>> # B
uild mobilenet v3 large model with scale=0.5
>>>
model = mobilenet_v3_large(scale=0.5)
x = paddle.rand([1, 3, 224, 224])
out = model(x)
>>>
x = paddle.rand([1, 3, 224, 224])
>>>
out = model(x)
print(out.shape)
#
[1, 1000]
>>>
print(out.shape)
[1, 1000]
"""
model
=
_mobilenet_v3
(
"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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录