Skip to content

Commit

Permalink
updated a better trained model; remove the redudant normalization in …
Browse files Browse the repository at this point in the history
…Mesh_dataset.py, step4, step5, and step6
  • Loading branch information
Tai-Hsien committed Dec 9, 2020
1 parent 5296b46 commit 5d97d72
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Mesh_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def __getitem__(self, idx):
normals[:,i] = (normals[:,i] - nmeans[i]) / nstds[i]

X = np.column_stack((cells, barycenters, normals))
X = (X-np.ones((X.shape[0], 1))*np.mean(X, axis=0)) / (np.ones((X.shape[0], 1))*np.std(X, axis=0))
#X = (X-np.ones((X.shape[0], 1))*np.mean(X, axis=0)) / (np.ones((X.shape[0], 1))*np.std(X, axis=0))
Y = labels

# initialize batch of input and label
Expand Down
Binary file not shown.
2 changes: 1 addition & 1 deletion step4_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
normals[:,i] = (normals[:,i] - nmeans[i]) / nstds[i]

X = np.column_stack((cells, barycenters, normals))
X = (X-np.ones((X.shape[0], 1))*np.mean(X, axis=0)) / (np.ones((X.shape[0], 1))*np.std(X, axis=0))
#X = (X-np.ones((X.shape[0], 1))*np.mean(X, axis=0)) / (np.ones((X.shape[0], 1))*np.std(X, axis=0))

# computing A_S and A_L
A_S = np.zeros([X.shape[0], X.shape[0]], dtype='float32')
Expand Down
21 changes: 14 additions & 7 deletions step5_predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import torch.nn as nn
from meshsegnet import *
import utils
from easy_mesh_vtk import *
from easy_mesh_vtk.easy_mesh_vtk import *
import pandas as pd
from losses_and_metrics_for_mesh import *
from scipy.spatial import distance_matrix
Expand All @@ -14,10 +14,11 @@
torch.cuda.set_device(utils.get_avail_gpu()) # assign which gpu will be used (only linux works)

model_path = './models'
model_name = 'Mesh_Segementation_MeshSegNet_15_classes_60samples_best.tar'
#model_name = 'Mesh_Segementation_MeshSegNet_15_classes_60samples_best.tar'
model_name = 'MeshSegNet_Max_15_classes_72samples_lr1e-2_best.tar'

mesh_path = '' # need to define
sample_filenames = ['Sample_0101_d.stl'] # need to define
mesh_path = 'inputs' # need to define
sample_filenames = ['Example_02.stl'] # need to define
output_path = './outputs'
if not os.path.exists(output_path):
os.mkdir(output_path)
Expand Down Expand Up @@ -45,9 +46,13 @@
for i_sample in sample_filenames:

print('Predicting Sample filename: {}'.format(i_sample))
# read image and label (annotation)
# pre-processing: downsampling
print('\tDownsampling...')
mesh = Easy_Mesh(os.path.join(mesh_path, i_sample))
predicted_labels = np.zeros([mesh.cells.shape[0], 1])
target_num = 10000
ratio = 1 - target_num/mesh.cells.shape[0] # calculate ratio
mesh.mesh_decimation(ratio)
predicted_labels = np.zeros([mesh.cells.shape[0], 1], dtype=np.int32)

# move mesh to origin
cell_centers = (mesh.cells[:, 0:3] + mesh.cells[:, 3:6] + mesh.cells[:, 6:9])/3.0
Expand Down Expand Up @@ -81,7 +86,7 @@
normals[:,i] = (normals[:,i] - nmeans[i]) / nstds[i]

X = np.column_stack((cells, barycenters, normals))
X = (X-np.ones((X.shape[0], 1))*np.mean(X, axis=0)) / (np.ones((X.shape[0], 1))*np.std(X, axis=0))
#X = (X-np.ones((X.shape[0], 1))*np.mean(X, axis=0)) / (np.ones((X.shape[0], 1))*np.std(X, axis=0))

# computing A_S and A_L
A_S = np.zeros([X.shape[0], X.shape[0]], dtype='float32')
Expand Down Expand Up @@ -110,6 +115,8 @@

# output predicted labels
mesh = Easy_Mesh(os.path.join(mesh_path, i_sample))
mesh.mesh_decimation(ratio)

mesh2 = Easy_Mesh()
mesh2.cells = mesh.cells
mesh2.update_cell_ids_and_points()
Expand Down
2 changes: 1 addition & 1 deletion step6_predict_with_post_processing_gco.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
normals[:,i] = (normals[:,i] - nmeans[i]) / nstds[i]

X = np.column_stack((cells, barycenters, normals))
X = (X-np.ones((X.shape[0], 1))*np.mean(X, axis=0)) / (np.ones((X.shape[0], 1))*np.std(X, axis=0))
#X = (X-np.ones((X.shape[0], 1))*np.mean(X, axis=0)) / (np.ones((X.shape[0], 1))*np.std(X, axis=0))

# computing A_S and A_L
A_S = np.zeros([X.shape[0], X.shape[0]], dtype='float32')
Expand Down
5 changes: 3 additions & 2 deletions step6_predict_with_post_processing_pygco.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@
#upsampling_method = 'KNN'

model_path = './models'
model_name = 'Mesh_Segementation_MeshSegNet_15_classes_60samples_best.tar'
#model_name = 'Mesh_Segementation_MeshSegNet_15_classes_60samples_best.tar'
model_name = 'MeshSegNet_Max_15_classes_72samples_lr1e-2_best.tar'

mesh_path = './inputs'
sample_filenames = ['upper_T0.stl'] # need to modify
sample_filenames = ['Example_02.stl'] # need to modify
output_path = './outputs'
if not os.path.exists(output_path):
os.mkdir(output_path)
Expand Down

0 comments on commit 5d97d72

Please sign in to comment.