Skip to content
Snippets Groups Projects
Commit ea21ae51 authored by Maciej Wielgosz's avatar Maciej Wielgosz
Browse files

seeded semantic segm.

parent 24acf38d
No related branches found
No related tags found
No related merge requests found
#!/bin/bash
TARGET_FOLDER=/home/nibio/mutable-outside-world/code/gitlab_fsct/instance_segmentation_classic/maciek
# clean the folder
rm -rf $TARGET_FOLDER/*
cp /home/nibio/mutable-outside-world/data/austrian_example_stefano/p2_instance.las $TARGET_FOLDER
......@@ -2,5 +2,4 @@
SOURCE_FOLDER=/home/nibio/mutable-outside-world/code/gitlab_fsct/instance_segmentation_classic/sample_playground
rm -rf $SOURCE_FOLDER/*
cp /home/nibio/mutable-outside-world/code/gitlab_fsct/instance_segmentation_classic/playground_data/* \
/home/nibio/mutable-outside-world/code/gitlab_fsct/instance_segmentation_classic/sample_playground
\ No newline at end of file
cp /home/nibio/mutable-outside-world/code/gitlab_fsct/instance_segmentation_classic/playground_data/* $SOURCE_FOLDER
\ No newline at end of file
#!/bin/bash
TARGET_FOLDER=/home/nibio/mutable-outside-world/code/gitlab_fsct/instance_segmentation_classic/maciek
# clean the folder
rm -rf $TARGET_FOLDER/*
cp /home/nibio/mutable-outside-world/data/terestial_data_for_training_sem_seg_model/test/plot73_tile_-25_-25.las $TARGET_FOLDER
#!/bin/bash
TARGET_FOLDER=/home/nibio/mutable-outside-world/code/gitlab_fsct/instance_segmentation_classic/maciek
# clean the folder
rm -rf $TARGET_FOLDER/*
cp -r /home/nibio/mutable-outside-world/data/terestial_data_for_training_sem_seg_model/validation_after_seg/* $TARGET_FOLDER
......@@ -3,6 +3,8 @@ from scipy import optimize
from scipy.spatial.transform import Rotation
from scipy.stats import variation
import numpy as np
np.random.seed(0)
from matplotlib.patches import Circle
import matplotlib.pyplot as plt
......
......@@ -3,6 +3,7 @@ import time
import shutil
import sys
import glob
import pickle
import pandas as pd
import numpy as np
......@@ -71,23 +72,36 @@ def SemanticSegmentation(params):
with torch.no_grad():
output_point_cloud = np.zeros((0, 3 + 4))
output_list = []
# out_list = []
counter = 0
for data in tqdm(test_loader, disable=False if params.verbose else True):
data = data.to(params.device)
out = model(data)
# out_list.append(out.cpu().numpy())
out = out.permute(2, 1, 0).squeeze()
batches = np.unique(data.batch.cpu())
out = torch.softmax(out.cpu().detach(), axis=1)
pos = data.pos.cpu()
output = np.hstack((pos, out))
counter += 1
for batch in batches:
outputb = np.asarray(output[data.batch.cpu() == batch])
outputb[:, :3] = outputb[:, :3] + np.asarray(data.local_shift.cpu())[3 * batch:3 + (3 * batch)]
output_list.append(outputb)
# break
# save intermediate out_list to npy with a filename what contains the counter
# pickle.dump(out_list, open(os.path.join(params.odir, 'out_list_{}.pkl'.format(counter)), 'wb'))
classified_pc = np.vstack(output_list)
# sage classified as a pickle
pickle.dump(classified_pc, open(os.path.join(params.odir, 'classified_pc.pkl'), 'wb'))
# save classified point cloud to npy
# np.save(os.path.join(params.working_dir, 'classified_pc.npy'), classified_pc)
# clean up anything no longer needed to free RAM.
del outputb, out, batches, pos, output
......
......@@ -17,6 +17,10 @@ from matplotlib.lines import Line2D
from matplotlib.animation import FuncAnimation
from torch.optim.lr_scheduler import ExponentialLR
from helpers.seed_everything import seed_everything
seed_everything(42)
class SAModule(torch.nn.Module):
def __init__(self, ratio, r, NN):
......
import os
import numpy as np
np.random.seed(0)
import fsct
# Don't change these unless you really understand what you are doing with them/are learning the code base.
......
......@@ -9,6 +9,8 @@ from tqdm import tqdm
from fsct.tools import *
from helpers.seed_everything import seed_everything
def save_pts(params, I, bx, by, bz):
pc = params.pc.loc[(params.pc.x.between(bx, bx + params.box_dims[0])) &
......@@ -18,6 +20,7 @@ def save_pts(params, I, bx, by, bz):
if len(pc) > params.min_points_per_box:
if len(pc) > params.max_points_per_box:
print('Warning: box contains more points than max_points_per_box. Downsampling...')
pc = pc.sample(n=params.max_points_per_box)
np.save(os.path.join(params.working_dir, f'{I:07}'), pc[['x', 'y', 'z']].values)
......@@ -113,6 +116,9 @@ def Preprocessing(params):
for x in threads:
x.join()
# for i, (bx, by, bz) in tqdm(enumerate(itertools.product(x_cnr, y_cnr, z_cnr))):
# save_pts(params, i, bx, by, bz)
if params.verbose: print("Preprocessing done in {} seconds\n".format(time.time() - start_time))
return params
......@@ -3,6 +3,8 @@ import os
import argparse
import pickle
from helpers.seed_everything import seed_everything
# from fsct.run_tools import FSCT
from fsct.other_parameters import other_parameters
from fsct.tools import dict2class
......@@ -10,6 +12,8 @@ from fsct.preprocessing import Preprocessing
from fsct.inference import SemanticSegmentation
from fsct.segmentation import Segmentation
seed_everything(42)
if __name__ == '__main__':
parser = argparse.ArgumentParser()
......
......@@ -58,6 +58,6 @@ if __name__ == "__main__":
# Comparing the hashes
if file1_hash == file2_hash:
print("Files are identical")
print("identical")
else:
print("Files are different")
print("different")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment