Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mpelchat04 committed Nov 2, 2021
1 parent 752dbbc commit b37f61b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
21 changes: 1 addition & 20 deletions airborne_lidar/airborne_lidar_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from collections import OrderedDict
from airborne_lidar_seg import get_model, nearest_correspondance, count_parameters, class_mode
import laspy
from airborne_lidar_utils import write_features, read_parameters, gpu_stats
from airborne_lidar_utils import write_features, read_parameters, gpu_stats, write_to_las
from airborne_lidar_datasets import PartDatasetTest


Expand Down Expand Up @@ -70,25 +70,6 @@ def write_las_to_h5(filename):
return filename.parent / filename.stem


def write_to_las(filename, xyz, pred, header, info_class):
"""Write xyz and ASPRS predictions to las file format. """
# TODO: Write CRS info with file.
with laspy.file.File(filename, mode='w', header=header) as out_file:
out_file.x = xyz[:, 0]
out_file.y = xyz[:, 1]
out_file.z = xyz[:, 2]
pred = pred_to_asprs(pred, info_class)
out_file.classification = pred


def pred_to_asprs(pred, info_class):
"""Converts predicted values (0->n) to the corresponding ASPRS class."""
labels2 = np.full(shape=pred.shape, fill_value=0, dtype=int)
for key, value in info_class.items():
labels2[pred == value['mode']] = int(key)
return labels2


def test(args, filename, info_class):
model_folder = Path(args['global']['model_dir'])
data_dir = Path(args['global']['data_dir'])
Expand Down
20 changes: 20 additions & 0 deletions airborne_lidar/airborne_lidar_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import shutil
import warnings
import numpy as np
import laspy

try:
from pynvml import *
Expand Down Expand Up @@ -99,3 +100,22 @@ def wblue(str):

def wgreen(str):
return bcolors.OKGREEN + str + bcolors.ENDC


def write_to_las(filename, xyz, pred, header, info_class):
"""Write xyz and ASPRS predictions to las file format. """
# TODO: Write CRS info with file.
with laspy.file.File(filename, mode='w', header=header) as out_file:
out_file.x = xyz[:, 0]
out_file.y = xyz[:, 1]
out_file.z = xyz[:, 2]
pred = pred_to_asprs(pred, info_class)
out_file.classification = pred


def pred_to_asprs(pred, info_class):
"""Converts predicted values (0->n) to the corresponding ASPRS class."""
labels2 = np.full(shape=pred.shape, fill_value=0, dtype=int)
for key, value in info_class.items():
labels2[pred == value['mode']] = int(key)
return labels2
2 changes: 1 addition & 1 deletion airborne_lidar/prepare_airborne_lidar_label.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def main():
path_prepare_label = Path(args.dest, dst)
path_prepare_label.mkdir(exist_ok=True)

xyzni, label, nb_pts = read_las_format(f"{elem}.las")
xyzni, label, nb_pts, header = read_las_format(f"{elem}.las")
write_features(Path(f"{path_prepare_label / Path(elem).stem}_prepared.hdfs"), xyzni=xyzni, labels=label)
print(f"File {dst}/{Path(elem).stem} prepared. {nb_pts:,} points written.")

Expand Down

0 comments on commit b37f61b

Please sign in to comment.