Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
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)
Ejemplo n.º 3
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)
Ejemplo n.º 4
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)
Ejemplo n.º 5
0
    features_nn, confusion_nn = vae.batch_encode(
        [np.reshape(sample, MP.INPUT_SHAPE) for sample in segments_vox])
    fnames_nn = [
        'autoencoder_feature' + str(i + 1)
        for i, _ in enumerate(features_nn[0])
    ]
    F = features_nn
    C = classes

# In[ ]:

if not RUN_AS_PY_SCRIPT:
    print("Rotating segments")
    from voxelize import create_rotations
    rotated_segments, rotated_classes = create_rotations(segments,
                                                         N_ROTATION_ANGLES,
                                                         classes=classes)
    if False:  # walls_vs_cars
        print("Removing unknowns")
        rotated_segments = [
            segment
            for segment, class_ in zip(rotated_segments, rotated_classes)
            if class_ != "unknown"
        ]
        rotated_classes = [
            class_ for class_ in rotated_classes if class_ != "unknown"
        ]
    print("Voxelizing rotations")
    from voxelize import voxelize
    rotated_segments_vox, rotated_segments_scale = voxelize(
        rotated_segments, VOXEL_SIDE)
Ejemplo n.º 6
0
# ## Create Voxelized Segment Dataset - With Rotated Copies

# In[ ]:

## Split into training and val data
split_at = min(VAL_EXAMPLES, int(0.2 * len(ids)))
val = segments[:split_at]
train = segments[split_at:]


# In[ ]:

if not TRAIN_TWINS:
  print("Rotating segments")
  from voxelize import create_rotations
  train = create_rotations(train, N_ROTATION_ANGLES, ROTATION_OFFSET)
  val = create_rotations(val, 12, ROTATION_OFFSET)

  print("Voxelizing training data")
  from voxelize import voxelize
  train_vox, _ = voxelize(train,VOXEL_SIDE)
  val_vox, _   = voxelize(val  ,VOXEL_SIDE)
  train_twins_vox = None
  val_twins_vox   = None

  if train_vox[0].shape != MP.INPUT_SHAPE:
    print("Reshaping")
    train_vox=[np.reshape(vox, MP.INPUT_SHAPE) for vox in train_vox]
    val_vox=[np.reshape(vox, MP.INPUT_SHAPE) for vox in val_vox]

  del train # Save some memory
Ejemplo n.º 7
0
# In[ ]:

if not RUN_AS_PY_SCRIPT:
  print("Computing Features for Segments")
  features_nn, confusion_nn = vae.batch_encode([np.reshape(sample, MP.INPUT_SHAPE) for sample in segments_vox])
  fnames_nn = ['autoencoder_feature'+str(i+1) for i, _ in enumerate(features_nn[0])]
  F = features_nn
  C = classes


# In[ ]:

if not RUN_AS_PY_SCRIPT:
  print("Rotating segments")
  from voxelize import create_rotations
  rotated_segments, rotated_classes = create_rotations(segments, N_ROTATION_ANGLES, classes=classes)
  if False: # walls_vs_cars
    print("Removing unknowns")
    rotated_segments = [segment for segment, class_ in zip(rotated_segments, rotated_classes) if class_ != "unknown"]
    rotated_classes = [class_ for class_ in rotated_classes if class_ != "unknown"]
  print("Voxelizing rotations")
  from voxelize import voxelize
  rotated_segments_vox, rotated_segments_scale = voxelize(rotated_segments, VOXEL_SIDE)
  print("Computing Features for rotations")
  rotated_features, _ = vae.batch_encode([np.reshape(sample, MP.INPUT_SHAPE) for sample in rotated_segments_vox])
  F = rotated_features
  C = rotated_classes


# ## T-SNE