Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. import tensorflow as tf
  2. def conv2d(x,output_filters, kh=5,kw=5, sh=2, sw=2, stddev=0.02, scope="conv2d"):
  3. with tf.compat.v1.variable_scope(scope):
  4. shape = x.get_shape().as_list()
  5. W = tf.compat.v1.get_variable('W', [kh,kw,shape[-1],output_filters], initializer=tf.compat.v1.truncated_normal_initializer(stddev=stddev))
  6. Wconv = tf.nn.conv2d(x,W,strides=[1,sh,sw,1], padding='SAME')
  7. biases = tf.compat.v1.get_variable('b',[output_filters], initializer=tf.compat.v1.constant_initializer(0.0))
  8. Wconv_plus_b = tf.reshape(tf.nn.bias_add(Wconv, biases), Wconv.get_shape())
  9. return Wconv_plus_b
  10. def dropout(x,rate):
  11. return tf.nn.dropout(x=x, rate=rate)
  12. def fc(x,output_size, stddev=0.02, scope='fc'):
  13. with tf.compat.v1.variable_scope(scope):
  14. shape = x.get_shape().as_list()
  15. W = tf.compat.v1.get_variable('W', [shape[1],output_size], tf.float32, tf.random_normal_initializer(stddev=stddev))
  16. b = tf.compat.v1.get_variable('b', [output_size], initializer=tf.constant_initializer(0.0))
  17. return tf.matmul(x,W) + b
  18. def flatten(x):
  19. shape = x.get_shape().as_list()
  20. return tf.reshape(x, [shape[0], shape[1]*shape[2]*shape[3]])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement