Guest User

Untitled

a guest
Jun 18th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. sobel_x = tf.constant([[-1, 0, 1], [-2, 0, 2], [-1, 0, 1]], tf.float32)
  2. sobel_x_filter = tf.reshape(sobel_x, [1, 3, 3, 3, 3]) # here it crashes
  3.  
  4. import numpy as np
  5. import tensorflow as tf
  6. import matplotlib.pyplot as plt
  7.  
  8. im0 = plt.imread('../../data/im0.png') # already divided by 255
  9. sobel_x = tf.constant([[-1, 0, 1], [-2, 0, 2], [-1, 0, 1]], tf.float32)
  10. sobel_x_filter = tf.reshape(sobel_x, [1, 3, 3, 3, 3])
  11. image = tf.placeholder(tf.float32, shape=[496, 718, 3])
  12. image_resized = tf.expand_dims(tf.expand_dims(image, 0), 0)
  13.  
  14. filters_x = tf.nn.conv3d(image_resized, filter=sobel_x_filter, strides=[1,1,1,1,1],
  15. padding='SAME', data_format='NDHWC')
  16.  
  17. with tf.Session('') as sess:
  18. sess.run([tf.global_variables_initializer(), tf.local_variables_initializer()])
  19. coord = tf.train.Coordinator()
  20. threads = tf.train.start_queue_runners(sess=sess, coord=coord)
  21. feed_dict = {image: im0}
  22. img = filters_x.eval(feed_dict=feed_dict)
  23.  
  24. plt.figure(0), plt.title('red'), plt.imshow(np.squeeze(img[...,0])),
  25. plt.figure(1), plt.title('green'), plt.imshow(np.squeeze(img[...,1])),
  26. plt.figure(2), plt.title('blue'), plt.imshow(np.squeeze(img[...,2]))
Add Comment
Please, Sign In to add comment