facuq

Simpler MWE for "Computer freeze when feeding a large numpy"

Dec 2nd, 2016
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.35 KB | None | 0 0
  1. from tensorflow.examples.tutorials.mnist import input_data
  2. import tensorflow as tf
  3.  
  4. def weight_variable(shape):
  5.   initial = tf.truncated_normal(shape, stddev=0.1)
  6.   return tf.Variable(initial)
  7.  
  8. def bias_variable(shape):
  9.   initial = tf.constant(0.1, shape=shape)
  10.   return tf.Variable(initial)
  11.  
  12. def conv2d(x, W):
  13.   return tf.nn.conv2d(x, W, strides=[1, 1, 1, 1], padding='SAME')
  14.  
  15. def max_pool_2x2(x):
  16.   return tf.nn.max_pool(x, ksize=[1, 2, 2, 1],
  17.                         strides=[1, 2, 2, 1], padding='SAME')
  18.  
  19. mnist = input_data.read_data_sets('MNIST_data', one_hot=True)
  20. sess = tf.InteractiveSession()
  21.  
  22. x = tf.placeholder(tf.float32, shape=[None, 784])
  23. y_ = tf.placeholder(tf.float32, shape=[None, 10])
  24.  
  25. x_image = tf.reshape(x, [-1,28,28,1])
  26.  
  27. filters=4
  28. W_conv = weight_variable([5, 5, 1, filters])
  29. b_conv = bias_variable([filters])
  30.  
  31. h_conv = (conv2d(x_image, W_conv) + b_conv)
  32. h_pool = max_pool_2x2(h_conv)
  33.  
  34. s=14*14*filters
  35. h=16
  36. h_pool_flat = tf.reshape(h_pool, [-1, s])
  37. classes=10
  38. W_fc = weight_variable([s, classes])
  39. b_fc = bias_variable([classes])
  40. y_conv = tf.matmul(h_pool_flat, W_fc) + b_fc
  41. cross_entropy = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(y_conv, y_))
  42.  
  43. sess.run(tf.initialize_all_variables())
  44.  
  45. n=55000
  46. train_accuracy = cross_entropy.eval(feed_dict={ x:mnist.train.images[:n,:], y_: mnist.train.labels[:n,:]})
Add Comment
Please, Sign In to add comment