Guest User

Untitled

a guest
Jul 20th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. ```python
  2. import numpy as np
  3. import tensorflow as tf
  4.  
  5.  
  6. # np.set_printoptions(threshold=np.nan)
  7.  
  8.  
  9. def run(x, w, pad='SAME', stride=(1, 1)):
  10. xx = tf.constant(x, dtype='float32')
  11. ww = tf.constant(w, dtype='float32')
  12. yy = tf.nn.conv2d(xx, ww, strides=[1, stride[0], stride[1], 1], padding=pad)
  13. with tf.Session() as sess:
  14. out = yy.eval().ravel()
  15. return out
  16.  
  17.  
  18. if __name__ == '__main__':
  19. np.random.seed(0)
  20. # input [batch, in_height, in_width, in_channels]
  21. x = np.random.rand(1, 224, 224, 3).astype('float32')
  22. # filter [filter_height, filter_width, in_channels, out_channels]
  23. w = np.random.rand(3, 3, 3, 32).astype('float32')
  24. out = run(x, w)
  25. print(out.shape)
  26. print(out)
  27. ```
  28.  
  29. ```
  30. $ python validate-conv2d.py
  31. (1605632,)
  32. [3.6909204 3.6372736 3.3944104 ... 3.8938167 2.8258123 4.4820447]
  33. ```
Add Comment
Please, Sign In to add comment