Skip to content

Instantly share code, notes, and snippets.

@Mason-McGough
Last active June 25, 2021 17:42
Show Gist options
  • Save Mason-McGough/386fcbab33e794c62548b91e7440d1b5 to your computer and use it in GitHub Desktop.
Save Mason-McGough/386fcbab33e794c62548b91e7440d1b5 to your computer and use it in GitHub Desktop.
GIRAFFE - rendering.py
# adapted from https://github.com/autonomousvision/giraffe (MIT License)
class Renderer(object):
# ...
def render_full_visualization(self, img_out_path,
render_program=['object_rotation']):
for rp in render_program:
# ...
# APPEND THIS TO THE END OF render_full_visualization
if rp == 'object_wipeout':
self.set_random_seed()
self.render_object_wipeout(img_out_path)
# ...
# APPEND THIS TO THE END OF rendering.py
def render_object_wipeout(self, img_out_path, batch_size=15,
n_steps=32):
gen = self.generator
# Get values
latent_codes = gen.get_latent_codes(batch_size, tmp=self.sample_tmp)
bg_rotation = gen.get_random_bg_rotation(batch_size)
camera_matrices = gen.get_camera(batch_size=batch_size)
n_boxes = gen.bounding_box_generator.n_boxes
s = [[0., 0., 0.]
for i in range(n_boxes)]
n_steps = int(n_steps * 2)
r_scale = [0., 1.]
if n_boxes == 1:
t = []
x_val = 0.5
elif n_boxes == 2:
t = [[0.5, 0.5, 0.]]
x_val = 1.0
out = []
for step in range(n_steps):
# translation
i = step * 1.0 / (n_steps - 1)
ti = t + [[0.1, i, 0.]]
# rotation
r = [step * 1.0 / (n_steps - 1) for i in range(n_boxes)]
r = [r_scale[0] + ri * (r_scale[1] - r_scale[0]) for ri in r]
transformations = gen.get_transformations(s, ti, r, batch_size)
with torch.no_grad():
out_i = gen(batch_size, latent_codes, camera_matrices,
transformations, bg_rotation, mode='val')
out.append(out_i.cpu())
out = torch.stack(out)
out_folder = join(img_out_path, 'object_wipeout')
makedirs(out_folder, exist_ok=True)
self.save_video_and_images(
out, out_folder, name='object_wipeout',
add_reverse=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment