# Set this transformer_name = args['transformer'] # transformer to use N = args['n_img'] # number of transformations # Special for CPAB if transformer_name == 'CPAB': s = setup_CPAB_transformer() # Get transformer and random transformation transformer = get_transformer_layer(transformer_name) theta = get_random_theta(N, transformer_name) # Load im and create a batch of imgs im = get_cat() im = np.tile(im, (N, 1, 1, 1)) # Cast to tensorflow im_tf = tf.cast(im, tf.float32) theta_tf = tf.cast(theta, tf.float32) # Transformer imgs trans_im, theta_fg = transformer(im_tf, theta_tf, (1200, 1600)) # Run computations run_options = tf.RunOptions(report_tensor_allocations_upon_oom=True) sess = tf.Session() out_im, theta_gr = sess.run([trans_im, theta_fg], options=run_options) print(theta_gr) # Show the transformed images show_images(out_im, title=transformer_name + ' transformations')
V = ST_TPS_transformer(input_repeated, thetas, out_size, tps_size) return V #%% if __name__ == '__main__': from ddtn.helper.utility import get_cat, show_images # Load im and create a batch of imgs N = 15 im = get_cat() im = np.tile(im, (N, 1, 1, 1)) # Create transformation vector theta = np.tile(np.array([1, 0, 0, 0, 1, 0], np.float32), (N, 1)) theta[:, 2] = np.random.normal(scale=0.5, size=N) theta[:, 5] = np.random.normal(scale=0.5, size=N) # Cast to tensorflow and normalize values im_tf = tf.cast(im, tf.float32) theta_tf = tf.cast(theta, tf.float32) # Transformer imgs trans_im = ST_Affine_transformer(im_tf, theta_tf, (1200, 1600)) # Run computations sess = tf.Session() out_im = sess.run(trans_im) show_images(out_im, cols=3)