|
15 | 15 | # documentation root, use os.path.abspath to make it absolute, like shown here. |
16 | 16 | # |
17 | 17 | """Configuration file for the Sphinx documentation builder.""" |
| 18 | +import os |
18 | 19 | import sys |
19 | 20 | from pathlib import Path |
20 | 21 |
|
21 | 22 | sys.path.insert(0, str(Path(__file__).parents[2])) |
22 | | - |
| 23 | +from docs.source._templates.examples import ( # noqa: E402 # pylint: disable=wrong-import-position |
| 24 | + EXAMPLES_TEMPLATE, |
| 25 | +) |
23 | 26 |
|
24 | 27 | # -- Project information ----------------------------------------------------- |
25 | 28 |
|
|
79 | 82 | # relative to this directory. They are copied after the builtin static files, |
80 | 83 | # so a file named "default.css" will overwrite the builtin "default.css". |
81 | 84 | # 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 | +dataset_names = ( |
| 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 | + |
| 106 | +dataset_with_images = ("BSTLD", "Neolix OD", "Leeds Sports Pose") |
| 107 | + |
| 108 | +figure_description = """(:numref:`Fig. %s <example-{file_name}>`). |
| 109 | +
|
| 110 | +.. _example-{file_name}: |
| 111 | +
|
| 112 | +.. figure:: ../../images/example-{label_type}.png |
| 113 | + :scale: 50 % |
| 114 | + :align: center |
| 115 | +
|
| 116 | + The preview of a cropped image with labels from "{dataset_name}". |
| 117 | +""" |
| 118 | + |
| 119 | +category_attribute_descriptions = {} |
| 120 | +category_attribute_descriptions[ |
| 121 | + "BSTLD" |
| 122 | +] = """ |
| 123 | +The only annotation type for "{dataset_name}" is |
| 124 | +:ref:`reference/label_format/{label_type}:{label_type}`, and there are 13 |
| 125 | +:ref:`reference/label_format/CommonLabelProperties:category` types and one |
| 126 | +:ref:`reference/label_format/CommonLabelProperties:attributes` type. |
| 127 | +""" |
| 128 | + |
| 129 | +category_attribute_descriptions[ |
| 130 | + "Dogs Vs Cats" |
| 131 | +] = """ |
| 132 | +The only annotation type for "{dataset_name}" is |
| 133 | +:ref:`reference/label_format/{label_type}:{label_type}`, and there are 2 |
| 134 | +:ref:`reference/label_format/CommonLabelProperties:category` types. |
| 135 | +""" |
| 136 | + |
| 137 | +category_attribute_descriptions[ |
| 138 | + "Leeds Sports Pose" |
| 139 | +] = """ |
| 140 | +The only annotation type for "{dataset_name}" is |
| 141 | +:ref:`reference/label_format/{label_type}:{label_type}`. |
| 142 | +""" |
| 143 | + |
| 144 | +category_attribute_descriptions[ |
| 145 | + "Neolix OD" |
| 146 | +] = """ |
| 147 | +The only annotation type for "{dataset_name}" is |
| 148 | +:ref:`reference/label_format/{label_type}:{label_type}`, and there are 15 |
| 149 | +:ref:`reference/label_format/CommonLabelProperties:category` types and 3 |
| 150 | +:ref:`reference/label_format/CommonLabelProperties:attributes` type. |
| 151 | +""" |
| 152 | + |
| 153 | +category_attribute_descriptions[ |
| 154 | + "20 Newsgroups" |
| 155 | +] = """ |
| 156 | +The only annotation type for "{dataset_name}" is |
| 157 | +:ref:`reference/label_format/{label_type}:{label_type}`, and there are 20 |
| 158 | +:ref:`reference/label_format/CommonLabelProperties:category` types |
| 159 | +""" |
| 160 | + |
| 161 | +category_attribute_descriptions["THCHS-30"] = "" |
| 162 | + |
| 163 | +# from docs.source._templates.examples import EXAMPLES_TEMPLATE |
| 164 | +for dataset_name, label_type, file_name in zip(dataset_names, label_types, file_names): |
| 165 | + if dataset_name == "THCHS-30": |
| 166 | + catalog_description = """However the catalog of THCHS-30 is too large, instead of |
| 167 | +reading it from json file, we read it by mapping from subcatalog that is loaded by |
| 168 | +the raw file. Check the :ref:`dataloader <THCHS30-dataloader>` below for more details. |
| 169 | +""" |
| 170 | + information_description = """It contains ``sentence``, ``spell`` and ``phone`` information. |
| 171 | +See :ref:`Sentence <reference/label_format/{label_type}:{label_type}>` label format for |
| 172 | +more details. |
| 173 | +""" |
| 174 | + else: |
| 175 | + catalog_description = """ |
| 176 | +.. literalinclude:: ../../../../tensorbay/opendataset/{file_name}/catalog.json |
| 177 | + :language: json |
| 178 | + :name: {file_name}-catalog |
| 179 | + :linenos: |
| 180 | +""" |
| 181 | + information_description = """The information stored in |
| 182 | +:ref:`reference/label_format/CommonLabelProperties:category` is one of the names in "categories" |
| 183 | +list of :ref:`catalog.json <{file_name}-catalog>`. The information stored in |
| 184 | +:ref:`reference/label_format/CommonLabelProperties:attributes` is one or several of |
| 185 | +the attributes in "attributes" list of :ref:`catalog.json <{file_name}-catalog>`. |
| 186 | +See :ref:`reference/label_format/{label_type}:{label_type}` label format for more details. |
| 187 | +""" |
| 188 | + |
| 189 | + if dataset_name in dataset_with_images: |
| 190 | + figure_description_tmp = figure_description.format( |
| 191 | + dataset_name=dataset_name, file_name=file_name, label_type=label_type |
| 192 | + ) |
| 193 | + else: |
| 194 | + figure_description_tmp = "" |
| 195 | + catalog_description_tmp = catalog_description.format(file_name=file_name) |
| 196 | + information_description_tmp = information_description.format( |
| 197 | + label_type=label_type, file_name=file_name |
| 198 | + ) |
| 199 | + category_attribute_description = category_attribute_descriptions[dataset_name].format( |
| 200 | + dataset_name=dataset_name, label_type=label_type |
| 201 | + ) |
| 202 | + with open(os.path.join(example_path, f"{file_name}.rst"), "w", encoding="utf-8") as fp: |
| 203 | + fp.write( |
| 204 | + EXAMPLES_TEMPLATE.format( |
| 205 | + dataset_name=dataset_name, |
| 206 | + file_name=file_name, |
| 207 | + label_type=label_type, |
| 208 | + figure_description=figure_description_tmp, |
| 209 | + catalog_description=catalog_description_tmp, |
| 210 | + category_attribute_description=category_attribute_description, |
| 211 | + information_description=information_description_tmp, |
| 212 | + ) |
| 213 | + ) |
0 commit comments