def single_segment_as_gif(segment, directory="/tmp/online_matcher/visuals/animated/", frames=60, black_and_white=False): import os if not os.path.exists(directory): os.makedirs(directory) import voxelize rotations = voxelize.create_rotations([voxelize.recenter_segment(segment)], n_angles=frames) segments_as_gif(rotations, filename='segment', directory=directory, black_and_white=black_and_white)
def single_segment_rotations_reconstruction_as_gif(segment, vae, confidence=0.3, directory="/tmp/online_matcher/visuals/animated/", frames=120, black_and_white=False): import os if not os.path.exists(directory): os.makedirs(directory) import voxelize rotations = voxelize.create_rotations([segment], n_angles=frames) import autoencoder.model VOXEL_SIDE = vae.MP.INPUT_SHAPE[0] rotations_vox, features_voxel_scale = voxelize.voxelize(rotations, VOXEL_SIDE) reconstruction_vox = vae.batch_encode_decode([np.reshape(sample, vae.MP.INPUT_SHAPE) for sample in rotations_vox], batch_size=120) reconstruction_vox = [np.reshape(vox, [VOXEL_SIDE, VOXEL_SIDE, VOXEL_SIDE]) for vox in reconstruction_vox] from voxelize import unvoxelize reconstruction = [unvoxelize(vox > confidence) for vox in reconstruction_vox] reconstruction = [voxelize.recenter_segment(segment*scale) for (segment, scale) in zip(reconstruction, features_voxel_scale)] segments_as_gif(reconstruction, rotate_YP=(2*np.pi/frames), filename='reconstruction_rot', directory=directory, black_and_white=black_and_white)
def single_segment_degeneration_as_gif( segment, vae, confidence=0.3, directory="/tmp/online_matcher/visuals/animated/", frames=60, black_and_white=False): import os if not os.path.exists(directory): os.makedirs(directory) import voxelize import autoencoder.model VOXEL_SIDE = vae.MP.INPUT_SHAPE[0] segment_vox, features_voxel_scale = voxelize.voxelize([segment], VOXEL_SIDE) segment_vox = [ np.reshape(sample, vae.MP.INPUT_SHAPE) for sample in segment_vox ] for i in range(frames): reconstruction_vox = vae.batch_encode_decode( reconstruction_vox) if i > 0 else segment_vox degen_vox = degen_vox + list(reconstruction_vox) if i > 0 else list( reconstruction_vox) degen_vox = [ np.reshape(vox, [VOXEL_SIDE, VOXEL_SIDE, VOXEL_SIDE]) for vox in degen_vox ] from voxelize import unvoxelize reconstruction = [unvoxelize(vox > confidence) for vox in degen_vox] reconstruction = [ voxelize.recenter_segment(segment * features_voxel_scale[0]) for segment in reconstruction ] print(len(reconstruction)) segments_as_gif(reconstruction, rotate_YP=0, filename='degeneration', directory=directory, black_and_white=black_and_white)
def single_segment_degeneration_as_gif(segment, vae, confidence=0.3, directory="/tmp/online_matcher/visuals/animated/", frames=60, black_and_white=False): import os if not os.path.exists(directory): os.makedirs(directory) import voxelize import autoencoder.model VOXEL_SIDE = vae.MP.INPUT_SHAPE[0] segment_vox, features_voxel_scale = voxelize.voxelize([segment], VOXEL_SIDE) segment_vox = [np.reshape(sample, vae.MP.INPUT_SHAPE) for sample in segment_vox] for i in range(frames): reconstruction_vox = vae.batch_encode_decode(reconstruction_vox) if i > 0 else segment_vox degen_vox = degen_vox + list(reconstruction_vox) if i > 0 else list(reconstruction_vox) degen_vox = [np.reshape(vox, [VOXEL_SIDE, VOXEL_SIDE, VOXEL_SIDE]) for vox in degen_vox] from voxelize import unvoxelize reconstruction = [unvoxelize(vox > confidence) for vox in degen_vox] reconstruction = [voxelize.recenter_segment(segment*features_voxel_scale[0]) for segment in reconstruction] print(len(reconstruction)) segments_as_gif(reconstruction, rotate_YP=0, filename='degeneration', directory=directory, black_and_white=black_and_white)