ChrisWu1997 / PQ-NET

code for our CVPR 2020 paper "PQ-NET: A Generative Part Seq2Seq Network for 3D Shapes"
MIT License
118 stars 18 forks source link

Visualizing h5 files #7

Closed fredcool7 closed 4 years ago

fredcool7 commented 4 years ago

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.

ChrisWu1997 commented 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)
fredcool7 commented 4 years ago

Thank you so much !!!

tianyilt commented 3 years ago

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. 0018