python - CIFAR-10 neural net doesn't accept batch -


i making neural network in python using tensorflow library classify cifar-10 dataset. issue cannot find way of converting batch train step accept feed. code, sections have verified work being replaced comments describing them:

# import statements  # declare global variables  # declare filepaths    def read_cifar10(filename_queue):      # parse cifar10 file, return label uint8image (cifar10record)    def generate_batch(image, label):      # generate shuffled batch, given images , labels    def get_imgs(test = false, fmin = 1, files = 1):      # generate filename(s) , filename_queue      # read input using read_cifar10      # cast uint8image , float32      # apply distortions      # set shape of image , label      # return batch, made using generate_batch    # build placeholders input , output  x = tf.placeholder(tf.float32, shape=[none, 784])  y_ = tf.placeholder(tf.float32, shape=[none, 10])   # create weight variable given shape  # slight amount of variation  def weight_variable(shape):      initial = tf.truncated_normal(shape, stddev = 0.1)      return tf.variable(initial)   # same bias variables  def bias_variable(shape):      initial = tf.constant(0.1, shape = shape)      return tf.variable(initial)   # convolve it, more layers, apply relu, make dropout , readout layers, etc  # softmax regression    # define loss function, training step, accuracy function  cross_entropy = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(labels = y_, logits = y_conv))  train_step = tf.train.adamoptimizer(1e-4).minimize(cross_entropy)  guess = tf.argmax(y_conv, 1)  answer = tf.argmax(y_, 1)  correct_prediction = tf.equal(guess, answer)  accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))   def train_nn():      in range(train_steps):         # error occurs         batch = get_imgs(files = 5).eval()           # every 100 steps output training accuracy          if % 100 == 0:              train_accuracy = accuracy.eval(feed_dict = {x: batch[0], y_: batch[1], keep_prob: 0.5})              print('step %d, training accuracy %g' % (i, train_accuracy))           train_step.run(feed_dict = {x: batch[0], y_: batch[1], keep_prob: 0.5})   def test_nn():      # test      batch = get_imgs(test = true).eval()      print('test accuracy %g' % accuracy.eval(feed_dict = {x: batch[0], y_: batch[1], keep_prob: 1.0}))   # create session  tf.session() sess:      # initialize global variables      sess.run(tf.global_variables_initializer())       # make queue runners      coord = tf.train.coordinator()      threads = tf.train.start_queue_runners(sess = sess, coord = coord)       # train it, test      sess.run(train_nn())      sess.run(test_nn())       coord.request_stop()      coord.join(threads) 

some things have tried , results:

  • batch = get_imgs(args) gives 'typeerror: value of feed cannot tf.tensor object. acceptable feed values include python scalars, strings, lists, numpy ndarrays, or tensorhandles.'
  • batch = get_imgs(args).eval() gives 'attributeerror: 'tuple' object has no attribute 'eval''
  • batch = sess.run(get_imgs(args)) causes program run indefinitely no output
  • printing type(batch) says batch tuple
  • printing batch gives description of tensor
  • printing batch.eval() or type(batch.eval()) gives 'w tensorflow/core/kernels/queue_base.cc:302] _3_input_producer: skipping cancelled dequeue attempt queue not closed'

i suspect issue either batch conversion, queueing tf.train.coordinator(), or placeholders. appreciated.


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -