def save_reference_img(img, direction, pct, fno): subdname = '{}_{}'.format(direction, pct) tfi.savejpeg(img, ('{}/{}/overlap_frame_{}.jpeg'.format( directory, subdname, '%04d' % fno)))
def save_rendered_img(img, direction, pct, fno): cropped_img = img[margin:-margin, margin:-margin, :] subdname = '{}_{}'.format(direction, pct) tfi.savejpeg( cropped_img, ('{}/{}/frame_{}.jpeg'.format(directory, subdname, '%04d' % fno)))
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)
first_ring_offset_b = 120 second_ring_offset_b = 135 clear_offset_b = 150 directory = 'animation_stage_03' if not os.path.exists(directory): os.makedirs(directory) img0 = PIL.Image.open('images/start_frame_1400x840.jpeg') img0 = np.float32(img0) tfi.reset_graph_and_session() current_img = img0 cropped_img = current_img[margin:-margin, margin:-margin, :] tfi.savejpeg(cropped_img, ('{}/frame_{}.jpeg'.format(directory, '%04d' % start_frame))) total_zoom = 1.0 total_rot = 0.0 targets = [ 'head0_bottleneck_pre_relu', 53, # Feathers 'mixed5a_3x3_bottleneck_pre_relu', 11, # Dog face and circles 'mixed5a_3x3_bottleneck_pre_relu', 119, # Butterfly 'mixed5a_3x3_bottleneck_pre_relu', 33, # Spider monkey brains 'head0_bottleneck_pre_relu', 18, # Trumpets
# Technically this is the end frame, as we're working backwards towards it img0 = PIL.Image.open('images/start_frame_1400x840.jpeg') img0 = np.float32(img0) colour_guides = [ img0, np.float32(PIL.Image.open('images/colour_guide_a.jpeg')), np.float32(PIL.Image.open('images/colour_guide_b.jpeg')), np.float32(PIL.Image.open('images/colour_guide_c.jpeg')) ] tfi.reset_graph_and_session() current_img = img0.copy() cropped_img = current_img[margin:-margin, margin:-margin, :] tfi.savejpeg(cropped_img, ('{}/frame_{}.jpeg'.format(directory, '%04d' % end_frame))) slow_zoom = 1.0 / 0.997 slow_rot = 0.2 fast_zoom = 1.0 / 0.994 fast_rot = 0.35 for frame in range(nframes): fno = end_frame - 1 - frame section_id = (fno // channel_step) prev_layer = targets[(section_id - 1) * 2] prev_channel = targets[(section_id - 1) * 2 + 1] layer = targets[section_id * 2] channel = targets[section_id * 2 + 1]
first_ring_offset_b = 120 second_ring_offset_b = 135 clear_offset_b = 150 directory = 'animation_stage_01' if not os.path.exists(directory): os.makedirs(directory) img0 = PIL.Image.open('images/start_frame_1400x840.jpeg') img0 = np.float32(img0) tfi.reset_graph_and_session() current_img = img0 cropped_img = current_img[margin:-margin, margin:-margin, :] tfi.savejpeg( cropped_img, ('{}/frame_{}.jpeg'.format( directory, '%04d' % 0 ) ) ) total_zoom = 1.0 total_rot = 0.0 transition_start = 930 transition_zoom = 0.997 transition_rot = 0.2 targets = [ 'mixed4b_3x3_bottleneck_pre_relu', 105, # girders 'mixed4a_3x3_bottleneck_pre_relu', 8, # molten glass 'mixed4a_3x3_bottleneck_pre_relu', 24, # leopard spots
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)))