Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: update documentation about "PaddlePaddle" in "INTEGRATIONS" #1152

Merged
merged 1 commit into from
Dec 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions docs/code/use_dataset_in_paddlepaddle.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
from tensorbay.dataset import Dataset as TensorBayDataset


class MNISTSegment(Dataset):
"""class for wrapping a MNIST segment."""
class DogsVsCatsSegment(Dataset):
"""class for wrapping a DogsVsCats segment."""

def __init__(self, gas, segment_name, transform):
super().__init__()
self.dataset = TensorBayDataset("MNIST", gas)
self.dataset = TensorBayDataset("DogsVsCats", gas)
self.segment = self.dataset[segment_name]
self.category_to_index = self.dataset.catalog.classification.get_category_to_index()
self.transform = transform
Expand All @@ -38,18 +38,17 @@ def __getitem__(self, idx):
image_tensor = self.transform(Image.open(fp))

return image_tensor, self.category_to_index[data.label.classification.category]
# """"""


""""""

"""Build a dataloader and run it"""
ACCESS_KEY = "Accesskey-*****"

to_tensor = transforms.ToTensor()
normalization = transforms.Normalize(mean=[0.485], std=[0.229])
my_transforms = transforms.Compose([to_tensor, normalization])

train_segment = MNISTSegment(GAS(ACCESS_KEY), segment_name="train", transform=my_transforms)
train_segment = DogsVsCatsSegment(GAS(ACCESS_KEY), segment_name="train", transform=my_transforms)
train_dataloader = DataLoader(train_segment, batch_size=4, shuffle=True, num_workers=0)

for index, (image, label) in enumerate(train_dataloader):
Expand Down
6 changes: 3 additions & 3 deletions docs/source/integrations/paddlepaddle.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
###############

This topic describes how to integrate TensorBay dataset with PaddlePaddle Pipeline
using the `MNIST Dataset <https://gas.graviti.cn/dataset/data-decorators/MNIST>`_ as an example.
using the `DogsVsCats Dataset <https://gas.graviti.cn/dataset/data-decorators/DogsVsCats>`_ as an example.

The typical method to integrate TensorBay dataset with PaddlePaddle is to build a "Segment" class
derived from ``paddle.io.Dataset``.

.. literalinclude:: ../../../docs/code/use_dataset_in_paddlepaddle.py
:language: python
:start-after: """Build a Segment class"""
:end-before: """"""
:end-before: # """"""

Using the following code to create a PaddlePaddle dataloader and run it:

.. literalinclude:: ../../../docs/code/use_dataset_in_paddlepaddle.py
:language: python
:start-after: """Build a dataloader and run it"""
:end-before: """"""
:end-before: """"""