def add_texture_ring( current_img, pattern_step, offset, size, layer, channel ): if pattern_step >= offset and pattern_step < offset + size: ring_id = pattern_step - offset ring_img = ring_masks[ring_id] target = tfi.T(layer)[:,:,:,channel] textured = tfi.render_deepdream( target, current_img, iter_n=3, step=1.5, octave_n=4, octave_scale=1.5 ) return tfi.masked_mix( current_img, textured, ring_img ) else: return current_img
def process_image_step(current_img, zoom, rot, mix_ratio, mix_img, target): current_img = tfi.affine_zoom(current_img, zoom, rot) current_img = tfi.mix_images(current_img, mix_img, mix_ratio) return tfi.render_deepdream(target, current_img, iter_n=2, step=1.5, octave_n=4, octave_scale=1.5, direct_objective=True)
import tfi import os import numpy as np import PIL.Image import tensorflow as tf in_name = 'images/nfrac_1400x840.jpg' out_name = 'images/start_frame_1400x840.jpeg' img0 = PIL.Image.open(in_name) img0 = np.float32(img0) tfi.reset_graph_and_session() target = tf.square(tfi.T('mixed4c')) print('Rendering {}'.format(out_name)) test_img = tfi.render_deepdream(target, img0, iter_n=20, step=0.75, octave_n=4, octave_scale=1.5) tfi.savejpeg(test_img, out_name)
delta_rot = 0.1 delta_zoom = 1.05 total_rot += delta_rot total_zoom *= delta_zoom current_img = tfi.affine_zoom(current_img, delta_zoom, delta_rot) r = (fno - start_frame) / (end_frame - start_frame) mix_amount = 0.99 * (1 - r) + 0.96 * r current_img = tfi.mix_images(current_img, end_colours, mix_amount) current_img = tfi.render_deepdream(target, current_img, iter_n=2, step=1.5, octave_n=4, octave_scale=1.5, direct_objective=True) display_img = current_img # Fade to black if (fno > 5400): fade_r = 1.0 - (fno - 5400) / 45.0 display_img = tfi.mix_images(display_img, complete_fade_img, fade_r) # Fade in credits if (fno > 5430): credit_fade = 1.0 - (fno - 5430) / 15.0 display_img = tfi.mix_images(display_img, credit_img, credit_fade)
img0 = PIL.Image.open(source_img) img0 = np.float32(img0) if not os.path.exists('explore_layers'): os.makedirs('explore_layers') for layer in test_layers: num_channels = tfi.T(layer).get_shape()[3] directory = 'explore_layers/{}'.format(layer) if not os.path.exists(directory): os.makedirs(directory) print('Rendering {}, all {} channels squared'.format(layer, num_channels)) test_img = tfi.render_deepdream(tf.square(tfi.T(layer)), img0, iter_n=iterations, step=2.0, octave_n=4, octave_scale=1.5) tfi.savejpeg(test_img, ('{}/all_channels_squared.jpeg'.format(directory))) for channel in range(0, num_channels): print('Rendering {}, channel {}'.format(layer, channel)) test_img = tfi.render_deepdream(tfi.T(layer)[:, :, :, channel], img0, iter_n=iterations, step=2.0, octave_n=4, octave_scale=1.5) tfi.savejpeg( test_img, ('{}/channel_{}.jpeg'.format(directory, '%03d' % channel)))