Skip to content

Commit 90fd1e2

Browse files
committed
docs: use template to generate rst files in "Examples"
1 parent c57ea4b commit 90fd1e2

11 files changed

Lines changed: 505 additions & 145 deletions

File tree

docs/code/LeedsSportsPose.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@
4343
dataset = Dataset("LeedsSportsPose", gas)
4444
""""""
4545

46+
"""Read Dataset / list segment names"""
47+
dataset.keys()
48+
""""""
49+
4650
"""Read Dataset / get segment"""
4751
segment = dataset[0]
4852
""""""

docs/code/NeolixOD.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@
4242
dataset = Dataset("NeolixOD", gas)
4343
""""""
4444

45+
"""Read Dataset / list segment names"""
46+
dataset.keys()
47+
""""""
48+
4549
"""Read Dataset / get segment"""
4650
segment = dataset[0]
4751
""""""

docs/source/conf.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@
1515
# documentation root, use os.path.abspath to make it absolute, like shown here.
1616
#
1717
"""Configuration file for the Sphinx documentation builder."""
18+
import os
1819
import sys
1920
from pathlib import Path
2021

22+
import jinja2
23+
2124
sys.path.insert(0, str(Path(__file__).parents[2]))
2225

2326

@@ -79,3 +82,34 @@
7982
# relative to this directory. They are copied after the builtin static files,
8083
# so a file named "default.css" will overwrite the builtin "default.css".
8184
# html_static_path = ["_static"]
85+
86+
source_path = os.path.dirname(os.path.abspath(__file__))
87+
example_path = os.path.join(source_path, "quick_start", "examples")
88+
datasets = (
89+
"Dogs Vs Cats",
90+
"20 Newsgroups",
91+
"BSTLD",
92+
"Neolix OD",
93+
"Leeds Sports Pose",
94+
"THCHS-30",
95+
)
96+
label_types = (
97+
"Classification",
98+
"Classification",
99+
"Box2D",
100+
"Box3D",
101+
"Keypoints2D",
102+
"Sentence",
103+
)
104+
file_names = ("DogsVsCats", "Newsgroups20", "BSTLD", "NeolixOD", "LeedsSportsPose", "THCHS30")
105+
for dataset_name, label_type, file_name in zip(datasets, label_types, file_names):
106+
with open(os.path.join(example_path, "examples.rst.template"), encoding="utf-8") as f:
107+
t = jinja2.Template(f.read())
108+
with open(os.path.join(example_path, f"{file_name}.rst"), "w", encoding="utf-8") as f:
109+
f.write(
110+
t.render(
111+
dataset_name=dataset_name,
112+
label_type=label_type,
113+
file_name=file_name,
114+
)
115+
)

docs/source/quick_start/examples/BSTLD.rst

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
########
1+
2+
3+
##################
24
BSTLD
3-
########
5+
##################
46

57
This topic describes how to manage the `BSTLD Dataset <https://gas.graviti.cn/dataset/data-decorators/BSTLD>`_,
6-
which is a dataset with :ref:`reference/label_format/Box2D:Box2D` label(:numref:`Fig. %s <example-bstld>`).
8+
which is a dataset with :ref:`reference/label_format/Box2D:Box2D` label
9+
(:numref:`Fig. %s <example-bstld>`).
710

811
.. _example-bstld:
912

@@ -13,6 +16,7 @@ which is a dataset with :ref:`reference/label_format/Box2D:Box2D` label(:numref:
1316

1417
The preview of a cropped image with labels from "BSTLD".
1518

19+
1620
*****************************
1721
Authorize a Client Instance
1822
*****************************
@@ -48,16 +52,28 @@ Step 1: Write the Catalog
4852
=========================
4953

5054
A :ref:`reference/dataset_structure:catalog` contains all label information of one dataset, which
51-
is typically stored in a json file like ``catalog.json``.
55+
is typically stored in a json file like ``catalog.json``.
56+
5257

5358
.. literalinclude:: ../../../../tensorbay/opendataset/BSTLD/catalog.json
5459
:language: json
5560
:name: BSTLD-catalog
5661
:linenos:
5762

63+
64+
5865
The only annotation type for "BSTLD" is :ref:`reference/label_format/Box2D:Box2D`, and there are 13
5966
:ref:`reference/label_format/CommonLabelProperties:category` types and one :ref:`reference/label_format/CommonLabelProperties:attributes` type.
6067

68+
69+
70+
71+
72+
73+
74+
75+
76+
6177
.. note::
6278

6379
By passing the path of the ``catalog.json``, :func:`~tensorbay.dataset.dataset.DatasetBase.load_catalog` supports loading the catalog into dataset.
@@ -114,7 +130,7 @@ The organized "BSTLD" dataset can be uploaded to TensorBay for sharing, reuse, e
114130
:end-before: """"""
115131

116132
.. note::
117-
Set `skip_uploaded_files=True` to skip uploaded data.
133+
Set ``skip_uploaded_files=True`` to skip uploaded data.
118134
The data will be skiped if its name and segment name is the same as remote data.
119135

120136
Similar with Git, the commit step after uploading can record changes to the dataset as a version.
@@ -132,8 +148,6 @@ Now "BSTLD" dataset can be read from TensorBay.
132148
:start-after: """Read Dataset / get dataset"""
133149
:end-before: """"""
134150

135-
In :ref:`reference/dataset_structure:dataset` "BSTLD", there are three
136-
:ref:`segments <reference/dataset_structure:segment>`: ``train``, ``test`` and ``additional``.
137151
Get the segment names by listing them all.
138152

139153
.. literalinclude:: ../../../../docs/code/BSTLD.py
@@ -148,8 +162,7 @@ Get a segment by passing the required segment name.
148162
:start-after: """Read Dataset / get segment"""
149163
:end-before: """"""
150164

151-
152-
In the train :ref:`reference/dataset_structure:segment`, there is a sequence of :ref:`reference/dataset_structure:data`,
165+
In the :ref:`reference/dataset_structure:segment`, there is a sequence of :ref:`reference/dataset_structure:data`,
153166
which can be obtained by index.
154167

155168
.. literalinclude:: ../../../../docs/code/BSTLD.py
@@ -167,16 +180,18 @@ which can be obtained by index.
167180
:end-before: """"""
168181

169182
There is only one label type in "BSTLD" dataset, which is ``box2d``.
183+
170184
The information stored in :ref:`reference/label_format/CommonLabelProperties:category` is
171185
one of the names in "categories" list of :ref:`catalog.json <BSTLD-catalog>`. The information stored
172186
in :ref:`reference/label_format/CommonLabelProperties:attributes` is one or several of the attributes in "attributes" list of :ref:`catalog.json <BSTLD-catalog>`.
173187
See :ref:`reference/label_format/Box2D:Box2D` label format for more details.
174188

189+
175190
****************
176191
Delete Dataset
177192
****************
178193

179194
.. literalinclude:: ../../../../docs/code/BSTLD.py
180195
:language: python
181196
:start-after: """Delete Dataset"""
182-
:end-before: """"""
197+
:end-before: """"""

docs/source/quick_start/examples/DogsVsCats.rst

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
##############
2-
Dogs vs Cats
3-
##############
41

5-
This topic describes how to manage the `Dogs vs Cats Dataset <https://gas.graviti.cn/dataset/data-decorators/DogsVsCats>`_,
6-
which is a dataset with :ref:`reference/label_format/Classification:Classification` label.
2+
3+
##################
4+
Dogs Vs Cats
5+
##################
6+
7+
This topic describes how to manage the `Dogs Vs Cats Dataset <https://gas.graviti.cn/dataset/data-decorators/DogsVsCats>`_,
8+
which is a dataset with :ref:`reference/label_format/Classification:Classification` label
79

810
*****************************
911
Authorize a Client Instance
@@ -29,27 +31,39 @@ An :ref:`reference/glossary:accesskey` is needed to authenticate identity when u
2931
Organize Dataset
3032
******************
3133

32-
Normally, ``dataloader.py`` and ``catalog.json`` are required to organize the "Dogs vs Cats" dataset into the :class:`~tensorbay.dataset.dataset.Dataset` instance.
34+
Normally, ``dataloader.py`` and ``catalog.json`` are required to organize the "Dogs Vs Cats" dataset into the :class:`~tensorbay.dataset.dataset.Dataset` instance.
3335
In this example, they are stored in the same directory like::
3436

35-
Dogs vs Cats/
37+
Dogs Vs Cats/
3638
catalog.json
3739
dataloader.py
3840

3941
Step 1: Write the Catalog
4042
=========================
4143

4244
A :ref:`reference/dataset_structure:catalog` contains all label information of one dataset, which
43-
is typically stored in a json file like ``catalog.json``.
45+
is typically stored in a json file like ``catalog.json``.
46+
4447

4548
.. literalinclude:: ../../../../tensorbay/opendataset/DogsVsCats/catalog.json
4649
:language: json
47-
:name: dogsvscats-catalog
50+
:name: DogsVsCats-catalog
4851
:linenos:
4952

50-
The only annotation type for "Dogs vs Cats" is :ref:`reference/label_format/Classification:Classification`, and there are 2
53+
54+
55+
56+
57+
The only annotation type for "Dogs Vs Cats" is :ref:`reference/label_format/Classification:Classification`, and there are 2
5158
:ref:`reference/label_format/CommonLabelProperties:category` types.
5259

60+
61+
62+
63+
64+
65+
66+
5367
.. note::
5468

5569
By passing the path of the ``catalog.json``, :func:`~tensorbay.dataset.dataset.DatasetBase.load_catalog` supports loading the catalog into dataset.
@@ -61,19 +75,17 @@ The only annotation type for "Dogs vs Cats" is :ref:`reference/label_format/Clas
6175
Step 2: Write the Dataloader
6276
============================
6377

64-
A :ref:`reference/glossary:dataloader` is needed to organize the dataset into
65-
a :class:`~tensorbay.dataset.dataset.Dataset` instance.
78+
A :ref:`reference/glossary:dataloader` is needed to organize the dataset into a :class:`~tensorbay.dataset.dataset.Dataset` instance.
6679

6780
.. literalinclude:: ../../../../tensorbay/opendataset/DogsVsCats/loader.py
6881
:language: python
69-
:name: dogsvscats-dataloader
82+
:name: DogsVsCats-dataloader
7083
:linenos:
7184

7285
See :ref:`Classification annotation <reference/label_format/Classification:Classification>` for more details.
7386

74-
7587
There are already a number of dataloaders in TensorBay SDK provided by the community.
76-
Thus, instead of writing, importing an available dataloadert is also feasible.
88+
Thus, instead of writing, importing an available dataloader is also feasible.
7789

7890
.. literalinclude:: ../../../../docs/code/DogsVsCats.py
7991
:language: python
@@ -86,7 +98,7 @@ Thus, instead of writing, importing an available dataloadert is also feasible.
8698

8799
.. important::
88100

89-
See :ref:`dataloader table <reference/glossary:dataloader>` for more examples of dataloaders with different label types.
101+
See :ref:`dataloader table <reference/glossary:dataloader>` for dataloaders with different label types.
90102

91103
*******************
92104
Visualize Dataset
@@ -100,13 +112,17 @@ Please see :ref:`features/visualization:Visualization` for more details.
100112
Upload Dataset
101113
****************
102114

103-
The organized "Dogs vs Cats" dataset can be uploaded to TensorBay for sharing, reuse, etc.
115+
The organized "Dogs Vs Cats" dataset can be uploaded to TensorBay for sharing, reuse, etc.
104116

105117
.. literalinclude:: ../../../../docs/code/DogsVsCats.py
106118
:language: python
107119
:start-after: """Upload Dataset"""
108120
:end-before: """"""
109121

122+
.. note::
123+
Set ``skip_uploaded_files=True`` to skip uploaded data.
124+
The data will be skiped if its name and segment name is the same as remote data.
125+
110126
Similar with Git, the commit step after uploading can record changes to the dataset as a version.
111127
If needed, do the modifications and commit again.
112128
Please see :ref:`features/version_control/index:Version Control` for more details.
@@ -115,15 +131,13 @@ Please see :ref:`features/version_control/index:Version Control` for more detail
115131
Read Dataset
116132
**************
117133

118-
Now "Dogs vs Cats" dataset can be read from TensorBay.
134+
Now "Dogs Vs Cats" dataset can be read from TensorBay.
119135

120136
.. literalinclude:: ../../../../docs/code/DogsVsCats.py
121137
:language: python
122138
:start-after: """Read Dataset / get dataset"""
123139
:end-before: """"""
124140

125-
In :ref:`reference/dataset_structure:dataset` "Dogs vs Cats", there are two
126-
:ref:`segments <reference/dataset_structure:segment>`: ``train`` and ``test``.
127141
Get the segment names by listing them all.
128142

129143
.. literalinclude:: ../../../../docs/code/DogsVsCats.py
@@ -138,7 +152,7 @@ Get a segment by passing the required segment name.
138152
:start-after: """Read Dataset / get segment"""
139153
:end-before: """"""
140154

141-
In the train :ref:`reference/dataset_structure:segment`, there is a sequence of :ref:`reference/dataset_structure:data`,
155+
In the :ref:`reference/dataset_structure:segment`, there is a sequence of :ref:`reference/dataset_structure:data`,
142156
which can be obtained by index.
143157

144158
.. literalinclude:: ../../../../docs/code/DogsVsCats.py
@@ -155,15 +169,19 @@ which can be obtained by index.
155169
:start-after: """Read Dataset / get label"""
156170
:end-before: """"""
157171

158-
There is only one label type in "Dogs vs Cats" dataset, which is ``classification``. The information stored in :ref:`reference/label_format/CommonLabelProperties:category` is
159-
one of the names in "categories" list of :ref:`catalog.json <dogsvscats-catalog>`.
172+
There is only one label type in "Dogs Vs Cats" dataset, which is ``classification``.
173+
174+
The information stored in :ref:`reference/label_format/CommonLabelProperties:category` is
175+
one of the names in "categories" list of :ref:`catalog.json <DogsVsCats-catalog>`. The information stored
176+
in :ref:`reference/label_format/CommonLabelProperties:attributes` is one or several of the attributes in "attributes" list of :ref:`catalog.json <DogsVsCats-catalog>`.
160177
See :ref:`reference/label_format/Classification:Classification` label format for more details.
161178

179+
162180
****************
163181
Delete Dataset
164182
****************
165183

166184
.. literalinclude:: ../../../../docs/code/DogsVsCats.py
167185
:language: python
168186
:start-after: """Delete Dataset"""
169-
:end-before: """"""
187+
:end-before: """"""

0 commit comments

Comments
 (0)