示例#1
0
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)
示例#2
0
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)
示例#3
0
def single_segment_confidence_as_gif(
        segment,
        vae,
        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
    ]
    reconstruction_vox = vae.batch_encode_decode(segment_vox)
    reconstruction_vox = [
        np.reshape(vox, [VOXEL_SIDE, VOXEL_SIDE, VOXEL_SIDE])
        for vox in reconstruction_vox
    ]
    from voxelize import unvoxelize
    cmin = 0.1
    cmax = np.amax(reconstruction_vox)
    confidences = list(np.linspace(cmin, cmax, frames / 2)) + list(
        np.linspace(cmax, cmin, frames / 2))
    reconstruction = [
        unvoxelize(reconstruction_vox[0] > confidence)
        for confidence in confidences
    ]
    reconstruction = [
        segment * features_voxel_scale[0] for segment in reconstruction
    ]

    segments_as_gif(reconstruction,
                    rotate_YP=0,
                    filename='confidence',
                    directory=directory,
                    black_and_white=black_and_white)
示例#4
0
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)
示例#5
0
def single_segment_confidence_as_gif(segment, vae,
                                     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]
  reconstruction_vox = vae.batch_encode_decode(segment_vox)
  reconstruction_vox = [np.reshape(vox, [VOXEL_SIDE, VOXEL_SIDE, VOXEL_SIDE]) for vox in reconstruction_vox]
  from voxelize import unvoxelize
  cmin=0.1; cmax=np.amax(reconstruction_vox);
  confidences = list(np.linspace(cmin,cmax,frames/2))+list(np.linspace(cmax,cmin,frames/2))
  reconstruction = [unvoxelize(reconstruction_vox[0] > confidence) for confidence in confidences]
  reconstruction = [segment*features_voxel_scale[0] for segment in reconstruction]

  segments_as_gif(reconstruction, rotate_YP=0, filename='confidence',
                  directory=directory, black_and_white=black_and_white)
示例#6
0
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)
示例#7
0
        ###############
        PROFILING = True
        if PROFILING:
            from timeit import default_timer as timer
            total_start = timer()
            reconstr_start = timer()

        ## RECONSTRUCT SEGMENTS ##
        ##########################
        segments_vox = vae.batch_decode(ae_features)
        segments_vox = [
            np.reshape(vox, [voxel_side, voxel_side, voxel_side])
            for vox in segments_vox
        ]
        from voxelize import unvoxelize
        segments = [unvoxelize(vox > RC_CONFIDENCE) for vox in segments_vox]
        segments = [
            segment * scale for (segment, scale) in zip(segments, xyz_scales)
        ]

        if PROFILING:
            reconstr_end = timer()
            overhead_out_start = timer()

        print("__RCST_COMPLETE__")

        ## OUTPUT DATA TO FILES ##
        ##########################
        print("Writing segments")
        from import_export import write_segments
        write_segments(ids, segments, folder="", filename=segments_fifo_path)
示例#8
0
# Reconstructions
if not RUN_AS_PY_SCRIPT:
    N = 100
    SV_ = segments_vox[:N]
    S_ = segments[:N]
    I_ = ids[:N]
    reconstruction_vox = vae.batch_encode_decode(
        [np.reshape(sample, MP.INPUT_SHAPE) for sample in SV_])
    reconstruction_vox = [
        np.reshape(vox, [VOXEL_SIDE, VOXEL_SIDE, VOXEL_SIDE])
        for vox in reconstruction_vox
    ]
    from voxelize import unvoxelize
    reconstruction = [
        unvoxelize(vox > RC_CONFIDENCE) for vox in reconstruction_vox
    ]
    reconstruction = [
        segment * scale
        for (segment, scale) in zip(reconstruction, features_voxel_scale)
    ]
    if CREATE_VISUALS:
        dir_ = "/tmp/online_matcher/visuals/reconstructions/"
        from visuals import visuals_of_matches
        reconstruction_ids = [id_ + max(I_) + 1 for id_ in I_]
        one_to_one_matches = [[id1, id2]
                              for id1, id2 in zip(I_, reconstruction_ids)]
        visuals_of_matches(one_to_one_matches,
                           S_ + reconstruction,
                           I_ + reconstruction_ids,
                           directory=dir_,
示例#9
0
RC_CONFIDENCE = 0.2
ONEVIEW = True


# In[ ]:

# Reconstructions
if not RUN_AS_PY_SCRIPT:
  N = 400
  SV_ = segments_vox[:N]
  S_ = segments[:N]
  I_ = ids[:N]
  reconstruction_vox = vae.batch_encode_decode([np.reshape(sample, MP.INPUT_SHAPE) for sample in SV_])
  reconstruction_vox = [np.reshape(vox, [VOXEL_SIDE, VOXEL_SIDE, VOXEL_SIDE]) for vox in reconstruction_vox]
  from voxelize import unvoxelize
  reconstruction = [unvoxelize(vox > RC_CONFIDENCE) for vox in reconstruction_vox]
  reconstruction = [segment*scale for (segment, scale) in zip(reconstruction, features_voxel_scale)]             
  if CREATE_VISUALS:
    dir_ = "/tmp/online_matcher/visuals/reconstructions/"
    from visuals import visuals_of_matches
    reconstruction_ids = [id_+max(I_)+1 for id_ in I_]
    one_to_one_matches = [[id1, id2] for id1, id2 in zip(I_, reconstruction_ids)]
    visuals_of_matches(one_to_one_matches, S_+reconstruction, I_+reconstruction_ids, directory=dir_, oneview=ONEVIEW)
    clear_output()


# In[ ]:

# Reconstructions of rotations for one object
if CREATE_VISUALS:
  dir_ = "/tmp/online_matcher/visuals/rotations/"
RC_CONFIDENCE = 0.1
ONEVIEW = True


# In[ ]:

# Reconstructions
if not RUN_AS_PY_SCRIPT:
  N = 100
  SV_ = segments_vox[:N]
  S_ = segments[:N]
  I_ = ids[:N]
  reconstruction_vox = vae.batch_encode_decode([np.reshape(sample, MP.INPUT_SHAPE) for sample in SV_])
  reconstruction_vox = [np.reshape(vox, [VOXEL_SIDE, VOXEL_SIDE, VOXEL_SIDE]) for vox in reconstruction_vox]
  from voxelize import unvoxelize
  reconstruction = [unvoxelize(vox > RC_CONFIDENCE) for vox in reconstruction_vox]
  reconstruction = [segment*scale for (segment, scale) in zip(reconstruction, features_voxel_scale)]             
  if CREATE_VISUALS:
    dir_ = "/tmp/online_matcher/visuals/reconstructions/"
    from visuals import visuals_of_matches
    reconstruction_ids = [id_+max(I_)+1 for id_ in I_]
    one_to_one_matches = [[id1, id2] for id1, id2 in zip(I_, reconstruction_ids)]
    visuals_of_matches(one_to_one_matches, S_+reconstruction, I_+reconstruction_ids, directory=dir_, oneview=ONEVIEW)
    clear_output()


# In[ ]:

# Exploring influence of first dimension on generated segments
dim_ = 0
if CREATE_VISUALS:
    xyz_scales  = sc_features[:,3:]

    ## PROFILING ##
    ###############
    PROFILING = True
    if PROFILING:
        from timeit import default_timer as timer
        total_start = timer()
        reconstr_start = timer()

    ## RECONSTRUCT SEGMENTS ##
    ##########################
    segments_vox = vae.batch_decode(ae_features)
    segments_vox = [np.reshape(vox, [voxel_side, voxel_side, voxel_side]) for vox in segments_vox]
    from voxelize import unvoxelize, unalign
    segments = [unvoxelize(vox > RC_CONFIDENCE) for vox in segments_vox]
    segments = [segment*scale for (segment, scale) in zip(segments, xyz_scales)]
    segments = unalign(segments, al_features)

    if PROFILING:
        reconstr_end = timer()
        overhead_out_start = timer()

    print("__RCST_COMPLETE__")

    ## OUTPUT DATA TO FILES ##
    ##########################
    print("Writing segments")
    from import_export import write_segments
    write_segments(ids, segments, folder="", filename=segments_fifo_path)