random_test.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. import tensorflow as tf
  2. import numpy as np
  3. from six.moves import xrange
  4. with tf.Graph().as_default():
  5. tf.set_random_seed(666)
  6. # Placeholder for input images
  7. input_placeholder = tf.placeholder(tf.float32, shape=(9, 7), name='input')
  8. # Split example embeddings into anchor, positive and negative
  9. #anchor, positive, negative = tf.split(0, 3, input)
  10. resh1 = tf.reshape(input_placeholder, [3,3,7])
  11. anchor = resh1[0,:,:]
  12. positive = resh1[1,:,:]
  13. negative = resh1[2,:,:]
  14. # Build an initialization operation to run below.
  15. init = tf.global_variables_initializer()
  16. # Start running operations on the Graph.
  17. sess = tf.Session(config=tf.ConfigProto(log_device_placement=False))
  18. sess.run(init)
  19. with sess.as_default():
  20. batch = np.zeros((9,7))
  21. batch[0,:] = 1.1
  22. batch[1,:] = 2.1
  23. batch[2,:] = 3.1
  24. batch[3,:] = 1.2
  25. batch[4,:] = 2.2
  26. batch[5,:] = 3.2
  27. batch[6,:] = 1.3
  28. batch[7,:] = 2.3
  29. batch[8,:] = 3.3
  30. feed_dict = {input_placeholder: batch }
  31. print(batch)
  32. print(sess.run([anchor, positive, negative], feed_dict=feed_dict))
  33. #feed_dict = { images_placeholder: np.zeros((90,96,96,3)), phase_train_placeholder: True }
  34. #vars_eval = sess.run(tf.global_variables(), feed_dict=feed_dict)
  35. #for gt in vars_eval:
  36. #print('%.20f' % (np.sum(gt)))
  37. #for gt, gv in zip(grads_eval, grad_vars):
  38. #print('%40s: %.20f' % (gv.op.name, np.sum(gt)))
  39. #import h5py
  40. #myFile = h5py.File('/home/david/repo/TensorFace/network.h5', 'r')
  41. ## The '...' means retrieve the whole tensor
  42. #data = myFile[...]
  43. #print(data)
  44. #import h5py # HDF5 support
  45. #fileName = "/home/david/repo/TensorFace/network.h5"
  46. #f = h5py.File(fileName, "r")
  47. ##for item in f.keys():
  48. ##print item
  49. #for item in f.values():
  50. #print item
  51. #import tensorflow as tf
  52. #import numpy as np
  53. #import matplotlib.pyplot as plt
  54. #import math
  55. #import facenet
  56. #import os
  57. #import glob
  58. #from scipy import misc
  59. #def plot_triplet(apn, idx):
  60. #plt.subplot(1,3,1)
  61. #plt.imshow(np.multiply(apn[idx*3+0,:,:,:],1/256))
  62. #plt.subplot(1,3,2)
  63. #plt.imshow(np.multiply(apn[idx*3+1,:,:,:],1/256))
  64. #plt.subplot(1,3,3)
  65. #plt.imshow(np.multiply(apn[idx*3+2,:,:,:],1/256))
  66. #input_image = tf.placeholder(tf.float32, name='input_image')
  67. #phase_train = tf.placeholder(tf.bool, name='phase_train')
  68. #n_in, n_out = 3, 16
  69. #ksize = 3
  70. #stride = 1
  71. #kernel = tf.Variable(tf.truncated_normal([ksize, ksize, n_in, n_out],
  72. #stddev=math.sqrt(2/(ksize*ksize*n_out))),
  73. #name='kernel')
  74. #conv = tf.nn.conv2d(input_image, kernel, [1,stride,stride,1], padding="SAME")
  75. #conv_bn = facenet.batch_norm(conv, n_out, phase_train)
  76. #relu = tf.nn.relu(conv_bn)
  77. ## Build an initialization operation to run below.
  78. #init = tf.global_variables_initializer()
  79. ## Start running operations on the Graph.
  80. #sess = tf.Session()
  81. #sess.run(init)
  82. #path = '/home/david/datasets/fs_aligned/Zooey_Deschanel/'
  83. #files = glob.glob(os.path.join(path, '*.png'))
  84. #nrof_samples = 30
  85. #img_list = [None] * nrof_samples
  86. #for i in xrange(nrof_samples):
  87. #img_list[i] = misc.imread(files[i])
  88. #images = np.stack(img_list)
  89. #feed_dict = {
  90. #input_image: images.astype(np.float32),
  91. #phase_train: True
  92. #}
  93. #out = sess.run([relu], feed_dict=feed_dict)
  94. #print(out[0].shape)
  95. ##print(out)
  96. #plot_triplet(images, 0)
  97. #import matplotlib.pyplot as plt
  98. #import numpy as np
  99. #a=[3,4,5,6]
  100. #b = [1,a[1:3]]
  101. #print(b)
  102. ## Generate some data...
  103. #x, y = np.meshgrid(np.linspace(-2,2,200), np.linspace(-2,2,200))
  104. #x, y = x - x.mean(), y - y.mean()
  105. #z = x * np.exp(-x**2 - y**2)
  106. #print(z.shape)
  107. ## Plot the grid
  108. #plt.imshow(z)
  109. #plt.gray()
  110. #plt.show()
  111. #import numpy as np
  112. #np.random.seed(123)
  113. #rnd = 1.0*np.random.randint(1,2**32)/2**32
  114. #print(rnd)