Skip to content

Commit

Permalink
Enhance the documentation. (#374)
Browse files Browse the repository at this point in the history
* refact: refact doc theme

* refact: resolve `html_static_path` warning

* fix: myst-parser warning

* fix: NVIDIA naming

* refact: C++ installation doc

* fix: training setup

* refact: refine yixiao's doc [training.install]

* fix: ONNX link

* fix: typo tl -> tf

* refact: refine wording. thx Luo

* refact: pin doc utility versions

* fix: markdown style

* refact: quick_start/prediction doc

* refact: update logo in config

* feat: auto glob tensorflow GraphDef input/output nodes

* refact: doc - quick-start

* refact: figure in docs -> center
  • Loading branch information
ganler authored Jun 30, 2021
1 parent 9858573 commit a90d286
Show file tree
Hide file tree
Showing 17 changed files with 431 additions and 262 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ We demonstrate how to train a custom pose estimation model with HyperPose. Hyper
from hyperpose import Config, Model, Dataset

# Set model name to distinguish models (necessary)
Config.set_model_name("My_lopps")
Config.set_model_name("MyLightweightOpenPose")

# Set model type, model backbone and dataset
Config.set_model_type(Config.MODEL.LightweightOpenpose)
Expand Down
18 changes: 12 additions & 6 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
#
import os
import sys

dir_path = os.path.dirname(os.path.realpath(__file__))
sys.path.insert(0, os.path.abspath('../'))
sys.path.insert(0, os.path.abspath('../Hyperpose'))
sys.path.insert(0, os.path.abspath('../hyperpose'))

# -- Project information -----------------------------------------------------

Expand All @@ -32,10 +33,15 @@
'sphinx.ext.todo',
'sphinx.ext.githubpages',
'sphinx_markdown_tables',
'recommonmark',
'numpydoc'
'myst_parser',
'numpydoc',
]

myst_enable_extensions = ["colon_fence"]
pygments_style = "sphinx"
pygments_dark_style = "monokai"
html_logo = "markdown/images/logo.png"

autodoc_mock_imports = [
'gridfs',
'horovod',
Expand All @@ -52,6 +58,7 @@
'tensorflow',
'tqdm',
'h5py',
'tensorlayer',

'tensorlayer.third_party.roi_pooling.roi_pooling.roi_pooling_ops',
]
Expand All @@ -73,13 +80,12 @@

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'sphinx_rtd_theme'
html_theme = 'furo'

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = []

master_doc = 'index'

Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Welcome to HyperPose's Documentation!
=====================================

Installation
-----------
------------
.. toctree::
:maxdepth: 1

Expand Down
Binary file added docs/markdown/images/data_vis_dir.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/markdown/images/train_vis_dir.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 19 additions & 13 deletions docs/markdown/install/prediction.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Note that C++ prediction library requires NVIDIA GPU acceleration.
HyperPose is developed and frequently tested on Linux platforms (i.e., Ubuntu 18.04). Hence, we recommend you to build HyperPose on Linux.

## Docker Environment Installation (RECOMMENDED)
## Container Installation (RECOMMENDED)

To ease the installation, you can use HyperPose library in our docker image where the environment is pre-installed (including pretrained models).

Expand All @@ -15,13 +15,13 @@ To test your docker environment compatibility and get related instructions:
wget https://raw.githubusercontent.com/tensorlayer/hyperpose/master/scripts/test_docker.py -qO- | python
```

- [CUDA Driver >= 418.81.07 (bounded by NVidia Docker)](https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#driver-installation)
- [NVidia Docker >= 2.0](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html#pre-requisites)
- [CUDA Driver >= 418.81.07 (bounded by NVIDIA Docker)](https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#driver-installation)
- [NVIDIA Docker >= 2.0](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html#pre-requisites)
- [Docker >= 19.03](https://docs.docker.com/engine/install/)

### Official Docker Image

NVidia docker support is required to execute our docker image.
NVIDIA docker support is required to execute our docker image.

The official image is on [DockerHub](https://hub.docker.com/r/tensorlayer/hyperpose).

Expand Down Expand Up @@ -55,19 +55,25 @@ docker run --rm --gpus all $(USER_DEF_NAME)
* Third-Party
* OpenCV3.2+. (**[OpenCV 4+](https://docs.opencv.org/trunk/d7/d9f/tutorial_linux_install.html) is highly recommended**)
* CUDA related:
* (suggested) [CUDA 10.2](https://developer.nvidia.com/cuda-downloads), [CuDNN 7.6.5](https://docs.nvidia.com/deeplearning/cudnn/install-guide/index.html), [TensorRT 7.1](https://docs.nvidia.com/deeplearning/tensorrt/install-guide/index.html).
* (suggested) [CUDA 10.2](https://developer.nvidia.com/cuda-downloads), [CuDNN 8.2.0](https://docs.nvidia.com/deeplearning/cudnn/install-guide/index.html), [TensorRT >= 7.1, <= 8.0](https://docs.nvidia.com/deeplearning/tensorrt/install-guide/index.html).
* (minimal) [CUDA 10.0](https://developer.nvidia.com/cuda-downloads), [CuDNN 7.6.5](https://docs.nvidia.com/deeplearning/cudnn/install-guide/index.html), [TensorRT 7.0](https://docs.nvidia.com/deeplearning/tensorrt/install-guide/index.html).
* gFlags (for command-line tool/examples/tests)

> Packages of other versions might also work but not tested.
```{admonition} Note
Packages of other versions might also work but not tested.
```

```{admonition} TensorRT Tips
For Linux users, you are highly recommended to install it in a system-wide setting. You can install TensorRT7 via the [debian distributions](https://docs.nvidia.com/deeplearning/tensorrt/install-guide/index.html#installing-debian) or [NVIDIA network repo ](https://docs.nvidia.com/deeplearning/tensorrt/install-guide/index.html#maclearn-net-repo-install)(CUDA and CuDNN dependency will be automatically installed).
```

> **About TensorRT installation**
>
> - For Linux users, you are highly recommended to install it in a system-wide setting. You can install TensorRT7 via the [debian distributions](https://docs.nvidia.com/deeplearning/tensorrt/install-guide/index.html#installing-debian) or [NVIDIA network repo ](https://docs.nvidia.com/deeplearning/tensorrt/install-guide/index.html#maclearn-net-repo-install)(CUDA and CuDNN dependency will be automatically installed).
> - Different TensorRT version requires specific CUDA and CuDNN version. For specific CUDA and CuDNN requirements of TensorRT7, please refer to [this](https://docs.nvidia.com/deeplearning/tensorrt/support-matrix/index.html#platform-matrix).
> - Also, for Ubuntu 18.04 users, this [3rd party blog](https://ddkang.github.io/2020/01/02/installing-tensorrt.html) may help you.
```{admonition} CUDA-CuDNN-TensorRT Compatibility
:class: warning
Different TensorRT version requires specific CUDA and CuDNN version. For specific CUDA and CuDNN requirements of TensorRT7, please refer to [this](https://docs.nvidia.com/deeplearning/tensorrt/support-matrix/index.html#platform-matrix).
```

### Build On Ubuntu 18.04
### Build on Ubuntu 18.04

```bash
# >>> Install OpenCV3+ and other dependencies.
Expand Down Expand Up @@ -102,4 +108,4 @@ cmake --build .

- **Step 3**: Execute your codes!

Go to [Quick Start](../quick_start/prediction.md) to test your installation.
Go to [Quick Start](../quick_start/prediction.md) to test your installation.
175 changes: 104 additions & 71 deletions docs/markdown/install/training.md
Original file line number Diff line number Diff line change
@@ -1,116 +1,149 @@
# Python Training Library Installation

## Prerequisites
* [Anaconda3](https://www.anaconda.com/products/individual):<br>
Anaconda is used to create virtual environment that facilitates building the running environment and ease the complexity of library depedencies. Here we mainly use it to create virtual python environment and install cuda run-time libraries.
* [CUDA](https://developer.nvidia.com/cuda-downloads):<br>
CUDA enviroment is essential to run deep learning neural networks on GPUs. The CUDA installation packages to download should match your system and your NVIDIA Driver version.
## Configure CUDA environment

## Configure environment
&emsp;There are two ways to install hyperpose python training library.
You can configure your CUDA either by Anaconda or your system setting.

&emsp;All the following instructions have been tested on the environments below:<br>
| OS | NVIDIA Driver | CUDA Toolkit | GPU |
| ------------ | ------------- | ------------ | -------------- |
| Ubuntu 18.04 | 410.79 | 10.0 | Tesla V100-DGX |
| Ubuntu 18.04 | 440.33.01 | 10.2 | Tesla V100-DGX |
| Ubuntu 18.04 | 430.64 | 10.1 | TITAN RTX |
| Ubuntu 18.04 | 430.26 | 10.2 | TITAN XP |
| Ubuntu 16.04 | 430.50 | 10.1 | RTX 2080Ti |
### Using CUDA toolkits from Anaconda (RECOMMENDED)

:::{admonition} Prerequisites
- [Anaconda3](https://www.anaconda.com/products/individual)
- [NVidia Driver >= 410.79 (required by CUDA 10)](https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#driver-installation)
:::

It is suggested to create new conda environment regarding the CUDA requirements.

&emsp;Before all, we recommend you to create anaconda virtual environment first, which could handle the possible conflicts between the libraries you already have in your computers and the libraries hyperpose need to install, and also handle the dependencies of the cudatoolkit and cudnn library in a very simple way.<br>
&emsp;To create the virtual environment, run the following command in bash:
```bash
# >>> create virtual environment (choose yes)
conda create -n hyperpose python=3.7
# >>> create virtual environment
conda create -n hyperpose python=3.7 -y
# >>> activate the virtual environment, start installation
conda activate hyperpose
# >>> install cudatoolkit and cudnn library using conda
conda install cudatoolkit=10.0.130
conda install cudnn=7.6.0
```

::::{warning}
It is also possible to install CUDA dependencies without creating a new environment.
But it might introduce environment conflicts.

:::{code-block} bash
conda install cudatoolkit=10.0.130
conda install cudnn=7.6.0
:::
::::


### Using system-wide CUDA toolkits

Users may also directly depend on the system-wide CUDA and CuDNN libraries.

HyperPose have been tested on the environments below:

| OS | NVIDIA Driver | CUDA Toolkit | GPU |
| ------------ | ------------- | ------------ | -------------- |
| Ubuntu 18.04 | 410.79 | 10.0 | Tesla V100-DGX |
| Ubuntu 18.04 | 440.33.01 | 10.2 | Tesla V100-DGX |
| Ubuntu 18.04 | 430.64 | 10.1 | TITAN RTX |
| Ubuntu 18.04 | 430.26 | 10.2 | TITAN XP |
| Ubuntu 16.04 | 430.50 | 10.1 | RTX 2080Ti |

::::{admonition} Check CUDA/CuDNN versions

&emsp;After configuring and activating conda enviroment, we can then begin to install the hyperpose.<br>
To test CUDA version, run `nvcc --version`: the highlight line in the output indicates that you have CUDA 11.2 installed.
:::{code-block} bash
:emphasize-lines: 5
nvcc --version
# ========== Valid output looks like ==========
# nvcc: NVIDIA (R) Cuda compiler driver
# Copyright (c) 2005-2020 NVIDIA Corporation
# Built on Mon_Nov_30_19:08:53_PST_2020
# Cuda compilation tools, release 11.2, V11.2.67
# Build cuda_11.2.r11.2/compiler.29373293_0
:::

### (I)The first method to install is to put hyperpose python module in the working directory.(recommand)<br>
&emsp;After git-cloning the source [repository](https://github.com/tensorlayer/hyperpose.git), you can directly import hyperpose python library under the root directory of the cloned repository.<br>
To check your system-wide CuDNN version **on Linux**: the output (in the comment) shows that we have CuDNN 8.0.5.
:::{code-block} bash
ls /usr/local/cuda/lib64 | grep libcudnn.so
# === Valid output looks like ===
# libcudnn.so
# libcudnn.so.8
# libcudnn.so.8.0.5
:::
::::

&emsp;To make importion available, you should install the prerequist dependencies as followed:<br>
&emsp;you can either install according to the requirements.txt in the [repository](https://github.com/tensorlayer/hyperpose.git)
## Install HyperPose Python training library

### Install with `pip`

To install a stable library from [Python Package Index](https://github.com/tensorlayer/hyperpose):

```bash
# install according to the requirements.txt
pip install -r requirements.txt
pip install -U hyperpose
```

&emsp;or install libraries one by one
Or you can install a specific release of hyperpose from GitHub, for example:

```bash
# >>> install tensorflow of version 2.3.1
pip install tensorflow-gpu==2.3.1
# >>> install tensorlayer of version 2.2.3
pip install tensorlayer==2.2.3
# >>> install other requirements (numpy<=17.0.0 because it has conflicts with pycocotools)
pip install opencv-python
pip install numpy==1.16.4
pip install pycocotools
pip install matplotlib
export HYPERPOSE_VERSION="2.2.0-alpha"
pip install -U https://github.com/tensorlayer/hyperpose/archive/${HYPERPOSE_VERSION}.zip
```

&emsp;This method of installation use the latest source code and thus is less likely to meet compatibility problems.<br><br>
More GitHub releases and its version can be found [here](https://github.com/tensorlayer/hyperpose/releases).

### (II)The second method to install is to use pypi repositories.<br>
&emsp;We have already upload hyperpose python library to pypi website so you can install it using pip, which gives you the last stable version.
### Local installation

You can also install HyperPose by installing the raw GitHub repository, this is usually for developers.

```bash
pip install hyperpose
# Install the source codes from GitHub
git clone https://github.com/tensorlayer/hyperpose.git
pip install -U -r hyperpose/requirements.txt

# Add `hyperpose/hyperpose` to `PYTHONPATH` to help python find it.
export HYPERPOSE_PYTHON_HOME=$(pwd)/hyperpose
export PYTHONPATH=$HYPERPOSE_PYTHON_HOME/python:${PYTHONPATH}
```

&emsp;This will download and install all dependencies automatically.
## Check the installation

Let's check whether HyperPose is installed by running following commands:

&emsp;Now after installing dependent libraries and hyperpose itself, let's check whether the installation successes.
run following command in bash:
```bash
# >>> now the configuration is done, check whether the GPU is avaliable.
python
>>> import tensorflow as tf
>>> import tensorlayer as tl
>>> tf.test.is_gpu_available()
# >>> if the output is True, congratulation! you can import and run hyperpose now
>>> from hyperpose import Config,Model,Dataset
python -c '
import tensorflow as tf # Test TensorFlow installation
import tensorlayer as tl # Test TensorLayer installation
assert tf.test.is_gpu_available() # Test GPU availability
import hyperpose # Test HyperPose import
'
```

## Extra configuration for exporting model
&emsp;The hypeprose python training library handles the whole pipelines for developing the pose estimation system, including training, evaluating and testing. Its goal is to produce a **.npz** file that contains the well-trained model weights.
## Optional Setup

### Extra configurations for exporting models

&emsp;For the training platform, the enviroment configuration above is engough. However, most inference engine only accept .pb format or .onnx format model, such as [TensorRT](https://docs.nvidia.com/deeplearning/tensorrt/install-guide/index.html).
The hypeprose python training library handles the whole pipelines for developing the pose estimation system, including training, evaluating and testing. Its goal is to produce a **.npz** file that contains the well-trained model weights.

&emsp;Thus, one need to convert the trained model loaded with **.npz** file weight to **.pb** format or **.onnx** format for further deployment, which need extra configuration below:<br>
For the training platform, the enviroment configuration above is engough. However, most inference engine accepts ProtoBuf or [ONNX](https://onnx.ai/) format model. For example, the HyperPose C++ inference engine leverages [TensorRT](https://docs.nvidia.com/deeplearning/tensorrt/install-guide/index.html) as the DNN engine, which takes ONNX models as inputs.

### (I)Convert to .pb format:<br>
&emsp;To convert the model into .pb format, we use *@tf.function* to decorate the *infer* function of each model class, so we can use the *get_concrete_function* function from tensorflow to consctruct the frozen model computation graph and then save it in .pb format.
Thus, one need to convert the trained model loaded with **.npz** file weight to **.pb** format or **.onnx** format for further deployment, which need extra configuration below:

&emsp;We already provide a script with cli to facilitate conversion, which located at [export_pb.py](https://github.com/tensorlayer/hyperpose/blob/master/export_pb.py). What we need here is only *tensorflow* library that we already installed.
#### Converting a ProtoBuf model

### (II)Convert to .onnx format:<br>
&emsp;To convert the model in .onnx format, we need to first convert the model into .pb format, then convert it from .pb format into .onnx format. Two extra library are needed:
To convert the model into ProtoBuf format, we use `@tf.function` to decorate the `infer` function for each model class, and we then can use the `get_concrete_function` function from tensorflow to consctruct the frozen model computation graph and then save it with ProtoBuf format.

* [tf2onnx](https://github.com/onnx/tensorflow-onnx):<br>
*tf2onnx* is used to convert .pb format model into .onnx format model. more information see [here](https://github.com/onnx/tensorflow-onnx).<br>
install tf2onnx by running:
We provide [a commandline tool](https://github.com/tensorlayer/hyperpose/blob/master/export_pb.py) to facilitate the conversion. The prerequisite of this tool is a tensorflow library installed along with HyperPose's dependency.

```bash
pip install -U tf2onnx
```
#### Converting a ONNX model

* [graph_transforms](https://github.com/tensorflow/tensorflow/tree/master/tensorflow/tools/graph_transforms#using-the-graph-transform-tool):<br>
*graph_transform* is used to check the input and output node of the .pb file if one doesn't know. when convert .pb file into .onnx file using tf2onnx, one is required to provide the input node name and output node name of the computation graph stored in .pb file, so he may need to use *graph_transform* to inspect the .pb file to get node names.<br>
build graph_transforms according to [tensorflow tools](https://github.com/tensorflow/tensorflow/tree/master/tensorflow/tools/graph_transforms#using-the-graph-transform-tool).
To convert a trained model into ONNX format, we need to first convert the model into ProtoBuf format, we then convert a ProtoBuf model into ONNX format, which requires an additional library: [**tf2onnx**](https://github.com/onnx/tensorflow-onnx) for converting TensorFlow's ProtoBuf model into ONNX format.

## Extra configuration for parallel training
&emsp;The hyperpose python training library use the High performance distributed machine learning framework **Kungfu** for parallel training.<br>
&emsp;Thus to use the parallel training functionality of hyperpose, please install [Kungfu](https://github.com/lsds/KungFu) according to the official instructon it provides.
To install `tf2onnx`, we simply run:

```bash
pip install -U tf2onnx
```

### Extra configuration for distributed training with KungFu

The HyperPose python training library can also perform distributed training with [Kungfu](https://github.com/lsds/KungFu). To enable parallel training, please install [Kungfu](https://github.com/lsds/KungFu) according to its official instructon.
2 changes: 1 addition & 1 deletion docs/markdown/performance/supports.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@

### Released Prediction Models

We released the models on [Google Drive](TinyVGG-V1-HW=256x384.uff). `.onnx` and `.uff` files are for inference.
We released the models on [Google Drive](https://drive.google.com/drive/folders/1w9EjMkrjxOmMw3Rf6fXXkiv_ge7M99jR?usp=sharing). `.onnx` and `.uff` files are for inference.
Loading

0 comments on commit a90d286

Please sign in to comment.