SHARE
TWEET

Untitled

a guest Aug 19th, 2019 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import tensorflow as tf
  2. import numpy as np
  3. import itertools
  4.  
  5.  
  6. input_bits = tf.placeholder(dtype=tf.float32, shape=[None, 2], name='input_bits')
  7. code_out = tf.placeholder(dtype=tf.float32, shape=[None, 3], name='code_out')
  8. np.random.seed(1331)
  9.  
  10.  
  11. def find_code(message):
  12.     weight1 = np.random.normal(loc=0.0, scale=0.01, size=[2, 3])
  13.     init1 = tf.constant_initializer(weight1)
  14.     out = tf.layers.dense(inputs=message, units=3, activation=tf.nn.sigmoid, kernel_initializer=init1)
  15.     return out
  16.  
  17.  
  18. code = find_code(input_bits)
  19.  
  20. distances = []
  21. for i in range(0, 3):
  22.     for j in range(i+1, 3):
  23.         distances.append(tf.linalg.norm(code_out[i]-code_out[j]))
  24. min_dist = tf.reduce_min(distances)
  25. # avg_dist = tf.reduce_mean(distances)
  26.  
  27. loss = -min_dist
  28.  
  29. opt = tf.train.AdamOptimizer().minimize(loss)
  30.  
  31. init_variables = tf.global_variables_initializer()
  32. sess = tf.Session()
  33. sess.run(init_variables)
  34.  
  35. saver = tf.train.Saver()
  36.  
  37. count = int(1e4)
  38.  
  39. for i in range(count):
  40.     input_bit = [list(k) for k in itertools.product([0, 1], repeat=2)]
  41.     code_preview = sess.run(code, feed_dict={input_bits: input_bit})
  42.     sess.run(opt, feed_dict={input_bits: input_bit, code_out: code_preview})
  43.      
  44. ValueError: No gradients provided for any variable, check your graph for ops that do not support gradients, between variables
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top