未验证 提交 fc71459f 编写于 作者: D David Nicolas 提交者: GitHub

[xdoctest][task 167-170] reformat example code with google style in...

[xdoctest][task 167-170] reformat example code with google style in /paddle/vision/datasets/*; test=docs_preview (#56906)

* reformat example code with google style

* udpate

* update

* add timeout for dataset download

* update cifar timeout

* update cifar timeout and fix an output

* update cifar timeout

* add a blank line

---------
Co-authored-by: NSigureMo <sigure.qaq@gmail.com>
上级 8aaceba5
...@@ -55,8 +55,9 @@ def is_float16_supported(device=None): ...@@ -55,8 +55,9 @@ def is_float16_supported(device=None):
.. code-block:: python .. code-block:: python
import paddle >>> import paddle
paddle.amp.is_float16_supported() # True or False >>> paddle.amp.is_float16_supported() # True or False
False
""" """
device = ( device = (
...@@ -81,8 +82,9 @@ def is_bfloat16_supported(device=None): ...@@ -81,8 +82,9 @@ def is_bfloat16_supported(device=None):
.. code-block:: python .. code-block:: python
import paddle >>> import paddle
paddle.amp.is_bfloat16_supported() # True or False >>> paddle.amp.is_bfloat16_supported() # True or False
True
""" """
device = ( device = (
......
...@@ -61,46 +61,46 @@ class Cifar10(Dataset): ...@@ -61,46 +61,46 @@ class Cifar10(Dataset):
.. code-block:: python .. code-block:: python
import itertools >>> # doctest: +TIMEOUT(60)
import paddle.vision.transforms as T >>> import itertools
from paddle.vision.datasets import Cifar10 >>> import paddle.vision.transforms as T
>>> from paddle.vision.datasets import Cifar10
cifar10 = Cifar10() >>> cifar10 = Cifar10()
print(len(cifar10)) >>> print(len(cifar10))
# 50000 50000
for i in range(5): # only show first 5 images >>> for i in range(5): # only show first 5 images
img, label = cifar10[i] ... img, label = cifar10[i]
# do something with img and label ... # do something with img and label
print(type(img), img.size, label) ... print(type(img), img.size, label)
# <class 'PIL.Image.Image'> (32, 32) 6 ... # <class 'PIL.Image.Image'> (32, 32) 6
transform = T.Compose( >>> transform = T.Compose(
[ ... [
T.Resize(64), ... T.Resize(64),
T.ToTensor(), ... T.ToTensor(),
T.Normalize( ... T.Normalize(
mean=[0.5, 0.5, 0.5], ... mean=[0.5, 0.5, 0.5],
std=[0.5, 0.5, 0.5], ... std=[0.5, 0.5, 0.5],
to_rgb=True, ... to_rgb=True,
), ... ),
] ... ]
) ... )
>>> cifar10_test = Cifar10(
cifar10_test = Cifar10( ... mode="test",
mode="test", ... transform=transform, # apply transform to every image
transform=transform, # apply transform to every image ... backend="cv2", # use OpenCV as image transform backend
backend="cv2", # use OpenCV as image transform backend ... )
) >>> print(len(cifar10_test))
print(len(cifar10_test)) 10000
# 10000
>>> for img, label in itertools.islice(iter(cifar10_test), 5): # only show first 5 images
... # do something with img and label
... print(type(img), img.shape, label)
... # <class 'paddle.Tensor'> [3, 64, 64] 3
for img, label in itertools.islice(iter(cifar10_test), 5): # only show first 5 images
# do something with img and label
print(type(img), img.shape, label)
# <class 'paddle.Tensor'> [3, 64, 64] 3
""" """
def __init__( def __init__(
...@@ -210,46 +210,47 @@ class Cifar100(Cifar10): ...@@ -210,46 +210,47 @@ class Cifar100(Cifar10):
.. code-block:: python .. code-block:: python
import itertools >>> # doctest: +TIMEOUT(60)
import paddle.vision.transforms as T >>> import itertools
from paddle.vision.datasets import Cifar100 >>> import paddle.vision.transforms as T
>>> from paddle.vision.datasets import Cifar100
cifar100 = Cifar100() >>> cifar100 = Cifar100()
print(len(cifar100)) >>> print(len(cifar100))
# 50000 50000
for i in range(5): # only show first 5 images >>> for i in range(5): # only show first 5 images
img, label = cifar100[i] ... img, label = cifar100[i]
# do something with img and label ... # do something with img and label
print(type(img), img.size, label) ... print(type(img), img.size, label)
# <class 'PIL.Image.Image'> (32, 32) 19 ... # <class 'PIL.Image.Image'> (32, 32) 19
transform = T.Compose( >>> transform = T.Compose(
[ ... [
T.Resize(64), ... T.Resize(64),
T.ToTensor(), ... T.ToTensor(),
T.Normalize( ... T.Normalize(
mean=[0.5, 0.5, 0.5], ... mean=[0.5, 0.5, 0.5],
std=[0.5, 0.5, 0.5], ... std=[0.5, 0.5, 0.5],
to_rgb=True, ... to_rgb=True,
), ... ),
] ... ]
) ... )
cifar100_test = Cifar100( >>> cifar100_test = Cifar100(
mode="test", ... mode="test",
transform=transform, # apply transform to every image ... transform=transform, # apply transform to every image
backend="cv2", # use OpenCV as image transform backend ... backend="cv2", # use OpenCV as image transform backend
) ... )
print(len(cifar100_test)) >>> print(len(cifar100_test))
# 10000 10000
>>> for img, label in itertools.islice(iter(cifar100_test), 5): # only show first 5 images
... # do something with img and label
... print(type(img), img.shape, label)
... # <class 'paddle.Tensor'> [3, 64, 64] 49
for img, label in itertools.islice(iter(cifar100_test), 5): # only show first 5 images
# do something with img and label
print(type(img), img.shape, label)
# <class 'paddle.Tensor'> [3, 64, 64] 49
""" """
def __init__( def __init__(
......
...@@ -65,46 +65,44 @@ class Flowers(Dataset): ...@@ -65,46 +65,44 @@ class Flowers(Dataset):
.. code-block:: python .. code-block:: python
import itertools >>> # doctest: +TIMEOUT(60)
import paddle.vision.transforms as T >>> import itertools
from paddle.vision.datasets import Flowers >>> import paddle.vision.transforms as T
>>> from paddle.vision.datasets import Flowers
flowers = Flowers() >>> flowers = Flowers()
print(len(flowers)) >>> print(len(flowers))
# 6149 6149
for i in range(5): # only show first 5 images >>> for i in range(5): # only show first 5 images
img, label = flowers[i] ... img, label = flowers[i]
# do something with img and label ... # do something with img and label
print(type(img), img.size, label) ... print(type(img), img.size, label)
# <class 'PIL.JpegImagePlugin.JpegImageFile'> (523, 500) [1] ... # <class 'PIL.JpegImagePlugin.JpegImageFile'> (523, 500) [1]
>>> transform = T.Compose(
transform = T.Compose( ... [
[ ... T.Resize(64),
T.Resize(64), ... T.ToTensor(),
T.ToTensor(), ... T.Normalize(
T.Normalize( ... mean=[0.5, 0.5, 0.5],
mean=[0.5, 0.5, 0.5], ... std=[0.5, 0.5, 0.5],
std=[0.5, 0.5, 0.5], ... to_rgb=True,
to_rgb=True, ... ),
), ... ]
] ... )
) >>> flowers_test = Flowers(
... mode="test",
flowers_test = Flowers( ... transform=transform, # apply transform to every image
mode="test", ... backend="cv2", # use OpenCV as image transform backend
transform=transform, # apply transform to every image ... )
backend="cv2", # use OpenCV as image transform backend >>> print(len(flowers_test))
) 1020
print(len(flowers_test))
# 1020 >>> for img, label in itertools.islice(iter(flowers_test), 5): # only show first 5 images
... # do something with img and label
for img, label in itertools.islice(iter(flowers_test), 5): # only show first 5 images ... print(type(img), img.shape, label)
# do something with img and label ... # <class 'paddle.Tensor'> [3, 64, 96] [1]
print(type(img), img.shape, label)
# <class 'paddle.Tensor'> [3, 64, 96] [1]
""" """
def __init__( def __init__(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册