未验证 提交 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
......@@ -53,10 +53,11 @@ def is_float16_supported(device=None):
Examples:
.. code-block:: python
.. code-block:: python
import paddle
paddle.amp.is_float16_supported() # True or False
>>> import paddle
>>> paddle.amp.is_float16_supported() # True or False
False
"""
device = (
......@@ -79,10 +80,11 @@ def is_bfloat16_supported(device=None):
Examples:
.. code-block:: python
.. code-block:: python
import paddle
paddle.amp.is_bfloat16_supported() # True or False
>>> import paddle
>>> paddle.amp.is_bfloat16_supported() # True or False
True
"""
device = (
......
......@@ -61,46 +61,46 @@ class Cifar10(Dataset):
.. code-block:: python
import itertools
import paddle.vision.transforms as T
from paddle.vision.datasets import Cifar10
cifar10 = Cifar10()
print(len(cifar10))
# 50000
for i in range(5): # only show first 5 images
img, label = cifar10[i]
# do something with img and label
print(type(img), img.size, label)
# <class 'PIL.Image.Image'> (32, 32) 6
transform = T.Compose(
[
T.Resize(64),
T.ToTensor(),
T.Normalize(
mean=[0.5, 0.5, 0.5],
std=[0.5, 0.5, 0.5],
to_rgb=True,
),
]
)
cifar10_test = Cifar10(
mode="test",
transform=transform, # apply transform to every image
backend="cv2", # use OpenCV as image transform backend
)
print(len(cifar10_test))
# 10000
>>> # doctest: +TIMEOUT(60)
>>> import itertools
>>> import paddle.vision.transforms as T
>>> from paddle.vision.datasets import Cifar10
>>> cifar10 = Cifar10()
>>> print(len(cifar10))
50000
>>> for i in range(5): # only show first 5 images
... img, label = cifar10[i]
... # do something with img and label
... print(type(img), img.size, label)
... # <class 'PIL.Image.Image'> (32, 32) 6
>>> transform = T.Compose(
... [
... T.Resize(64),
... T.ToTensor(),
... T.Normalize(
... mean=[0.5, 0.5, 0.5],
... std=[0.5, 0.5, 0.5],
... to_rgb=True,
... ),
... ]
... )
>>> cifar10_test = Cifar10(
... mode="test",
... transform=transform, # apply transform to every image
... backend="cv2", # use OpenCV as image transform backend
... )
>>> print(len(cifar10_test))
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__(
......@@ -210,46 +210,47 @@ class Cifar100(Cifar10):
.. code-block:: python
import itertools
import paddle.vision.transforms as T
from paddle.vision.datasets import Cifar100
cifar100 = Cifar100()
print(len(cifar100))
# 50000
for i in range(5): # only show first 5 images
img, label = cifar100[i]
# do something with img and label
print(type(img), img.size, label)
# <class 'PIL.Image.Image'> (32, 32) 19
transform = T.Compose(
[
T.Resize(64),
T.ToTensor(),
T.Normalize(
mean=[0.5, 0.5, 0.5],
std=[0.5, 0.5, 0.5],
to_rgb=True,
),
]
)
cifar100_test = Cifar100(
mode="test",
transform=transform, # apply transform to every image
backend="cv2", # use OpenCV as image transform backend
)
print(len(cifar100_test))
# 10000
>>> # doctest: +TIMEOUT(60)
>>> import itertools
>>> import paddle.vision.transforms as T
>>> from paddle.vision.datasets import Cifar100
>>> cifar100 = Cifar100()
>>> print(len(cifar100))
50000
>>> for i in range(5): # only show first 5 images
... img, label = cifar100[i]
... # do something with img and label
... print(type(img), img.size, label)
... # <class 'PIL.Image.Image'> (32, 32) 19
>>> transform = T.Compose(
... [
... T.Resize(64),
... T.ToTensor(),
... T.Normalize(
... mean=[0.5, 0.5, 0.5],
... std=[0.5, 0.5, 0.5],
... to_rgb=True,
... ),
... ]
... )
>>> cifar100_test = Cifar100(
... mode="test",
... transform=transform, # apply transform to every image
... backend="cv2", # use OpenCV as image transform backend
... )
>>> print(len(cifar100_test))
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__(
......
......@@ -65,46 +65,44 @@ class Flowers(Dataset):
.. code-block:: python
import itertools
import paddle.vision.transforms as T
from paddle.vision.datasets import Flowers
flowers = Flowers()
print(len(flowers))
# 6149
for i in range(5): # only show first 5 images
img, label = flowers[i]
# do something with img and label
print(type(img), img.size, label)
# <class 'PIL.JpegImagePlugin.JpegImageFile'> (523, 500) [1]
transform = T.Compose(
[
T.Resize(64),
T.ToTensor(),
T.Normalize(
mean=[0.5, 0.5, 0.5],
std=[0.5, 0.5, 0.5],
to_rgb=True,
),
]
)
flowers_test = Flowers(
mode="test",
transform=transform, # apply transform to every image
backend="cv2", # use OpenCV as image transform backend
)
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
print(type(img), img.shape, label)
# <class 'paddle.Tensor'> [3, 64, 96] [1]
>>> # doctest: +TIMEOUT(60)
>>> import itertools
>>> import paddle.vision.transforms as T
>>> from paddle.vision.datasets import Flowers
>>> flowers = Flowers()
>>> print(len(flowers))
6149
>>> for i in range(5): # only show first 5 images
... img, label = flowers[i]
... # do something with img and label
... print(type(img), img.size, label)
... # <class 'PIL.JpegImagePlugin.JpegImageFile'> (523, 500) [1]
>>> transform = T.Compose(
... [
... T.Resize(64),
... T.ToTensor(),
... T.Normalize(
... mean=[0.5, 0.5, 0.5],
... std=[0.5, 0.5, 0.5],
... to_rgb=True,
... ),
... ]
... )
>>> flowers_test = Flowers(
... mode="test",
... transform=transform, # apply transform to every image
... backend="cv2", # use OpenCV as image transform backend
... )
>>> 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
... print(type(img), img.shape, label)
... # <class 'paddle.Tensor'> [3, 64, 96] [1]
"""
def __init__(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册