In order to use the pywhu3d tool, you need to install the pwhu3d library for your interpreter. We recommend you use python=3.7 to follow this tutorial.
# this will install the latest version of pywhu3d
pip install pywhu3d
Create a WHU3D object:
xfrom pywhu3d.tool import WHU3D
data_root = '/data/datasets/whu'
scenes = ['0404', '0940']
# whu3d = WHU3D(data_root=data_root, data_type='mls', format='txt')
whu3d = WHU3D(data_root=data_root, data_type='mls', format='h5', scenes=scenes)
Parameters:
data_root: [data root folder]
data_type: als
, mls
, pc
, img
format: txt
, ply
, npy
, h5
, pickle
[optional] scenes: a list of scenes, if not specified, will be represented by all of the files
The structure of the data folder should be like this:
xxxxxxxxxx
data_root
├── images
├── als
│ ├── h5
│ │ ├── [scene_1].h5
│ │ ├── [scene_2].h5
│ │ └── [scene_*].h5
│ └── [optional] pkl/npy/pth
└── mls
├── h5
│ ├── [scene_1].h5
│ ├── [scene_2].h5
│ └── [scene_*].h5
└── [optional] pkl/npy/pth
It is also recommended to use default split scenes to create a whu3d object, by using whu3d.train_split
.
xxxxxxxxxx
# print(whu3d.split.val)
whu3d = WHU3D(data_root=data_root, data_type='mls', format='txt', scenes=whu3d.val_split)
Then some of the attributes could be directly accessed, including data_root, data_type, scenes, download_link
xxxxxxxxxx
# e.g., you could print current scenes
print(whu3d.scenes)
The attributes of whu3d may differ depending on your operations (e.g., after applying the compute_normals
function, the attributes may include normals
that may not exist before). Nonetheless, you could always use the list_attributes
function to see the current attributes that you could currently access.
xxxxxxxxxx
# this command will show you a table with all the attributes
# that you could currently use.
whu3d.list_attributes()
You could simply get a specific attribute of all scenes by using get_attribute
function.
xxxxxxxxxx
# this function will return a list of the attributes
attr = whu3d.get_attribute('coords')
You could access the data of a specific scene by using whu3d.data[scene][attribute]
.
xxxxxxxxxx
xyz = whu3d.data['0414']['coords']
Labels could also be directly accessed.
xxxxxxxxxx
semantics = whu3d.labels['0414']['semantics']
instances = whu3d.labels['0414']['instances']
If you have interpreted the labels by using interprete_labels
function, you could also get interpreted labels.
xxxxxxxxxx
semantics = whu3d.interpreted_labels['0414']['semantics']
instances = whu3d.interpreted_labels['0414']['instances']
You can visualize a specific scene or a list of scenes using the vis
function. By default, this function will show both the point cloud and image frames, and the points are randomly sampled with sample_ratio = 0.01 for faster visualization. It will show color according to the height of the point if color
is not specified, or you could choose a specific color, including intensity, normals, semantics, instances, and other features (some features should be computed first via whu3d functions if they do not exist, and you could use whu3d.list_attributes()
to see the current attributes first).
xxxxxxxxxx
# This will show sampled points and images
whu3d.vis(scene='0414', type='pc', color='intensity')
# Show all the points
whu3d.vis(scene='0414', sample_ratio=1.0, type='pc', color='intensity')
# if you want to show normals, please set 'show_normals' to True
whu3d.vis(scene='0414', type='pc', color='normals', show_normals=True)
or you can use a remote visualization function that allows you to visualize the scene on your local machine if the script is run on a remote server.
xxxxxxxxxx
# This function should be used if you want to visualize points
# and the script is run on a remote machine.
whu3d.remote_vis(scene='0424', type='pc', color='intensity')
Before running the remove_vis
function on your remote machine, you should start another ssh connection to your remote machine, and launch open3d on your local machine.
Similarly, you could use the vis
function to see a series of images of a specific scene.
xxxxxxxxxx
whu3d.vis(scene='0414', type='img')
[Will be available soon.]
[Will be available soon.]
If you want to visualize the labels of semantics or instances, you must run the interprete_labels
function first (please refer to the 'labels interpretation' section).
xxxxxxxxxx
# you should run this function first to interpret the labels
info, labels = whu3d.interprete_labels()
# you could visualize semantics with specified colors
whu3d.vis(scene='0414', type='pc', color='semantics')
# or you could visualize instances with random colors
whu3d.vis(scene='0414', type='pc', color='instances')
Note that all the export
functions will export data to self.data_path
by default and you should better not change it if you want to load it later via pywhu3d.
You could export other formats of whu3d, including las, ply, numpy, pickle, h5py, image, et al, by just using the export_[type]
function.
xxxxxxxxxx
scenes = ['0404', '0940']
whu3d.export_h5(output='.')
whu3d.export_images(output='.', scenes=scenes)
# this will export las to the '[self.data_path]/las' folder if
# output is not specified, you can also specify 'scenes'
whu3d.export_las()
If scenes
is not specified, it will export all the scenes by default.
export_labels
function could export raw labels or interpreted labels.
xxxxxxxxxx
# this will export '[scene].labels' files to your 'output' folder
whu3d.export_labels(output='./labels', scenes=scenes)
# whu3d.export_labels()
You could also export detailed statistics of the data and label to excel by using the export_statistics
function.
xxxxxxxxxx
whu3d.export_statistics(output='./whu3d_statistics.xlsx')
For the export of metrics, you could refer to the 'Evaluation' part.
You could use the export
function to export a specified type of data.
xxxxxxxxxx
whu3d.export(output='', attribute='interpreted_labels')
You could use the interprete_labels
function to merge similar categories and remap the labels to consecutive numbers like 0, 1, 2, ...
xxxxxxxxxx
# this will interpret the labels and create the 'gt' attribute
whu3d.interprete_labels()
After applying this function, you could access the interpreted labels by using whu3d.gt
. For more information, you could use the get_label_map
function to see the interpretation table.
xxxxxxxxxx
# this will output a table showing the detailed information
# this only shows you the information of semantics
whu3d.get_label_map()
If you want to divide the whole scene into rectangle blocks along XY plane, you could use save_divided_blocks
function. This function will directly save the divided blocks into .h5
file.
xxxxxxxxxx
# this will divide the scene into 10m * 10m blocks with 5m overlap$
whu3d.save_divided_blocks(out_dir='', num_points=4096, size=(10, 10), stride=5, threshold=100, show_points=False)
If you could use your own file to interpret the labels, you should follow the steps:
Step1: Create label_interpretion.json
. This file should include
xxxxxxxxxx
{
"sem_no_list_ins": "2, 3, 7",
"sem_label_mapping": [
{"175": "2"},
{"18": "5"}
]
}
sem_no_list_ins
exclude the categories which should be not interpreted as instances;
sem_label_mapping
specifies the mapping rules of semantic labels.
Step 2: Put the JSON file into the data root folder.
Step 3: Perform the interprete_labels
function.
The interpretation of predicted results should be consistent with that of the interpreted labels.
Or you could use the evaluation tool as in the 'instance segmentation evaluation' section, just by replacing the instance results with semantics.
For instance segmentation evaluation, you should use our evaluation.Evaluator
tool.
xxxxxxxxxx
# define an evaluator for evaluation
# preds is a list with num_scenes items, each item is a 2D
# array with shape (num_points, 2)
# there are two ways to create an evaluator
# first way
evaluator = whu3d.create_evaluator(preds)
# second way
from pywhu3d.evluation import Evaluator
evaluator = Evaluator(whu3d, preds)
# then you could use evaluator functions
evaluator.compute_metrics()
You could get metrics, including:
instance metrics: MUCov, MWCov, Pre, Rec, F1-score
semantic metrics: oAcc, mAcc, mIoU
xxxxxxxxxx
print(evaluator.info)
print(evaluator.eval_list)
print(evaluator.eval_table)
You could also export evaluation results.
xxxxxxxxxx
# this will export an Excel file with detailed metrics
evaluator.export(output_dir='./')
You can also use the whu3d tool to customize your own dataset for all pywhu3d features simply by using the format
function.
xxxxxxxxxx
data_root = '/data/datasets/you_custom_dataset'
scenes = ['scene1', 'scene2']
whu3d = WHU3D(data_root=data_root, data_type='mls', format='txt', scenes=scenes)
# this will format your data as whu3d format
# 'attributes' should be consistent with your input data
in_attributes = ['coords', 'semantics', 'instances', 'intensities']
whu3d.format(attributes=in_attributes)
After applying the format
function, you could use all the features the whu3d tool provides just as the whu3d-dataset.
This is a demo for preprocessing MLS dataset.
xxxxxxxxxx
from pywhu3d.tool import WHU3D
data_root = 'data/whu-dataset'
mls_scenes = ['0404', '0940']
# als_scenes = ['5033', '3922']
# whu3d = WHU3D(data_root=data_root, data_type='mls', format='txt')
whu3d = WHU3D(data_root=data_root, data_type='mls', format='h5', scenes=mls_scenes)
whu3d.norm_coords()
# self.compute_normals()
whu3d.interprete_labels()
whu3d.compute_normals(radius=0.8)
whu3d.save_divided_blocks(out_dir='', num_points=60000, size=(20, 20), stride=10, threshold=100, show_points=False)
© 2023 WHU3D. All rights reserved.pywhu3d
is a tool to manage the whu3d dataset, with limited ability to process the dataset (e.g., segmentation). But if you need more features for processing the outdoor scene dataset, you could refer to [well soon be available]. For more details about our dataset, please refer to our website. Contact Xu Han (hanxuwhu[at]whu[dot]edu[dot]com or hanxu@whu3d.com) if you have any questions.