From c6725fed9eca3a7b769ac17c9becb401db3bc282 Mon Sep 17 00:00:00 2001 From: Jirka Borovec Date: Wed, 3 Feb 2021 00:43:45 +0100 Subject: [PATCH] fix docs (#58) * fix links * test * setup --- docs/source/conf.py | 8 ++++++++ docs/source/custom_task.rst | 6 +++--- docs/source/installation.md | 6 ++---- docs/source/quickstart.rst | 6 ++++-- docs/source/reference/image_classification.rst | 4 +++- docs/source/reference/image_embedder.rst | 10 +++++----- docs/source/reference/tabular_classification.rst | 4 +--- 7 files changed, 26 insertions(+), 18 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index 17eb378b2e..38be684626 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -147,3 +147,11 @@ def _package_list_from_file(pfile): MOCK_PACKAGES = [PACKAGE_MAPPING.get(pkg, pkg) for pkg in MOCK_PACKAGES] autodoc_mock_imports = MOCK_PACKAGES + +# only run doctests marked with a ".. doctest::" directive +doctest_test_doctest_blocks = '' +doctest_global_setup = """ +import torch +import pytorch_lightning as pl +import flash +""" diff --git a/docs/source/custom_task.rst b/docs/source/custom_task.rst index 9d0c846f5d..539df81a83 100644 --- a/docs/source/custom_task.rst +++ b/docs/source/custom_task.rst @@ -4,7 +4,7 @@ Tutorial: Creating a Custom Task In this tutorial we will go over the process of creating a custom task, along with a custom data module. -.. code:: python +.. testcode:: python import flash @@ -21,7 +21,7 @@ Here we create a basic linear regression task by subclassing ``flash.Task``. For the majority of tasks, you will likely only need to override the ``__init__`` and ``forward`` methods. -.. code:: python +.. testcode:: class LinearRegression(flash.Task): def __init__(self, num_inputs, learning_rate=0.001, metrics=None): @@ -67,7 +67,7 @@ for the prediction of diabetes disease progression. We can create this ``DataModule`` below, wrapping the scikit-learn `Diabetes dataset `__. -.. code:: python +.. testcode:: class DiabetesPipeline(flash.core.data.TaskDataPipeline): def after_uncollate(self, samples): diff --git a/docs/source/installation.md b/docs/source/installation.md index 11a5c6d673..7d770a6baf 100644 --- a/docs/source/installation.md +++ b/docs/source/installation.md @@ -5,13 +5,11 @@ Flash is tested on Python 3.6+, and PyTorch 1.6 ## Install with pip/conda ```bash -pip install lightning-flash +pip install lightning-flash -U ``` ## Install from source ``` bash -git clone https://github.com/PyTorchLightning/flash.git -cd flash -pip install -e . +pip install git+https://github.com/PyTorchLightning/lightning-flash.git ``` diff --git a/docs/source/quickstart.rst b/docs/source/quickstart.rst index 4e8a2ccda0..f4ca9b29b4 100644 --- a/docs/source/quickstart.rst +++ b/docs/source/quickstart.rst @@ -45,7 +45,9 @@ organized PyTorch with the unecessary engineering details abstracted away. When you need more flexibility you can build your own tasks or simply use Lightning directly. -.. note:: Read :doc:`here ` to understand when to use Flash vs Lightning. +.. tip:: + + Read :doc:`here ` to understand when to use Flash vs Lightning. ---- @@ -56,7 +58,7 @@ You can install flash using pip or conda: .. code-block:: bash - pip install pytorch-lightning-flash -U -pre + pip install pytorch-lightning-flash -U ------ diff --git a/docs/source/reference/image_classification.rst b/docs/source/reference/image_classification.rst index b1ca065c15..e939856363 100644 --- a/docs/source/reference/image_classification.rst +++ b/docs/source/reference/image_classification.rst @@ -124,7 +124,9 @@ Changing the backbone ********************* By default, we use a `ResNet-18 `_ for image classification. You can change the model run by the task by passing in a different backbone. -.. note:: When changing the backbone, make sure you pass in the same backbone to the Task and the Data object! +.. note:: + + When changing the backbone, make sure you pass in the same backbone to the Task and the Data object! .. code-block:: python diff --git a/docs/source/reference/image_embedder.rst b/docs/source/reference/image_embedder.rst index de40b1807b..16fdb8fa7f 100644 --- a/docs/source/reference/image_embedder.rst +++ b/docs/source/reference/image_embedder.rst @@ -36,11 +36,11 @@ Or on a random image tensor .. code-block:: python - # 2. Perform inference on an image file - import torch - images = torch.rand(32, 3, 224, 224) - embeddings = model.predict(images) - print(predictions) + # 2. Perform inference on an image file + import torch + images = torch.rand(32, 3, 224, 224) + embeddings = model.predict(images) + print(predictions) For more advanced inference options, see :ref:`predictions`. diff --git a/docs/source/reference/tabular_classification.rst b/docs/source/reference/tabular_classification.rst index 4dd7aaee67..770e62e7af 100644 --- a/docs/source/reference/tabular_classification.rst +++ b/docs/source/reference/tabular_classification.rst @@ -39,12 +39,10 @@ We can create :class:`~flash.tabular.TabularData` from csv files using the :func * **numerical_input**- a list of the names of columns that contain numerical continuous data (floats) * **target**- the name of the column we want to predict -.. tip:: you can pass in val_size and test_size to partition your training data into a separate validation and test set like so: - Next, we create the :class:`~flash.tabular.TabularClassifier` task, using the Data module we created. -.. code-block:: +.. code-block:: python import flash from flash import download_data