Skip to content

Commit

Permalink
[Feature] Estimate mview sperson dataset in filesystem (openxrlab#123)
Browse files Browse the repository at this point in the history
1. Add `HummanSMCDataCovnerter`, converting SMCs to dataset in filesystem.
2. Add a tool `run_mview_sperson_estimator`, running estimation on the files above. Also this tool addresses the requirements mentioned in the [issue-118](openxrlab#118).
3. Add datautils for better logger.
  • Loading branch information
LazyBusyYang authored Jun 12, 2023
1 parent 4039369 commit 8b4931d
Show file tree
Hide file tree
Showing 10 changed files with 718 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
type = 'HummanSMCDataCovnerter'
data_root = 'xrmocap_data/humman_dataset'
bbox_detector = None
kps2d_estimator = None
batch_size = 1000
view_idxs = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
meta_path = 'xrmocap_data/humman_dataset/xrmocap_meta'
visualize = False
80 changes: 80 additions & 0 deletions docs/en/tools/run_mview_sperson_estimator.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
## Tool run_mview_sperson_estimator


- [Overview](#overview)
- [Argument: estimator_config](#argument-estimator_config)
- [Argument: output_dir](#argument-output_dir)
- [Argument: disable_log_file](#argument-disable_log_file)
- [Argument: visualize](#argument-visualize)
- [Example](#example)

### Overview

If you don't want to write code to call the `MultiViewSinglePersonSMPLEstimator` yourself, it's okay. We provide [this tool](../../../tools/run_mview_sperson_estimator.py) that can be run under a specific directory structure. Before using this tool, you need to organize the files required by the estimator according to the rules below.

```
your_dataset_root
└── xrmocap_meta
├── dataset_name.txt
├── scene_0
│   ├── camera_parameters
│   │   ├── fisheye_param_00.json
│   │   ├── fisheye_param_01.json
│   │   └── ...
│   ├── image_list_view_00.txt
│   ├── image_list_view_01.txt
│   ├── ...
│   ├── images_view_00
│   │   ├── 000000.jpg
│   │   ├── 000001.jpg
│   │   └── ...
│   ├── images_view_01
│   │   └── ...
│   └── ...
└── scene_1
   └── ...
```
`fisheye_param_{view_idx}.json` is a json file for XRPrimer FisheyeCameraParameter, please refer to [XRPrimer docs](https://github.com/openxrlab/xrprimer/blob/main/docs/en/data_structure/camera.md) for details.
`image_list_view_{view_idx}.txt` is a list of image paths relative to your dataset root, here's an example.
```
xrmocap_meta/scene_0/images_view_00/000000.jpg
xrmocap_meta/scene_0/images_view_00/000001.jpg
...
```

### Argument: estimator_config

`estimator_config` is the path to a `MultiViewSinglePersonSMPLEstimator` config file. For more details, see docs for `MultiViewSinglePersonSMPLEstimator` and the docstring in [code](../../../xrmocap/estimation/mview_sperson_smpl_estimator.py).

Also, you can find our prepared config files at `config/estimation/mview_sperson_smpl_estimator.py`.

### Argument: data_root

`data_root` is the path to the root directory of dataset. In the file tree example given above, `data_root` should point to `your_dataset_root`.

### Argument: meta_path

`meta_path` is the path to the meta data directory. In the file tree example given above, `meta_path` should point to `xrmocap_meta`.

### Argument: output_dir

`output_dir` is the path to the directory saving all possible output files, including multi-view keypoints2d, keypoints3d, SMPLData and visualization videos.

### Argument: disable_log_file

By default, disable_log_file is False and a log file named `{tool_name}_{time_str}.txt` will be written. Add `--disable_log_file` makes it True and the tool will only print log to console.

### Argument: visualize

By default, visualize is False. Add `--visualize` makes it True and the tool will visualize keypoints3d with an orbit camera, overlay projected keypoints3d on some views, and overlay SMPL meshes on one view.

### Example

Run the tool with visualization.

```bash
python tools/mview_sperson_estimator.py \
--data_root xrmocap_data/humman_dataset \
--meta_path xrmocap_data/humman_dataset/xrmocap_meta \
--visualize
```
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ multi_line_output = 5
include_trailing_comma = true
known_standard_library = pkg_resources,setuptools
known_first_party = xrmocap
known_third_party =PIL,cv2,filterpy,matplotlib,mmcv,mmhuman3d,numpy,prettytable,pytest,pytorch3d,scipy,smplx,sphinx_rtd_theme,torch,torchvision,tqdm,xrprimer
known_third_party =PIL,cv2,dateutil,filterpy,matplotlib,mmcv,mmhuman3d,numpy,prettytable,pytest,pytorch3d,scipy,smplx,sphinx_rtd_theme,torch,torchvision,tqdm,xrprimer
no_lines_before = STDLIB,LOCALFOLDER
default_section = THIRDPARTY
19 changes: 11 additions & 8 deletions tools/prepare_dataset.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# yapf: disable
import argparse
import datetime
import logging
import mmcv
import os
Expand All @@ -9,6 +8,7 @@
from xrprimer.utils.path_utils import Existence, check_path_existence

from xrmocap.data.data_converter.builder import build_data_converter
from xrmocap.utils.date_utils import get_datetime_local, get_str_from_datetime

# yapf: enable

Expand All @@ -17,15 +17,18 @@ def main(args):
converter_config = dict(mmcv.Config.fromfile(args.converter_config))
if check_path_existence('logs', 'dir') == Existence.DirectoryNotExist:
os.mkdir('logs')
filename = os.path.basename(__file__).split('.')[0]
if not args.disable_log_file:
time_str = datetime.datetime.now().strftime('%Y-%m-%d_%H:%M:%S')
log_path = os.path.join('logs', f'converter_log_{time_str}.txt')
datetime = get_datetime_local()
time_str = get_str_from_datetime(datetime)
log_path = os.path.join('logs', f'{filename}_{time_str}.txt')
logger = setup_logger(
logger_name=__name__,
logger_name=filename,
logger_path=log_path,
logger_level=logging.DEBUG)
file_level=logging.DEBUG,
console_level=logging.INFO)
else:
logger = setup_logger(logger_name=__name__)
logger = setup_logger(logger_name=filename)
if len(args.data_root) > 0 and len(args.meta_path) > 0:
logger.info('Taking paths from sys.argv.')
converter_config['data_root'] = args.data_root
Expand All @@ -41,8 +44,8 @@ def main(args):
data_converter = build_data_converter(converter_config)
data_converter.run(overwrite=args.overwrite)
if not args.disable_log_file:
shutil.move(
log_path,
shutil.copy(
src=log_path,
dst=os.path.join(converter_config['meta_path'],
f'converter_log_{time_str}.txt'))

Expand Down
18 changes: 12 additions & 6 deletions tools/process_smc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# yapf: disable
import argparse
import datetime
import glob
import mmcv
import numpy as np
Expand All @@ -11,7 +10,7 @@
visualize_smpl_calibration,
)
from xrprimer.utils.ffmpeg_utils import array_to_images
from xrprimer.utils.log_utils import setup_logger
from xrprimer.utils.log_utils import logging, setup_logger
from xrprimer.utils.path_utils import (
Existence, check_path_existence, prepare_output_path,
)
Expand All @@ -21,11 +20,13 @@
from xrmocap.data_structure.smc_reader import SMCReader
from xrmocap.io.camera import get_all_color_kinect_parameter_from_smc
from xrmocap.transform.image.color import rgb2bgr
from xrmocap.utils.date_utils import get_datetime_local, get_str_from_datetime

# yapf: enable


def main(args):
filename = os.path.basename(__file__).split('.')[0]
# check output path
exist_result = check_path_existence(args.output_dir, 'dir')
if exist_result == Existence.MissingParent:
Expand All @@ -35,11 +36,16 @@ def main(args):
file_name = args.smc_path.rsplit('/', 1)[-1]
smc_name = file_name.rsplit('.', 1)[0]
if not args.disable_log_file:
time_str = datetime.datetime.now().strftime('%Y.%m.%d_%H:%M:%S')
log_path = os.path.join(args.output_dir, f'{smc_name}_{time_str}.txt')
logger = setup_logger(logger_name=__name__, logger_path=log_path)
datetime = get_datetime_local()
time_str = get_str_from_datetime(datetime)
log_path = os.path.join('logs', f'{filename}_{time_str}.txt')
logger = setup_logger(
logger_name=filename,
logger_path=log_path,
file_level=logging.DEBUG,
console_level=logging.INFO)
else:
logger = setup_logger(logger_name=__name__)
logger = setup_logger(logger_name=filename)
# check input path
exist_result = check_path_existence(args.smc_path, 'file')
if exist_result != Existence.FileExist:
Expand Down
Loading

0 comments on commit 8b4931d

Please sign in to comment.