Closed fredcool7 closed 4 years ago
The output voxel is saved as .h5 file. You can use the following code to extract and visualize saved voxels:
with h5py.File(save_path, 'r') as fp:
voxel = fp['voxel'][:]
def vis_voxel(voxel, save_image=False):
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.voxels(voxel, facecolors='b', edgecolors='k') # this can be slow
plt.show()
vis_voxel(voxel)
Thank you so much !!!
I try to visualize part-awared voxels and I make it with the following code.
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import Axes3D # noqa: F401 unused import
from matplotlib.colors import LightSource
import seaborn as sns
def visualize_ndvoxel(voxel, filename=None):
"""
:param voxel:like (64,64,64) ndarray
:return:
"""
from mpl_toolkits.mplot3d import axes3d
voxel = np.squeeze(voxel)
if len(voxel.shape) == 4:
voxel = voxel[0]
color_num = voxel.max()
current_palette = sns.color_palette(as_cmap=True)
colors = np.empty(voxel.shape, dtype=object)
for i in range(color_num):
colors[voxel == i + 1] = current_palette[i]
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.set_axis_off()
ax.voxels(voxel, facecolors=colors, lightsource=LightSource(azdeg=315, altdeg=45))
# ax.set(xlabel='x', ylabel='y', zlabel='z')
if filename:
plt.savefig(fname=filename)
else:
plt.show()
one example result shows here.
Great work! Can you tell me how to visualize the .h5 file, at the path proj_log/pqnet-PartNet-Lamp/results, after the end of the program, please.