Guest User

Untitled

a guest
Feb 20th, 2019
939
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. rnd = np.random
  2. latents_a = rnd.randn(1, Gs.input_shape[1])
  3. latents_b = rnd.randn(1, Gs.input_shape[1])
  4. latents_c = rnd.randn(1, Gs.input_shape[1])
  5.  
  6. def circ_generator(latents_interpolate):
  7. radius = 40.0
  8.  
  9. latents_axis_x = (latents_a - latents_b).flatten() / la.norm(latents_a - latents_b)
  10. latents_axis_y = (latents_a - latents_c).flatten() / la.norm(latents_a - latents_c)
  11.  
  12. latents_x = math.sin(math.pi * 2.0 * latents_interpolate) * radius
  13. latents_y = math.cos(math.pi * 2.0 * latents_interpolate) * radius
  14.  
  15. latents = latents_a + latents_x * latents_axis_x + latents_y * latents_axis_y
  16. return latents
  17.  
  18. def mse(x, y):
  19. return (np.square(x - y)).mean()
  20.  
  21. def generate_from_generator_adaptive(gen_func):
  22. max_step = 1.0 / 64.0
  23. current_pos = 0.0
  24.  
  25. change_min = 10.0
  26. change_max = 11.0
  27.  
  28. fmt = dict(func=tflib.convert_images_to_uint8, nchw_to_nhwc=True)
  29.  
  30. current_latent = gen_func(current_pos)
  31. current_image = Gs.run(current_latent, None, truncation_psi=0.5, randomize_noise=False, output_transform=fmt)[0]
  32. array_list = []
  33.  
  34. while(current_pos < 1.0):
  35. array_list.append(current_image)
  36.  
  37. lower = current_pos
  38. upper = current_pos + max_step
  39. current_pos = (upper + lower) / 2.0
  40.  
  41. current_latent = gen_func(current_pos)
  42. current_image = images = Gs.run(current_latent, None, truncation_psi=0.5, randomize_noise=False, output_transform=fmt)[0]
  43. current_mse = mse(array_list[-1], current_image)
  44.  
  45. while current_mse < change_min or current_mse > change_max:
  46. if current_mse < change_min:
  47. lower = current_pos
  48. current_pos = (upper + lower) / 2.0
  49.  
  50. if current_mse > change_max:
  51. upper = current_pos
  52. current_pos = (upper + lower) / 2.0
  53.  
  54.  
  55. current_latent = gen_func(current_pos)
  56. current_image = images = Gs.run(current_latent, None, truncation_psi=0.5, randomize_noise=False, output_transform=fmt)[0]
  57. current_mse = mse(array_list[-1], current_image)
  58. print(current_pos, current_mse)
  59.  
  60. return array_list
Advertisement
Add Comment
Please, Sign In to add comment