Skip to content

Instantly share code, notes, and snippets.

@solaris33
Created March 27, 2017 14:05
Show Gist options
  • Save solaris33/6b598290ccb1ea7e533df9a5bed95b88 to your computer and use it in GitHub Desktop.
Save solaris33/6b598290ccb1ea7e533df9a5bed95b88 to your computer and use it in GitHub Desktop.
def render_deepdream(t_obj, img0=img_noise,
iter_n=10, step=1.5, octave_n=4, octave_scale=1.4):
t_score = tf.reduce_mean(t_obj) # defining the optimization objective
t_grad = tf.gradients(t_score, t_input)[0] # behold the power of automatic differentiation!
# split the image into a number of octaves
img = img0
octaves = []
for i in range(octave_n-1):
hw = img.shape[:2]
lo = resize(img, np.int32(np.float32(hw)/octave_scale))
hi = img-resize(lo, hw)
img = lo
octaves.append(hi)
# generate details octave by octave
for octave in range(octave_n):
if octave>0:
hi = octaves[-octave]
img = resize(img, hi.shape[:2])+hi
for i in range(iter_n):
g = calc_grad_tiled(img, t_grad)
img += g*(step / (np.abs(g).mean()+1e-7))
print('.',end = ' ')
clear_output()
showarray(img/255.0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment