File size: 5,438 Bytes
152f0f2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# Visualization
- [Single Image](#single-image)
- [Browse Dataset](#browse-dataset)
- [Visualizer Hook](#visualizer-hook)
## Single Image
`demo/image_demo.py` helps the user to visualize the prediction result of a single image, including the skeleton and heatmaps.
```shell
python demo/image_demo.py ${IMG} ${CONFIG} ${CHECKPOINT} [-h] [--out-file OUT_FILE] [--device DEVICE] [--draw-heatmap]
```
| ARGS | Description |
| --------------------- | -------------------------------- |
| `IMG` | The path to the test image. |
| `CONFIG` | The path to the config file. |
| `CHECKPOINT` | The path to the checkpoint file. |
| `--out-file OUT_FILE` | Path to output file. |
| `--device DEVICE` | Device used for inference. |
| `--draw-heatmap` | Visualize the predicted heatmap. |
Here is an example of Heatmap visualization:

## Browse Dataset
`tools/analysis_tools/browse_dataset.py` helps the user to browse a pose dataset visually, or save the image to a designated directory.
```shell
python tools/misc/browse_dataset.py ${CONFIG} [-h] [--output-dir ${OUTPUT_DIR}] [--not-show] [--phase ${PHASE}] [--mode ${MODE}] [--show-interval ${SHOW_INTERVAL}]
```
| ARGS | Description |
| -------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
| `CONFIG` | The path to the config file. |
| `--output-dir OUTPUT_DIR` | The target folder to save visualization results. If not specified, the visualization results will not be saved. |
| `--not-show` | Do not show the visualization results in an external window. |
| `--phase {train, val, test}` | Options for dataset. |
| `--mode {original, transformed}` | Specify the type of visualized images. `original` means to show images without pre-processing; `transformed` means to show images are pre-processed. |
| `--show-interval SHOW_INTERVAL` | Time interval between visualizing two images. |
For instance, users who want to visualize images and annotations in COCO dataset use:
```shell
python tools/misc/browse_dataset.py configs/body_2d_keypoint/topdown_heatmap/coco/td-hm_hrnet-w32_8xb64-e210_coco-256x192.py --mode original
```
The bounding boxes and keypoints will be plotted on the original image. Following is an example:

The original images need to be processed before being fed into models. To visualize pre-processed images and annotations, users need to modify the argument `mode` to `transformed`. For example:
```shell
python tools/misc/browse_dataset.py configs/body_2d_keypoint/topdown_heatmap/coco/td-hm_hrnet-w32_8xb64-e210_coco-256x192.py --mode transformed
```
Here is a processed sample

The heatmap target will be visualized together if it is generated in the pipeline.
## Visualizer Hook
During validation and testing, users can specify certain arguments to visualize the output of trained models.
To visualize in external window during testing:
```shell
python tools/test.py ${CONFIG} ${CHECKPOINT} --show
```
During validation:
```shell
python tools/train.py ${CONFIG} --work-dir ${WORK_DIR} --show --interval ${INTERVAL}
```
It is suggested to use large `INTERVAL` (e.g., 50) if users want to visualize during validation, since the wait time for each visualized instance will make the validation process very slow.
To save visualization results in `SHOW_DIR` during testing:
```shell
python tools/test.py ${CONFIG} ${CHECKPOINT} --show-dir=${SHOW_DIR}
```
During validation:
```shell
python tools/train.py ${CONFIG} --work-dir ${WORK_DIR} --show-dir=${SHOW_DIR}
```
More details about visualization arguments can be found in [train_and_test](./train_and_test.md).
If you use a heatmap-based method and want to visualize predicted heatmaps, you can manually specify `output_heatmaps=True` for `model.test_cfg` in config file. Another way is to add `--cfg-options='model.test_cfg.output_heatmaps=True'` at the end of your command.
Visualization example (top: decoded keypoints; bottom: predicted heatmap):

For top-down models, each sample only contains one instance. So there will be multiple visualization results for each image.
|